[BUG] /desktop "cannot determine working directory" after EnterWorktree→ExitWorktree — session transcript fragmented across two project slugs; /desktop resolves to a bridge-session record with no cwd
Refile of #64191, which was auto-closed as a duplicate of #41688 / #41723 / #48809. It is not a duplicate of those — see "Why this is not a duplicate" below. Reopen was not possible (the issue was closed by automation, not by me), so this refiles the specific, uncovered root cause with sharper framing.
Summary
When a CLI session changes its working directory via EnterWorktree → ExitWorktree and then runs /desktop, the handoff fails with:
Cannot determine working directory for CLI session <session-id> — the transcript may be incomplete
The session has a full transcript. The real problem is that one session id's transcript is fragmented across two ~/.claude/projects/<slug>/ directories, and /desktop resolves the id to a 1-line bridge-session record under the parent slug that has no cwd field at all — never consulting the worktree-slug fragment where the real conversation (and valid cwd values) live.
Why this is not a duplicate
- #41688 (CLOSED/COMPLETED, fix shipped ~2026-04) — triggered by worktree deletion leaving the shell cwd stuck on a deleted path. This bug involves no deletion, and it reproduces on CLI 2.1.158 / Desktop 1.9659.2 (2026-05-28) — after that fix shipped.
- #41723 (CLOSED/DUPLICATE → #41634) and #48809 (CLOSED/NOT_PLANNED) — both describe the generic "importCliSession reads only the first line / first record has no
cwd" parse bug, i.e. one file whose leading record lackscwd.
The failure here is a level above "first line has no cwd": /desktop resolves the session id to the wrong file entirely — a bridge-session stub under a different project slug — because the Enter/Exit-worktree lifecycle scatters one session id across multiple slugs. Fixing the first-line parse alone would not fix this, because the file /desktop reads has no conversation in it at all.
What's on disk
For a single session id <SID> there are two transcript files:
~/.claude/projects/<parent-slug>/<SID>.jsonl— 1 line, nocwd:
``json``
{"type":"bridge-session","sessionId":"<SID>","bridgeSessionId":"cse_…","lastSequenceNum":0}
~/.claude/projects/<worktree-slug>/<SID>.jsonl— the real conversation (~1.2k lines). Validcwdvalues are present (both the worktree path and the parent path), though the first line is{"type":"last-prompt","cwd":null,…}.
/desktop runs after ExitWorktree (session cwd back at the parent), writes the bridge-session record under the parent slug, and Desktop resolves <SID> to that parent-slug fragment — which carries no cwd — and errors.
Steps to reproduce
- Start a CLI session in a git repo.
EnterWorktree(create/enter a worktree).- Do some work.
ExitWorktreewithkeep./desktop.
→ Desktop errors: Cannot determine working directory … the transcript may be incomplete.
Root cause
- A session that changes cwd via Enter/Exit worktree writes transcript entries under different
projects/<slug>/dirs (the slug is derived from cwd). - The
/desktopbridge record is written under the current (post-exit) cwd's slug, which need not be the slug holding the conversation — and the bridge record itself carries nocwd. - Desktop's cwd resolution sees a fragment with no usable
cwdand gives up.
Suggested fix direction
- When resolving a CLI session's cwd, consult all
projects/*/<SID>.jsonlfragments for that session id, not just the one under the current slug. - Scan for the last non-null
cwd(the first line can legitimately becwd:null) rather than failing on the first/only record. - Fallback: derive cwd from the
projects/<slug>directory name, which already encodes the path.
Related
- #64191 — the prior report this refiles (auto-closed as duplicate).
- #62017 —
/desktopon an empty first-command session →CLI session transcript not found; same theme (resolves to a transcript that yields no cwd). - #65554 / #65808 — the same
/desktop⇄ worktree cluster (runtime cwd dropped on transfer; UI branch indicator stale).
Environment
- Claude Code CLI 2.1.158 (also reproduced on later 2.1.x)
- Desktop Claude 1.9659.2 (390d6c) — 2026-05-28
- macOS (Darwin 24.6.0), Apple Silicon
- Repo uses git
separate-git-dir; worktrees under<repo>/.claude/worktrees/<name>
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗