[BUG] `isolation: "worktree"` on Agent tool creates worktree but doesn't bind subagent CWD or rewrite parent-path references

Resolved 💬 2 comments Opened May 27, 2026 by InonS Closed May 31, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When dispatching an Agent tool call with isolation: "worktree", the harness creates a worktree under .claude/worktrees/agent-<id>/ (visible in git worktree list), but the subagent's tool calls operate against the parent's main checkout — not the worktree. The isolation parameter ends up advertising a guarantee it doesn't enforce.

Impact

Foot-gun for the long-running-agent pattern (cwc-long-running-agents). The exact failure mode isolation: "worktree" reads as preventing is the one we hit. Workaround is manual git worktree add invoked outside the Agent tool, which defeats the purpose.

What Should Happen?

Either:

  • (a) The subagent's CWD is bound to the worktree, OR
  • (b) Absolute paths under the project root are rewritten to the worktree path, OR
  • (c) The harness rejects or warns when subagent tool calls would escape the worktree.

Error Messages/Logs

Worktree is created but unused. Subagent operates in parent CWD. Parent's `git status` shows untracked files / branch switches from the subagent's work, which then trips Stop hooks during the parent's turn (e.g., `~/.claude/stop-hook-git-check.sh` warning "uncommitted changes"). Parallel subagents also clobber each other's WIP on the shared checkout.

Steps to Reproduce

  1. Run a long-running agent that dispatches an Agent subagent with isolation: "worktree".
  2. Include in the subagent prompt: paths under the project root (e.g., "in /home/user/myrepo, edit foo.py and commit").
  3. Observe the subagent's edits land in the parent's main checkout, switching branches and adding untracked files there — not in the worktree.

Environment

  • Claude Code (Web), Opus 4.7 1M
  • Linux 6.18.5 sandbox

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

Claude 1.9255.2 (1dc8f7) 2026-05-27T01:57:20.000Z

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗