Write/Edit tools stay pinned to a subagent's launch-time worktree after it calls EnterWorktree to switch to a new one (Bash cwd follows correctly)
Summary
When a subagent (launched via the Agent tool) calls EnterWorktree mid-task to create and switch into its own fresh worktree, the Bash tool's cwd correctly follows the switch — but the Write/Edit tools continue targeting the subagent's original launch-time worktree path (its parent session's cwd at dispatch time), not the new worktree EnterWorktree just reported switching into.
Reproduction
Reproduced 3 times independently in a single session, same exact symptom each time:
- Orchestrating session's cwd is worktree A (
.claude/worktrees/<repo>/<worktree-A>). - Dispatch a background subagent (
Agenttool) with instructions to isolate its own work by callingEnterWorktreeto create a new worktree B before editing anything. - Subagent calls
EnterWorktree(noname/pathcollision) — tool reports success, a new worktree B is created and the subagent's session is switched into it. - Subagent's subsequent
Bashcalls correctly show cwd as worktree B (confirmed viapwd). - Subagent's subsequent
Write/Editcalls on a path relative to worktree B fail or resolve against worktree A instead — the file-edit tools behave as if still pinned to worktree A, the subagent's original launch-time location.
All 3 subagents worked around it by performing file writes through Bash (heredoc / a small Python script invoked via Bash) instead of Write/Edit, since Bash's cwd tracking was the one that actually reflected the real EnterWorktree switch.
Expected behavior
After a subagent calls EnterWorktree and it reports success, Write/Edit should resolve paths against the new worktree, the same way Bash's cwd does.
Actual behavior
Write/Edit stay resolved against whatever worktree path the subagent was launched into (apparently a static permission/path boundary set once at subagent launch), unaffected by the subagent's own later EnterWorktree call. Bash's cwd tracking is dynamic and correctly follows the switch.
Environment
- Claude Code CLI, subagents launched via the
Agenttool (run_in_background: true), each independently instructed to callEnterWorktree(nopathargument — creating a fresh worktree, not entering an existing one) before making edits. - Reproduced across 3 different subagents in the same orchestrating session, each isolating into its own distinct new worktree, all in the same repository.
Workaround in use
Route all file writes for any subagent that calls EnterWorktree mid-task through Bash (heredoc or a script) rather than Write/Edit, since only Bash's cwd tracking reflects the real switch.