You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In a worktree-isolated Claude Code session, any rtk … command with a git-named operand is refused #4591
Claude Code's worktree guard refuses a command whose launcher it does not model when an operand matches ^git(?:\.exe|\.real|-[a-z][\w-]*)?$ (2.1.301). rtk is such a launcher, so beyond the rtk git … case fixed by #3879:
Hook rewrites:grep -n git README.md → rtk grep -n git README.md, refused ("… this command runs rtk with a git command among its operands …"). Reproduced in claude -p --worktree with fix(hooks): leave git unrewritten in Claude Code managed worktrees #3879 merged on develop f16beca. Any rewritten command whose arguments contain the bare word git (a search pattern, a path component spelled git) hits it.
Commands the model types from rtk's own guidance:rtk bypass git status and rtk git status are refused the same way. rtk's awareness text and recovery hints tell the model to re-run with rtk bypass <cmd>, which cannot succeed for git in an isolated session.
Plain grep -n git README.md runs in the same session. A fix on the rewrite side would leave a segment unrewritten when the session is isolated and the rewrite would put a git-named operand after rtk; the hint side needs a spelling the guard accepts, or no hint, in that case. Detecting isolation is the same open question as #4490: a .git file also marks a linked worktree a plain, non-isolated session runs in, where the guard never applies.
Worktree guard over-matches: any operand spelled like 'git' (even a grep pattern or rtk's own bypass hint) is refused in isolated sessions, extending beyond the #3879 fix.
Hit this too, on rtk 1.0.1 (Homebrew) with Claude Code subagents launched with isolation: worktree. 1.0.1 doesn't have #3879 yet, so for me even a plain git status was refused:
This agent is isolated in the worktree /Users/.../.claude/worktrees/agent-..., but this command runs rtk with a git command among its operands ... Refusing to run it
git rev-parse went through fine, only because rtk doesn't rewrite it, which confirms the guard only cares about what ends up after rtk.
Until a release has #3879 plus a fix for the operand case here, I've put a small wrapper in front of rtk hook claude in settings.json. When cwd is under /.claude/worktrees/, it drops rtk's answer if any word of the rewritten command looks like a git binary (the same shape as the guard's regex: git, git-*, git.exe, git.real, with or without a path). Everything else passes through unchanged:
With that in place, an isolated agent could run git status, commit on a scratch branch, and run grep -n git AGENTS.md, while ls in the same worktree still got rtk's compact output.
One side effect worth knowing: rtk init -g / the "Hook outdated" check sees the wrapper as an outdated hook, so anyone copying this shouldn't re-run init.
A rewrite-side fix in decide_for_agent_at that does the same check on the rewritten segment would let me drop the wrapper. Happy to test a build from develop if that helps.
Still reproducible with the 1.1.0 release (Windows 11, Git Bash, Claude Code 2.1.312, subagent with isolation: worktree).
With #3879 in the release, plain git now passes: git status --short, git diff --stat, git show --stat HEAD and timeout 5 git status --short all run. The operand case remains, and a quoted search pattern hits a second message:
Command as typed
Guard
grep -c git FILE (rewritten to rtk grep …)
refused: "…this command runs rtk with a git command among its operands…"
rg -c git FILE (rewritten to rtk rg …)
refused, same message
grep -c "git push" FILE (rewritten to rtk grep …)
refused: "…this command runs rtk with the text git push in a plain command, so what it runs cannot be shown not to be git…"
cat .gitignore (rewritten to rtk read .gitignore)
accepted
So an operand containing the text git push (a search pattern) is refused too, not only an operand spelled git.
Starting an investigation and implementation for this issue.
Additional checks on macOS with RTK 1.1.0:
Invoked the configured selective PreToolUse wrapper with payloads for a main checkout, a sibling linked worktree, and a worktree subdirectory. Simple ls, rg, and docker compose ps commands were rewritten successfully in all three locations.
The current local workaround deliberately leaves Git-bearing commands and compound shell commands unrewritten, irrespective of checkout location. This preserves ordinary Git execution while retaining RTK for other simple commands.
Running rtk git status directly in a linked worktree outside a Claude worktree-isolated session succeeded. A linked worktree alone therefore does not reproduce the isolation-guard failure; these checks do not constitute a fresh reproduction inside Claude's isolated session.
Windows native and WSL execution have not been verified. In particular, the local workaround targets the Bash tool, not PowerShell, and Windows/WSL hook installations must be evaluated independently.
I will inspect the current rewrite paths and recovery/awareness hints, check the isolation-detection limitations discussed in #4490, and add focused regression coverage. The aim is to avoid producing commands that the worktree guard will refuse, while retaining rewriting for commands the guard can accept. No claim of a cross-platform fix or completed isolated-session reproduction yet.
Local implementation is now prepared on fix/hook-worktree-git-operands (not yet submitted as a PR).
In a detected Claude-managed worktree, inspect the proposed rewrite using the existing quote-aware shell lexer. If an RTK launcher would contain a Git-named argument/path component (git, git.exe, git.real, or git-*), defer the whole command to Claude unchanged. This conservative whole-command fallback avoids reconstructing shell syntax; unaffected segments in that particular command also remain uncompressed.
Preserve existing behavior for git status && cargo build → git status && rtk cargo build, ordinary checkouts, configured exclusions, and deny decisions.
Update all three awareness levels to run these commands directly in isolated worktrees, and use RTK_DISABLED=1 <cmd> for unfiltered recovery instead of wrapping Git with rtk bypass.
Validation on macOS:
Confirmed the new regression test fails before the fix and passes afterward.
cargo fmt --all, cargo clippy --all-targets (no warnings), cargo test --all: 5,511 passed, 0 failed, 8 ignored.
Separate proxy-workspace formatting check passed.
Invoked the built rtk hook claude with isolated configuration: Git search operand deferred inside the managed worktree, still rewritten outside it, the mixed Git/Cargo chain retained its existing rewrite, and RTK_DISABLED=1 git status stayed untouched.
Scope remains limited to the existing Claude-managed worktree detection. I reviewed the closure rationale for #4490 and have not introduced .git-file detection: custom-location isolation remains #4634. Native Windows/WSL and a fresh Claude isolated-session end-to-end run are still unverified; the binary-payload checks above are not a claim that those environments were tested.
Activity
rtk-wshm-sync-bot commentedon Oct 16, 2026
🔍 Automated Triage
bughighSummary
Worktree guard over-matches: any operand spelled like 'git' (even a grep pattern or rtk's own bypass hint) is refused in isolated sessions, extending beyond the #3879 fix.
Suggested Actions
grep -n git README.mdrewritten underclaude -p --worktreeTriaged automatically by wshm · This is an automated analysis, not a human review.
gfreschi commentedon Oct 20, 2026
Hit this too, on rtk 1.0.1 (Homebrew) with Claude Code subagents launched with
isolation: worktree. 1.0.1 doesn't have #3879 yet, so for me even a plaingit statuswas refused:git rev-parsewent through fine, only because rtk doesn't rewrite it, which confirms the guard only cares about what ends up afterrtk.Until a release has #3879 plus a fix for the operand case here, I've put a small wrapper in front of
rtk hook claudeinsettings.json. Whencwdis under/.claude/worktrees/, it drops rtk's answer if any word of the rewritten command looks like a git binary (the same shape as the guard's regex:git,git-*,git.exe,git.real, with or without a path). Everything else passes through unchanged:With that in place, an isolated agent could run
git status, commit on a scratch branch, and rungrep -n git AGENTS.md, whilelsin the same worktree still got rtk's compact output.One side effect worth knowing:
rtk init -g/ the "Hook outdated" check sees the wrapper as an outdated hook, so anyone copying this shouldn't re-run init.A rewrite-side fix in
decide_for_agent_atthat does the same check on the rewritten segment would let me drop the wrapper. Happy to test a build from develop if that helps.alponme commentedon Oct 28, 2026
Still reproducible with the 1.1.0 release (Windows 11, Git Bash, Claude Code 2.1.312, subagent with
isolation: worktree).With #3879 in the release, plain git now passes:
git status --short,git diff --stat,git show --stat HEADandtimeout 5 git status --shortall run. The operand case remains, and a quoted search pattern hits a second message:grep -c git FILE(rewritten tortk grep …)rg -c git FILE(rewritten tortk rg …)grep -c "git push" FILE(rewritten tortk grep …)cat .gitignore(rewritten tortk read .gitignore)So an operand containing the text
git push(a search pattern) is refused too, not only an operand spelledgit.HyeonggeonMin commentedon Nov 5, 2026
Starting an investigation and implementation for this issue.
Additional checks on macOS with RTK 1.1.0:
PreToolUsewrapper with payloads for a main checkout, a sibling linked worktree, and a worktree subdirectory. Simplels,rg, anddocker compose pscommands were rewritten successfully in all three locations.rtk git statusdirectly in a linked worktree outside a Claude worktree-isolated session succeeded. A linked worktree alone therefore does not reproduce the isolation-guard failure; these checks do not constitute a fresh reproduction inside Claude's isolated session.I will inspect the current rewrite paths and recovery/awareness hints, check the isolation-detection limitations discussed in #4490, and add focused regression coverage. The aim is to avoid producing commands that the worktree guard will refuse, while retaining rewriting for commands the guard can accept. No claim of a cross-platform fix or completed isolated-session reproduction yet.
HyeonggeonMin commentedon Nov 5, 2026
Local implementation is now prepared on
fix/hook-worktree-git-operands(not yet submitted as a PR).git,git.exe,git.real, orgit-*), defer the whole command to Claude unchanged. This conservative whole-command fallback avoids reconstructing shell syntax; unaffected segments in that particular command also remain uncompressed.git status && cargo build→git status && rtk cargo build, ordinary checkouts, configured exclusions, and deny decisions.RTK_DISABLED=1 <cmd>for unfiltered recovery instead of wrapping Git withrtk bypass.Validation on macOS:
cargo fmt --all,cargo clippy --all-targets(no warnings),cargo test --all: 5,511 passed, 0 failed, 8 ignored.rtk hook claudewith isolated configuration: Git search operand deferred inside the managed worktree, still rewritten outside it, the mixed Git/Cargo chain retained its existing rewrite, andRTK_DISABLED=1 git statusstayed untouched.Scope remains limited to the existing Claude-managed worktree detection. I reviewed the closure rationale for #4490 and have not introduced
.git-file detection: custom-location isolation remains #4634. Native Windows/WSL and a fresh Claude isolated-session end-to-end run are still unverified; the binary-payload checks above are not a claim that those environments were tested.fix(hooks): leave git-named operands unrewritten in Claude Code workt…