Skip to content

rtk hook claude: git refused in sessions isolated in a worktree outside .claude/worktrees/ #4634

Open

Description

@KuSh

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.

Repro (Claude Code 2.1.302, rtk develop e542dca):

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).

Activity

  1. rtk-wshm-sync-bot commented on Oct 17, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    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

    1. Ask upstream whether Claude Code can expose isolation status directly in the PreToolUse payload instead of relying on c…
    2. Consider a config key for additional worktree roots to treat like .claude/worktrees/, as proposed in the issue
    3. Cross-reference In a worktree-isolated Claude Code session, any rtk … command with a git-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 design
    4. Note the documented workaround (exclude_commands = ['^git\b']) in the issue/docs until a proper fix lands

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. rtreffler commented on Oct 30, 2026

    @rtreffler

    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).

  3. nitayk commented on Nov 5, 2026

    @nitayk

    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
      [hooks]
      exclude_commands = ["git"]
      We checked git -C /path status, git status && git diff and cd src && git push all stay unrewritten, while grep is 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 for git -C.)
    • 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.
  4. dmastrorillo commented on Nov 6, 2026

    @dmastrorillo

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions