security-guidance: commit review runs in a git worktree the session removes seconds later, so every Read fails
Plugin: security-guidance 2.0.8
Claude Code: 2.1.278–2.1.283, Linux; auth via ANTHROPIC_API_KEY
Summary
The asynchronous commit review (PostToolUse on git commit, asyncRewake) starts the agentic reviewer with its working directory set to the session's current checkout. When that checkout is a linked git worktree, the usual end of a branch is commit → merge → git worktree remove, all within a few seconds. The reviewer starts in, or keeps reading from, a directory that no longer exists. Its Reads of the changed files fail, it guesses other roots (the primary checkout, /home/user/...), and it spends its tool budget on failed Reads instead of the review.
Evidence
From one workstation's transcripts, 2026-08-05 → 09-27:
- 1,128 reviewer sessions ran with a worktree as their cwd.
- 64 of them failed a Read of a path inside their own worktree. In 59 of the 64, a
git worktree removeof that worktree ran in the parent session a median of 5.5 s after the reviewer started, and the first failed Read came a median of 3.3 s after the removal. (3 failed before any removal; 2 had no removal within an hour.) - Across all reviewer sessions in worktrees: 87 failed Reads of own-worktree paths, 145 of primary-checkout paths for files that exist only on the branch, and 18 of an invented
/home/user/...root. The last two overlap with #4693: once the cwd is gone, the reviewer falls back to guessing roots.
Expected
The review of a commit should not depend on the working tree surviving. Either:
- Read the reviewed files from git objects (
git show <sha>:<path>, orgit cat-file), which outlivegit worktree removebecause linked worktrees share the object store with the primary checkout; or - Check out the reviewed commit into a temporary directory the plugin owns (
git worktree add --detach <tmp> <sha>) and remove it when the review ends; or, at minimum, - Check that the cwd still exists before each phase, and report "review skipped: worktree removed" rather than returning an empty verdict.
Reproduce
- In a repository,
git worktree add ../wt -b testand make a commit there that touches a source file (so the commit review triggers). - Right after the commit, from the same session:
cd .. && git worktree remove wt. - Read the reviewer's transcript (headless
sdk-pysession under~/.claude/projects/<the worktree's project dir>/): the Reads of the committed file returnFile does not exist.
Related: #4693 (reviewer prompt never states its root), #4960 (findings body replaced by inner-CLI stderr).
Source: anthropics/claude-plugins-official