claude-code - 💡(How to fix) Fix `/desktop` session transfer drops the EnterWorktree working directory — Desktop resumes in the main checkout (wrong branch), no mismatch warning

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  1. On resume, detect that the transcript's most recent EnterWorktree target != current cwd and warn.

Root Cause

I caught it only because project instructions mandate a pwd + branch check before any Write. Without that, the edits would have gone onto the wrong branch.

RAW_BUFFERClick to expand / collapse

Bug description

When a CLI session has entered a git worktree via EnterWorktree and is then migrated to the Claude Desktop app with /desktop, the Desktop session does not restore the worktree working directory. The migrated session resumes with its cwd at the main checkout root, on whatever branch the main checkout currently happens to be on — not the worktree branch.

Critically, the conversation transcript carried over by /desktop still contains the earlier Entered worktree at .../.claude/worktrees/<name> ... on branch <wt-branch> tool result. So both the user and the model are led to believe the session is still operating inside the worktree, while the actual runtime cwd is the main checkout. No warning is surfaced about the mismatch.

Steps to reproduce

  1. In a CLI session, EnterWorktree into a worktree under <repo>/.claude/worktrees/<name> on a separate branch (e.g. feat/foo). Transcript shows Entered worktree at ... on branch feat/foo.
  2. Run /desktop to migrate the session to the Desktop app.
  3. In the Desktop session, run pwd && git rev-parse --abbrev-ref HEAD.

Expected behavior

Either:

  • The Desktop session restores the same worktree cwd/branch the CLI session was in, or
  • If the runtime cwd genuinely cannot be migrated, /desktop (or the Desktop session on resume) surfaces a clear warning that the prior EnterWorktree context was not restored and the session is now in <cwd> on branch <branch> — so the model doesn't silently keep assuming the worktree.

Actual behavior

  • pwd returns the main checkout root (.../PRD), not the worktree path.
  • git rev-parse --abbrev-ref HEAD returns the branch the main checkout happens to be on — in my case feat/260605-10-05-ledger, a different feature branch in use by another concurrent worktree workflow — not the worktree's own feat/260605-10-06-settlement.
  • The transcript still shows the earlier Entered worktree ... on branch feat/260605-10-06-settlement result, with nothing indicating it no longer reflects reality.
  • No mismatch warning anywhere.

Impact

A silent wrong-branch data-loss hazard. Same symptom family as #36182 / #20406 but triggered by a different path — /desktop cross-client transfer, rather than subagent path resolution or stale gitBranch metadata:

  • A model that trusts the transcript will run Write / Edit / git commit believing it is inside the worktree, and the changes land on the main checkout's current branch.
  • In a separate-git-dir repo with multiple concurrent worktrees, the main checkout can be parked on an unrelated feature branch, so edits intended for worktree A silently pollute branch B.
  • Only an explicit pwd + git rev-parse check reveals the mismatch — which the model has no reason to run if it trusts the transcript.

I caught it only because project instructions mandate a pwd + branch check before any Write. Without that, the edits would have gone onto the wrong branch.

Diagnostic detail

Re-issuing EnterWorktree with path: <worktree> inside the Desktop session correctly switches back — verified with pwd, git rev-parse --show-toplevel, and a probe file that showed up only in the worktree branch's git status, not the main checkout's. So the worktree itself is fully intact; the issue is purely that /desktop does not replay/restore the runtime cwd state established by EnterWorktree.

Related

  • #36182 — worktree Edit/Read tools target main-workspace paths (different trigger, same silent-wrong-branch symptom)
  • #20406 (closed as duplicate) — gitBranch metadata not refreshed after cwd changes (this report is stronger: the cwd itself is the main checkout, not merely stale metadata)
  • #60097 — Desktop has no worktree/cwd indicator, which compounds this: there is no UI cue that the session is no longer in the worktree

Suggested fix (any of)

  1. On /desktop migration, restore the session's last-known EnterWorktree cwd/branch.
  2. If not restorable, inject a visible banner / systemMessage stating the worktree context was dropped and the session is now in <cwd>@<branch>.
  3. On resume, detect that the transcript's most recent EnterWorktree target != current cwd and warn.

Environment

  • Claude Code CLI 2.1.163; transcript version 2.1.161
  • Claude Desktop app 1.11187.1
  • macOS 15.7.4 (24G517), Apple Silicon
  • Repo uses git separate-git-dir; worktrees under <repo>/.claude/worktrees/<name>; multiple concurrent worktrees on different feature branches

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Either:

  • The Desktop session restores the same worktree cwd/branch the CLI session was in, or
  • If the runtime cwd genuinely cannot be migrated, /desktop (or the Desktop session on resume) surfaces a clear warning that the prior EnterWorktree context was not restored and the session is now in <cwd> on branch <branch> — so the model doesn't silently keep assuming the worktree.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING