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)

Status Open
Maintainer reply None cached
Activity 0 comments · opened Jul 29, 2026

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:

  1. Orchestrating session's cwd is worktree A (.claude/worktrees/<repo>/<worktree-A>).
  2. Dispatch a background subagent (Agent tool) with instructions to isolate its own work by calling EnterWorktree to create a new worktree B before editing anything.
  3. Subagent calls EnterWorktree (no name/path collision) — tool reports success, a new worktree B is created and the subagent's session is switched into it.
  4. Subagent's subsequent Bash calls correctly show cwd as worktree B (confirmed via pwd).
  5. Subagent's subsequent Write/Edit calls 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 Agent tool (run_in_background: true), each independently instructed to call EnterWorktree (no path argument — 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.

View original on GitHub ↗