EnterWorktree intermittently returns false subagent isolation error from main session
Summary
EnterWorktree(name=...) intermittently fails with a false subagent isolation error when called from the main session (not a subagent). The exact same call -- identical parameters -- succeeds on retry without any environmental change.
Reproduction
- Start a session in a git repo main checkout (not inside a worktree)
- Call EnterWorktree(name=some-worktree-name)
- First call fails with: EnterWorktree cannot be called from a subagent with a cwd override (isolation: worktree or explicit cwd) -- it would mutate the parent session process-wide working directory. This agent is already isolated in its own working copy.
- Retry the exact same call -- same failure
- Retry again (or after user interrupts and re-prompts) -- succeeds
Evidence
Observed in 2 independent sessions on the same repo, same pattern:
Session 1 (7537afaf):
- Line 537: EnterWorktree(name=slice-e8-s29-a-pdf-generation) -- FAIL
- Line 550: same call -- FAIL
- Line 567: same call -- SUCCESS
Session 2 (915024db):
- Line 516: EnterWorktree(name=slice-e8-pr31-c-notifications-ui) -- FAIL
- Line 528: same call -- FAIL
- Line 578: same call -- SUCCESS (after deleting an unrelated branch and returning to dev)
In all cases:
- pwd confirms the main repo root (not inside .claude/worktrees/)
- git rev-parse --git-common-dir returns .git (not a linked worktree)
- No isolation: worktree parameter was passed -- only name
- No prior Agent(isolation: worktree) calls in the session
- No active worktrees at time of call (worktrees are removed after each use via ExitWorktree)
Environment
- Claude Code: 2.1.118
- macOS Darwin 24.6.0
Expected behavior
EnterWorktree(name=...) should succeed on the first call when invoked from the main session at the repo root with no active worktree context.
Notes
The runtime subagent isolation detection appears to be checking stale state or incorrectly inheriting a flag. The error is transient -- the identical call succeeds after 2 failures with no meaningful environmental change between attempts.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗