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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions