Task tool with isolation=worktree leaks CWD to parent session
Resolved 💬 3 comments Opened Feb 24, 2026 by Gab-CosmoLabs Closed Feb 27, 2026
Description
When a Task tool agent runs with isolation: "worktree", the parent session's Bash CWD permanently drifts to the worktree path (.claude/worktrees/agent-xxx/). The parent session should be completely unaffected by subagent filesystem operations.
Steps to Reproduce
- Start a Claude Code session in a project directory (e.g.,
/Users/me/project) - Dispatch a Task tool call with
isolation: "worktree" - The subagent runs — it creates/copies files using absolute paths
- After the subagent completes, run
pwdin the parent session - CWD is now
.claude/worktrees/agent-xxx/instead of/Users/me/project
Expected Behavior
Parent session CWD remains at /Users/me/project regardless of what the worktree subagent does. The isolation boundary should be complete — the parent's shell state should not be affected.
Actual Behavior
Parent session CWD drifts to the worktree path and stays there. Subsequent Bash commands run in the wrong directory. If the user has a cd-guard hook, it blocks returning to the original directory, compounding the problem.
Additional Context
- The worktree and main repo share the same filesystem (git worktrees are just alternate checkouts), so
cpwith absolute paths between them works — but this seems to cause the CWD leak - Workaround: user must manually
cdback in their terminal - This affects any workflow that uses
isolation: "worktree"for parallel agent work
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗