[BUG] Agent tool isolation:"worktree" bases the new worktree on the repo's default branch, not the currently-checked-out branch
Description
When the Agent tool is called with isolation: "worktree", the new worktree it creates is based on the repository's default branch (e.g. master, whatever git remote show origin reports as HEAD branch), not the branch that is currently checked out in the calling session's working directory.
This means any sub-agent spawned with isolation: "worktree" from a non-default feature branch starts on an entirely unrelated codebase state, rather than continuing the feature work it was asked to do.
Reproduction
- In a repo, check out a feature branch that has diverged significantly from the default branch (e.g. entire directories added that don't exist on
master). - Call the
Agenttool withisolation: "worktree"and a prompt referencing files/paths that only exist on the feature branch. - Observe that the created worktree (and its
worktree-agent-*branch) is based on the default branch's HEAD commit, not the feature branch's HEAD — the referenced files/paths do not exist.
Observed impact
Reproduced twice independently in the same session, with two different agent launches producing two different worktree-agent-* branches, both landing on the default branch's HEAD commit and missing an entire top-level directory that only exists on the feature branch.
Both spawned agents correctly self-detected the mismatch (they were explicitly instructed to verify branch/expected files before starting) and stopped without making changes — no destructive action was taken — but this required extra instruction-writing and a manual workaround (git worktree add -b <branch> <path> <current-branch> followed by an Agent call without isolation, pointed at the manually created directory) to get a sub-agent working on the correct branch state at all.
Expected behavior
isolation: "worktree" should base the new worktree on the branch/commit currently checked out in the working directory the Agent tool call is made from, not the repository's configured default branch.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗