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
rtk hook claude: git refused in sessions isolated in a worktree outside .claude/worktrees/ #4634
Since #3879, rtk hook claude leaves git unrewritten when the payload's cwd is under <repo>/.claude/worktrees/<name>. Claude Code can also isolate a session somewhere else:
EnterWorktree(path: …) on a worktree made with git worktree add (Claude Code's tool description suggests exactly this)
a WorktreeCreate hook that provisions the worktree at a custom location
In both cases, every git … is still rewritten to rtk git …, and Claude Code's isolation guard refuses it with the #3864 text.
git init repo && cd repo && git commit --allow-empty -m init
git worktree add -b feat ../repo-worktrees/feat
claude -p 'EnterWorktree path=<abs>/repo-worktrees/feat, then run: git status' --settings <rtk hook claude>
# → "This session is isolated in the worktree …, but this command runs rtk with a git command among its operands … Refusing to run it"
Why cwd cannot decide it: the PreToolUse payload is identical, apart from ids, for an isolated session and a plain session in the same worktree. A plain session never meets the guard, and rtk git works there. Detecting "any linked worktree" (.git is a file, #4490) also catches those plain sessions and every submodule checkout, so git output would go unfiltered in all of them.
Options:
Claude Code exposes isolation in the hook payload. Then rtk can key on that instead of a path.
A config key listing the worktree roots to treat like .claude/worktrees/.
Workaround today: [hooks] exclude_commands = ['^git\b'] (it applies everywhere; see #3838 for git -C).
rtk's isolation guard for Claude Code only recognizes .claude/worktrees/, so EnterWorktree or WorktreeCreate-provisioned worktrees elsewhere have all git commands rewritten and then refused by the guard, blocking git entirely in those sessions.
📁 Relevant files
src/hooks/claude.rs
src/git/isolation.rs
Suggested Actions
Ask upstream whether Claude Code can expose isolation status directly in the PreToolUse payload instead of relying on c…
Consider a config key for additional worktree roots to treat like .claude/worktrees/, as proposed in the issue
The same ambiguity bites the other way too. We start plain, non-isolated Claude Code sessions
inside <repo>/.claude/worktrees/<name> from our own launcher. Since #3879, the hook leaves every git command there
unrewritten, although rtk git works fine in those sessions. A fix that only adds more worktree
roots would not cover this case. A payload flag from Claude Code would cover both.
A hook cannot tell these sessions apart today. Each session below ran <launcher> git status
once, on Claude Code 2.1.306 and 2.1.314:
Session
Claude Code runs <launcher> git status
rtk hook today
worktree-state records in the transcript
plain, started in .claude/worktrees/plain
yes
leaves git as is, though rtk git would run
0
claude --worktree exp-flag
no, the isolation guard refuses it
leaves git as is
3
EnterWorktree from the repo root
no, the isolation guard refuses it
leaves git as is
1
Rows 1 and 2 give the hook the same input, so it cannot rewrite git in row 1 without breaking row 2.
The PreToolUse payload and the hook's environment are the same in the plain and the --worktree session, apart from ids and paths. The only difference is the undocumented worktree-state record in the transcript, which a hook should not depend on. That leaves the
payload flag.
A small related ask: rtk hook check takes no cwd, so it shows the rewrite while the live hook
skips it. A --cwd option would make the dry run match the live decision (see #3476).
We hit this in a team rollout (Claude Code 2.1.318, rtk 0.50.0): a session isolated via EnterWorktree with its cwd outside .claude/worktrees/ had every git -C <clone> ... rewritten to rtk git -C ..., which the guard then refused, even with allow rules.
Two notes for anyone landing here:
Workaround that works on 0.50.0 today, no restart needed: in rtk's config.toml (macOS: ~/Library/Application Support/rtk/config.toml) set
For a precise fix, Claude Code writes a {"type":"worktree-state","worktreeSession":{...}|null} line (last one wins) into the session transcript on EnterWorktree/ExitWorktree and for claude -w; reading that from transcript_path distinguishes isolated sessions without relying on cwd. We asked upstream for a proper field in the hook input: Worktree guard refuses hook-rewritten rtk git anthropics/claude-code#107244.
Still present on the 1.1.0 release (Homebrew, macOS, Claude Code). The session was isolated with EnterWorktree(path: …) on a worktree under ~/.yggtree/<repo>/<branch>, made by git worktree add through yggtree. A plain git status -sb in that cwd is still rewritten to rtk git status -sb, and the isolation guard refuses it with the #3864 text.
The .claude/worktrees/ path check from #3879 can't cover setups that are required to keep worktrees outside the repository. Asking git would. In a linked worktree, git rev-parse --git-dir differs from git rev-parse --git-common-dir, and that holds wherever the worktree lives.
Activity
rtk-wshm-sync-bot commentedon Oct 17, 2026
🔍 Automated Triage
bughighSummary
rtk's isolation guard for Claude Code only recognizes .claude/worktrees/, so EnterWorktree or WorktreeCreate-provisioned worktrees elsewhere have all git commands rewritten and then refused by the guard, blocking git entirely in those sessions.
📁 Relevant files
src/hooks/claude.rssrc/git/isolation.rsSuggested Actions
rtk …command with agit-named operand is refused #4591 and fix(hooks): detect linked worktrees by .git shape, not path convention #4490 — same isolation-guard/worktree-detection tension, may need a combined designexclude_commands = ['^git\b']) in the issue/docs until a proper fix landsTriaged automatically by wshm · This is an automated analysis, not a human review.
rtreffler commentedon Oct 30, 2026
The same ambiguity bites the other way too. We start plain, non-isolated Claude Code sessions
inside
<repo>/.claude/worktrees/<name>from our own launcher. Since#3879, the hook leaves every git command there
unrewritten, although
rtk gitworks fine in those sessions. A fix that only adds more worktreeroots would not cover this case. A payload flag from Claude Code would cover both.
A hook cannot tell these sessions apart today. Each session below ran
<launcher> git statusonce, on Claude Code 2.1.306 and 2.1.314:
<launcher> git statusworktree-staterecords in the transcript.claude/worktrees/plainrtk gitwould runclaude --worktree exp-flagEnterWorktreefrom the repo rootRows 1 and 2 give the hook the same input, so it cannot rewrite git in row 1 without breaking row 2.
The PreToolUse payload and the hook's environment are the same in the plain and the
--worktreesession, apart from ids and paths. The only difference is the undocumentedworktree-staterecord in the transcript, which a hook should not depend on. That leaves thepayload flag.
A small related ask:
rtk hook checktakes nocwd, so it shows the rewrite while the live hookskips it. A
--cwdoption would make the dry run match the live decision (see#3476).
nitayk commentedon Nov 5, 2026
We hit this in a team rollout (Claude Code 2.1.318, rtk 0.50.0): a session isolated via
EnterWorktreewith its cwd outside.claude/worktrees/had everygit -C <clone> ...rewritten tortk git -C ..., which the guard then refused, even with allow rules.Two notes for anyone landing here:
config.toml(macOS:~/Library/Application Support/rtk/config.toml) setgit -C /path status,git status && git diffandcd src && git pushall stay unrewritten, whilegrepis still rewritten. (So exclude_commands is matched on the raw command, so git -C <path> escapes it #3838 did not reproduce for us on 0.50.0 forgit -C.){"type":"worktree-state","worktreeSession":{...}|null}line (last one wins) into the session transcript onEnterWorktree/ExitWorktreeand forclaude -w; reading that fromtranscript_pathdistinguishes isolated sessions without relying on cwd. We asked upstream for a proper field in the hook input: Worktree guard refuses hook-rewritten rtk git anthropics/claude-code#107244.dmastrorillo commentedon Nov 6, 2026
Still present on the 1.1.0 release (Homebrew, macOS, Claude Code). The session was isolated with
EnterWorktree(path: …)on a worktree under~/.yggtree/<repo>/<branch>, made bygit worktree addthrough yggtree. A plaingit status -sbin that cwd is still rewritten tortk git status -sb, and the isolation guard refuses it with the #3864 text.The
.claude/worktrees/path check from #3879 can't cover setups that are required to keep worktrees outside the repository. Asking git would. In a linked worktree,git rev-parse --git-dirdiffers fromgit rev-parse --git-common-dir, and that holds wherever the worktree lives.