EnterWorktree(path) into a sibling worktree reports success, but Bash then refuses every command there

Status Closed — duplicate
Maintainer reply None cached
Activity 1 comment · opened Aug 9, 2026 · closed Aug 15, 2026

Environment

Claude Code CLI on macOS (Darwin 25.5), session running inside a worktree created by EnterWorktree (repo's .claude/worktrees/<name>).

Repro

  1. Main session enters worktree A via EnterWorktree with name — session is now pinned to A.
  2. Session spawns a subagent (Agent tool, isolation: "worktree"), which gets its own worktree B under the same repo's .claude/worktrees/. The subagent later stops, leaving uncommitted work in B.
  3. A second subagent is spawned and instructed to continue the work in B. It calls EnterWorktree with path = B (documented as supported: "Switching with path also works … from agents whose working directory was pinned at launch … the target must be a worktree under .claude/worktrees/ of the same repository"). The call returns success.
  4. Every subsequent Bash command in B is refused by the worktree-isolation guard with variants of: "This session is isolated in the worktree <A>, but this command … Refusing to run it — a worktree-isolated session's git operations must target its own worktree." Plain cd, git -C <B>, and sandbox-disabled variants are all refused. Only read-style access (Read tool, bare ls) works.

The guard appears to keep enforcing the original pin (worktree A) after EnterWorktree(path) has nominally moved the agent to B — so the switch succeeds at the session level but the Bash policy never follows it. Expected: either the EnterWorktree(path) call should be refused up front, or Bash should be permitted in the entered worktree. The silent success-then-refusal forced the agent to port the diff between worktrees by hand.

Related observation (same guard, possibly separate)

The isolation guard also refuses commands on heuristics that produce false positives inside a single legitimate worktree: any command string containing the substring eval (e.g. paths like crates/runner/src/eval/, or a binary subcommand named eval) is refused with "this command runs a string through eval", and compound commands (a && b, pipes) are refused as "too complex to verify". Workaround was writing one-line wrapper scripts to a scratch directory — workable, but the eval-substring match seems overly broad.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗