Chip-spawned task runs on primary checkout instead of fresh worktree
Summary
A task spawned by clicking a chip created via mcp__ccd_session__spawn_task opens a new session that runs on the primary checkout's current branch (e.g. main), not in a fresh git worktree under .claude/worktrees/agent-<hash>/. This contradicts the documented desktop-app contract that each session is automatically isolated in its own worktree.
Expected behavior
Per the docs:
- Worktrees: "The desktop app creates a worktree for every new session automatically."
- Desktop: "For Git repositories, each session gets its own isolated copy of your project using Git worktrees, so changes in one session don't affect others."
- Issue #53494 (chip flow): "User clicks the chip — task spawns to a fresh worktree."
- Issue #50109 (request for
--no-worktreeopt-out) was closed; no opt-out exists.
The chip-spawned session should:
- Create
.claude/worktrees/agent-<hash>/under the project root. - Open the new session with its CWD inside that worktree.
- Have HEAD on a fresh branch, not on the primary checkout's current branch.
Actual behavior
The chip-spawned session opens with its CWD on the primary checkout, on the primary's current branch. No .claude/worktrees/agent-<hash>/ directory is created for it.
Evidence from the Code-tab session footer of a chip-spawned session in a private repo:
<repo> main +0 -310 [Create PR]
The footer shows main (the primary branch), not the documented agent-<hash> worktree branch. The +0 -310 is a working-tree diff against main — i.e. the spawned session is editing files directly on the primary checkout. Any commit it makes will land on main of the primary, exactly the contamination the worktree contract is supposed to prevent.
Reproduction
- From a parent Claude Code session, invoke
mcp__ccd_session__spawn_taskwith atitle,prompt, andtldr. A chip appears in the parent's UI. - Click the chip.
- In the spawned session's footer (Code tab), observe the branch label.
- Run inside the spawned session:
``bash``
pwd
git rev-parse --show-toplevel
git rev-parse --abbrev-ref HEAD
git rev-parse --git-common-dir
- Expected:
pwdends in.claude/worktrees/agent-<hash>;--show-toplevelreturns that worktree path;HEADis a fresh branch;--git-common-dirpoints at the primary's.git/. - Actual:
pwdis the primary checkout;HEADis the primary's current branch (e.g.main); the worktree was never created.
Impact
- Silent contract violation. Both the desktop docs and the chip's own UX (chip → "fresh session") imply isolation. Sessions appear isolated but mutate the primary tree.
- Risk of accidental commits to
main. A spawned session that thinks it's in its own worktree (per the documented contract) will happilygit commitand land work directly on the parent's working branch. - Confounds debugging. Because the worktree contract is documented as unconditional, downstream rules and skills assume it.
Environment
- OS: Windows 11 Pro (10.0.22621)
- Claude Code desktop version: 1.9659.2 (390d6c)
.claude/worktrees/directory existed prior to chip-click: yes (sibling agent worktrees already present)- Filesystem: local NTFS; no symlinks involved; path lengths well under Windows MAX_PATH
Notes
- Tested via the standard chip UX in the Claude Desktop "Code" tab; not via the CLI
claude --resumeflow. - The
mcp__ccd_session__spawn_tasktool's own parameter surface (title,prompt,tldr) exposes no worktree-control flag, consistent with the docs treating worktree creation as the unconditional default.
Related issues, not duplicates
These all touch the same area but report different failure modes. This bug is "no worktree created at all" — the spawned session never enters worktree isolation in the first place.
- #57643 (closed) —
spawn_taskcreates the worktree offorigin/maininstead of the parent's branch. Different: assumes a worktree is created and discusses its base branch. - #52243 (closed) — Chips should branch from parent's branch, not repo default. Different: same as above, assumes worktree exists.
- #57512 (open) —
spawn_taskshould auto-add.claude/worktrees/to.git/info/exclude. Different: assumes the worktree directory is created. - #59628 (open) — Worktree sessions can edit files in the parent main checkout via absolute path. Different: the worktree exists; the agent escapes it via absolute paths. Here, no worktree exists to escape from.
- #36182 (open) — Worktree Edit/Read tools use main-workspace paths instead of worktree paths. Different: worktree exists; tool path-resolution bug.
- #63008 (open) —
preview_startMCP spawns dev server with main-repo cwd from a worktree session. Different: worktree exists; downstream MCP child inherits wrong cwd.
Showing cached comments. Read the full discussion on GitHub ↗
5 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Thanks for the auto-flag. Looked at both suggested duplicates — they share a theme with this report (worktree isolation failing silently, agent ends up on the primary checkout), but the surface and contract are different enough that I think they're worth tracking separately.
Suggested dupes:
Agenttool'sisolation: "worktree"parameter silently ignored for team agents.Agenttool flag silently ignored for concurrent background agents (reports literal"null"in returnedworktreePath).Why this report is different:
| Dimension | #33045 / #48811 | This report (#64605) |
|---|---|---|
| Surface |
Agenttool (programmatic subagent spawn) |mcp__ccd_session__spawn_task(desktop chip MCP) || Trigger | Explicit opt-in: caller sets
isolation: "worktree"| No parameter exists; worktree is the unconditional documented default for chip-spawned sessions || Evidence | Tool returns include
worktreePath: ".../null"or agent reportspwd= main repo | Desktop Code-tab session footer displays<repo> mainwith a working-tree diff againstmain|| Caller intent | Programmatic, agent-orchestration code paths | User clicks a UI chip; entire desktop "Code" tab session is supposed to be isolated |
| Fix surface | Honor an opt-in flag inside the Agent tool's spawn path | Restore the unconditional desktop-session worktree creation for the chip flow |
The two
Agent-tool bugs are about an opt-in flag being ignored. This one is about a default contract being violated on a different code path (desktop session creation, not subagent spawn). It's possible all three share a root cause in whatever common "create session worktree" routine exists — but the user-facing surfaces, repros, and evidence are distinct, and a fix that lands on the Agent-tool path wouldn't necessarily restore the desktop-chip default.Happy to consolidate if the team confirms a single root cause once it's been root-caused. Until then I'd prefer to keep this open so the chip-flow regression doesn't get masked by an Agent-tool fix.
For triage, the closest open issue I'm aware of is #57512 (
spawn_task should auto-add .claude/worktrees/ to .git/info/exclude) — same MCP tool, but it explicitly assumes the worktree directory is created, which is the precondition that's failing here.Do you mind pointing me to the documentation? Worktrees aren't on my default, you have to opt in.
I'm adjusting the spawn task UI/UX so that it's easier and more clear when a worktree will be used.
Thanks @amorriscode! Glad to see the chip-spawn UX is getting some love, I use it pretty heavily and it's very efficient to stop the main session chewing a lot of tokens.
The chip flow itself (the
mcp__ccd_session__spawn_tasktool) seems to be undocumented right now?What I was inferring from is the desktop-session wording, which does say automatic in a couple of spots:
--worktreeopt-in for CLI).The real question might be: does the chip path default differently than "+ New session"? Pretty sure this behaviour changed between desktop versions , and I don't have any worktree.* / bgIsolation set.
Is the intent to have this configurable in settings? This would probably be ideal.
Confirming this on macOS (Darwin 25.5.0) as well — the issue is currently labeled
platform:windowsbut the behavior is the same here.Additional data point on impact: I had a parent session create 3 chips via
spawn_taskand clicked all three. All three spawned sessions ran on the same primary checkout concurrently (no per-chip worktree), so the three agents edited the same working tree at once and clobbered each other's uncommitted changes / branches.So beyond the single-session contamination already described, the lack of worktree isolation makes concurrent chips actively unsafe. A clear indicator of whether a chip will use a worktree (per @amorriscode's UX work) would help a lot here.