`/desktop` session transfer drops the EnterWorktree working directory — Desktop resumes in the main checkout (wrong branch), no mismatch warning
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
- In a CLI session,
EnterWorktreeinto a worktree under<repo>/.claude/worktrees/<name>on a separate branch (e.g.feat/foo). Transcript showsEntered worktree at ... on branch feat/foo. - Run
/desktopto migrate the session to the Desktop app. - 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 priorEnterWorktreecontext 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
pwdreturns the main checkout root (.../PRD), not the worktree path.git rev-parse --abbrev-ref HEADreturns the branch the main checkout happens to be on — in my casefeat/260605-10-05-ledger, a different feature branch in use by another concurrent worktree workflow — not the worktree's ownfeat/260605-10-06-settlement.- The transcript still shows the earlier
Entered worktree ... on branch feat/260605-10-06-settlementresult, 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 commitbelieving it is inside the worktree, and the changes land on the main checkout's current branch. - In a
separate-git-dirrepo 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-parsecheck 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) —
gitBranchmetadata 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)
- On
/desktopmigration, restore the session's last-knownEnterWorktreecwd/branch. - If not restorable, inject a visible banner /
systemMessagestating the worktree context was dropped and the session is now in<cwd>@<branch>. - On resume, detect that the transcript's most recent
EnterWorktreetarget != 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
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗