Agent tool: isolation: "worktree" creates worktree from default branch instead of parent HEAD

Resolved 💬 4 comments Opened May 10, 2026 by petervines Closed May 10, 2026

Summary

When dispatching a subagent via the Agent tool with isolation: "worktree", the created git worktree is sometimes based on the repository's default branch (main) or the initial commit, rather than the parent session's current HEAD. This causes subagents to operate on a stale tree and either silently regress files or fail downstream consistency checks.

Environment

  • Claude Code 2.1.138
  • macOS (Darwin 25.3.0)
  • Repos affected: multiple, all using a feature/epic branch off develop (i.e. not the repository's default branch)

Reproduction

  1. In a git repo, check out a feature/epic branch that is not the repository's default branch and has commits beyond it.
  2. From a Claude Code session on that branch, dispatch a subagent with isolation: "worktree".
  3. Have the subagent run git rev-parse HEAD and git log -1 --oneline as its first action.
  4. Compare to the parent session's git rev-parse HEAD.

Expected: worktree HEAD == parent HEAD (or at minimum, contains parent HEAD as an ancestor with no divergence).

Actual: worktree HEAD is the repository's default branch tip, or in some cases the repository's initial commit. The current branch's commits are absent.

Impact

Subagents see "out-of-date" files (config, build manifests, lockfiles) and "helpfully fix" them, producing edits that look like regressions when merged. We have observed this twice in production multi-agent runs across two different repos.

Workaround

We routed around it by avoiding isolation: "worktree" entirely and running subagents in the parent checkout sequentially. We also added a guard that captures EXPECTED_BASE=\$(git rev-parse HEAD) in the parent and asks the subagent to verify on entry; the guard reliably fires when the bug occurs, confirming the divergence is between parent HEAD and worktree HEAD (not stale-parent vs current-parent).

Asks

  1. Document what base ref isolation: "worktree" uses (HEAD? default branch? something else?).
  2. If it is not parent HEAD, expose a parameter (e.g. worktreeBase: "HEAD" | <ref>) so callers can pin it.

View original on GitHub ↗

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