EnterWorktree creates branch from main instead of current branch HEAD (macOS)

Resolved 💬 3 comments Opened Apr 8, 2026 by potterdigital Closed Apr 11, 2026

Bug Description

When using Agent(isolation: "worktree"), the worktree branch is created from main instead of the current branch HEAD. This causes the agent to work against main's file contents, and when the worktree branch is merged back, it overwrites the feature branch code.

Reproduction

  1. Be on a feature branch that has diverged significantly from main (e.g., 30+ commits ahead)
  2. Spawn an agent with isolation: "worktree":

``
Agent({
prompt: "...",
isolation: "worktree"
})
``

  1. The worktree is created from main, not from the current branch HEAD
  2. Agent makes commits against main's file tree
  3. Merging the worktree branch back overwrites all feature branch changes

Actual Behavior

  • Worktree branch is based on main
  • Agent edits files as they exist on main (missing all feature branch changes)
  • Merge-back is a fast-forward that replaces feature branch files with main versions
  • In our case: ~2,800 lines of feature code deleted

Expected Behavior

  • Worktree branch should be based on the current branch HEAD (git worktree add <path> -b <branch> HEAD)
  • Agent should see the same files as the current working tree

Environment

  • OS: macOS (Darwin 25.3.0)
  • Claude Code model: claude-opus-4-6 (1M context)
  • Branch at time of issue: v2.1-direct-signup (diverged from main)

Notes

  • The GSD framework (get-shit-done) documents this as a "known issue on Windows" and includes a git reset --soft workaround in agent prompts, but this only fixes the commit pointer — not the file contents
  • The issue also occurs on macOS, not just Windows
  • Related GSD issue: https://github.com/gsd-build/get-shit-done/issues/1957

View original on GitHub ↗

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