Add clash check command with Claude Code hook support#9
Merged
Conversation
Checks a file against all worktrees for merge conflicts (via git merge-tree) and active uncommitted changes (via gix HEAD comparison). Outputs JSON with exit code 0 (clear) or 2 (conflicted). Building block for Claude Code hook integration (#5). Also adds WorktreeManager::find_containing() for identifying which worktree a directory belongs to. Closes #2 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This allows the PreToolUse hook config to be just `"command": "clash check"` without needing a shell script or jq to extract the file path. When no path is provided, reads JSON from stdin and extracts tool_input.file_path. In hook mode, conflicts are output to stderr (which Claude sees on exit 2) and clean results are silent. Includes a TTY guard to show helpful usage instead of blocking when run interactively without arguments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In hook mode, output Claude Code's hookSpecificOutput JSON with permissionDecision "ask" so the user can override conflicts instead of being hard-blocked. Manual mode (`clash check <path>`) still uses exit 2. Note: permissionDecisionReason doesn't render in the permission prompt yet (anthropics/claude-code#17356). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes Denial of Service via Stack Exhaustion vulnerability in the time crate (transitive dep via ratatui). Resolves CI failures in Dependency Check and Security Audit jobs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Branch protection requires a status called "CI" but the workflow only reported individual job names. Add a summary job that depends on all other jobs and reports as "CI". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2, closes #5
Summary
clash checkcommand for single-file conflict detection across worktreesclash check <path>) with JSON on stdout, and hook mode (clash checkwith stdin) for Claude Code's PreToolUse hooktool_input.file_pathfrom stdin JSON, outputs conflicts to stderr on exit 2 (which Claude sees), and is silent on exit 0clash checkin a terminal shows helpful usage instead of blockingWorktreeManagerwithfind_containing()anditer()methodsconflicts_with()error field toWorktreePairConflictfor surfacing detection failuresHook configuration
{ "hooks": { "PreToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "clash check" } ] } ] } }Test plan
cargo build && cargo clippy -- -D warnings && cargo fmt --checkclash check src/main.rsoutputs JSON to stdoutecho '{"tool_input":{"file_path":"src/main.rs"}}' | clash checkreads from stdinclash checkin terminal prints helpful error, doesn't block🤖 Generated with Claude Code