Chip-spawned task runs on primary checkout instead of fresh worktree

Status Fixed / completed
Maintainer reply ✓ Yes — amorriscode
Activity 6 comments · opened Jun 2, 2026 · closed Jun 25, 2026
💡 Likely answer: A maintainer (amorriscode, contributor) responded on this thread — see the highlighted reply below.

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-worktree opt-out) was closed; no opt-out exists.

The chip-spawned session should:

  1. Create .claude/worktrees/agent-<hash>/ under the project root.
  2. Open the new session with its CWD inside that worktree.
  3. 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

  1. From a parent Claude Code session, invoke mcp__ccd_session__spawn_task with a title, prompt, and tldr. A chip appears in the parent's UI.
  2. Click the chip.
  3. In the spawned session's footer (Code tab), observe the branch label.
  4. 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: pwd ends in .claude/worktrees/agent-<hash>; --show-toplevel returns that worktree path; HEAD is a fresh branch; --git-common-dir points at the primary's .git/.
  • Actual: pwd is the primary checkout; HEAD is 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 happily git commit and 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 --resume flow.
  • The mcp__ccd_session__spawn_task tool'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_task creates the worktree off origin/main instead 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_task should 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_start MCP spawns dev server with main-repo cwd from a worktree session. Different: worktree exists; downstream MCP child inherits wrong cwd.

View original on GitHub ↗

5 Comments

github-actions[bot] · 3 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/33045
  2. https://github.com/anthropics/claude-code/issues/48811
  3. https://github.com/anthropics/claude-code/issues/64605

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

0xDarkMatter · 3 months ago

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:

  • #33045 — Agent tool's isolation: "worktree" parameter silently ignored for team agents.
  • #48811 — Same Agent tool flag silently ignored for concurrent background agents (reports literal "null" in returned worktreePath).

Why this report is different:

| Dimension | #33045 / #48811 | This report (#64605) |
|---|---|---|
| Surface | Agent tool (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 reports pwd = main repo | Desktop Code-tab session footer displays <repo> main with a working-tree diff against main |
| 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.

amorriscode contributor · 2 months ago
This contradicts the documented desktop-app contract that each session is automatically isolated in its own worktree.

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.

0xDarkMatter · 2 months ago

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_task tool) 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:

  • worktrees: "The desktop app creates a worktree for every new session automatically."
  • desktop: "each session gets its own isolated copy of your project using Git worktrees" — and the CLI-vs-Desktop table on that page lists Desktop session isolation as "Automatic worktrees" (vs --worktree opt-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.

ChaMinGyuSoftleaf · 2 months ago

Confirming this on macOS (Darwin 25.5.0) as well — the issue is currently labeled platform:windows but the behavior is the same here.

Additional data point on impact: I had a parent session create 3 chips via spawn_task and 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.

Showing cached comments. Read the full discussion on GitHub ↗