Repository navigation
Run quality checks in the worktree where files were edited - #8
Open
joshuanapoli wants to merge 1 commit into
Open
joshuanapoli wants to merge 1 commit into
joshuanapoli wants to merge 1 commit into
Conversation
The Claude Code desktop app starts a session in the main checkout and then works in a git worktree. The Stop hooks ran in CLAUDE_PROJECT_DIR, so worktree edits were never checked, and unrelated failures in the main checkout were fed back to the agent, which could not fix them and looped. Group tracked files by the checkout that contains them (nearest .git entry, keeping the project's subdirectory within its repository) and run each check there. Only checkouts that still fail stay tracked. git status uses the session cwd from the hook input. Session state and toggles stay in CLAUDE_PROJECT_DIR. Co-Authored-By: Claude Opus 5.5 <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.
Problem
The Claude Code desktop app starts a session in the main checkout and then does its work in a git worktree (e.g.
.claude/worktrees/<name>).CLAUDE_PROJECT_DIRkeeps pointing at the main checkout, and every Stop hook ran withcwd=CLAUDE_PROJECT_DIR. So:Change
checkout_dir(path, project_dir)finds the checkout that contains an edited file by walking up to the nearest.gitentry. That entry is a file in a worktree, so worktrees nested inside the main checkout are handled. If the project is a subdirectory of its repository, the same subdirectory of the worktree is used.ruff format,ruff check,mypy, andpytestgroup the tracked files by checkout and run once in each checkout, using only that checkout's files. Checkouts this session didn't edit are not checked. Only files in checkouts that still fail stay tracked.2if any checkout returned2, otherwise the first non-zero code.git statusruns in the checkout of the sessioncwdfrom the hook input.CLAUDE_PROJECT_DIR/.claude, so theeditedand Stop hooks always use the same state.CLAUDE_PROJECT_DIRexactly as before.Testing
tests/test_checkout.pycovers checkout resolution (main checkout, nested worktree, project in a subdirectory, file outside any repo) and each hook'scwdand per-checkout file grouping. It also checks that a failure in one checkout keeps only that checkout's files tracked.checkout_diragainst a realgit worktree add .claude/worktrees/feat.ruff,mypy, andpytestall pass (63 tests).🤖 Generated with Claude Code