[BUG] Agent isolation: "worktree" bases branch on main instead of current HEAD (Windows)

Resolved 💬 3 comments Opened Mar 31, 2026 by begna112 Closed Apr 3, 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 spawning agents with isolation: "worktree" via the Agent tool, the created worktree branch is based on main instead of the current working branch (HEAD). This means the agent starts with a stale codebase missing all feature branch commits.

This is related to but distinct from #30070 (wrong remote). In this case there is only one remote -- the issue is that EnterWorktree uses main as the base branch instead of the current checked-out branch.

What Should Happen?

The worktree should be created from the current HEAD (whatever branch is checked out), not from main/master. When on feature/database-web-frontend, the worktree agent should start with that branch's code.

Steps to Reproduce

  1. Check out a feature branch that is ahead of main:

``
git checkout feature/my-branch # 24 commits ahead of main
``

  1. In a Claude Code session, spawn an agent with worktree isolation:

``
Agent(subagent_type="...", isolation="worktree", prompt="...")
``

  1. Observe the created worktree branch:

```
$ git worktree list
/repo 8171e72 [feature/my-branch] # current
/repo/.claude/worktrees/agent-abc 134f993 [worktree-agent-abc] # based on main!

$ git log --oneline -1 main
134f993 fix: ... # OLD

$ git log --oneline -1 feature/my-branch
8171e72 fix: ... # 24 commits ahead
```

Observed Impact

In a real workflow (GSD phase execution), 4 parallel agents were spawned with isolation: "worktree":

  • All 4 worktree branches were based on main (commit 134f993)
  • Missing 24 commits from the feature branch
  • 3 agents worked around it by committing directly to the feature branch (defeating isolation)
  • 1 agent failed entirely because it could not find feature-branch code it depended on

Error Messages/Logs

No error -- the worktree is created successfully, just from the wrong base. The agent silently starts with stale code.

Claude Model

Opus

Is this a regression?

No, this never worked

Claude Code Version

Latest as of 2026-03-31

Platform

Anthropic API

Operating System

Windows 11 Pro (10.0.26200)

Terminal/Shell

Git Bash (MSYS2/MINGW64)

Additional Information

  • Single remote (origin) -- this is NOT the multi-remote issue from #30070
  • The Agent tool's isolation parameter has no option to specify a base branch
  • Workaround: omit isolation: "worktree" and let parallel agents commit to the same branch with --no-verify

View original on GitHub ↗

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