Agent tool isolation: "worktree" forks from default branch instead of caller's current HEAD

Resolved 💬 3 comments Opened Apr 8, 2026 by RyanSinger Closed Apr 12, 2026

Summary

When dispatching a subagent via the Agent tool with isolation: "worktree" from a non-default branch, the resulting worktree consistently forks from the default branch (main) instead of the caller's current branch HEAD. This silently gives subagents the wrong baseline.

Environment

  • Claude Code: 2.1.96 (observed in-session)
  • Platform: darwin 25.3.0
  • Repo: standard git repo with main as default, other local branches checked out

Reproduction

  1. git checkout -b feature-branch and make one or more commits on it
  2. Dispatch a subagent from the Agent tool with isolation: "worktree" and any subagent_type
  3. Inside the worktree, the subagent sees git log --oneline -5 showing main's HEAD, not feature-branch's HEAD
  4. Files modified on feature-branch are missing from the subagent's working tree

Observed frequency

In a single session running an iterative multi-agent loop, 8 of 9 dispatches forked from \main\ instead of the current branch. One dispatch had no worktree created at all; the agent edited the parent checkout directly.

Expected

Worktree should fork from the caller's current branch HEAD, matching what \git worktree add\ does with no explicit ref.

Impact

Subagents receive stale baselines, silently revert or skip work from prior commits, and produce diffs that cannot cleanly merge back. In iterative workflows where each step builds on the previous one, this breaks the pipeline unless every dispatch includes a manual baseline-sync workaround.

Workaround

Have the subagent run \git checkout <current-branch> -- <paths>\ and commit a \"baseline-sync\" as its first action, then extract only its incremental work via \git diff baseline-sync HEAD\ on merge.

View original on GitHub ↗

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