/desktop fails to import CLI sessions when first JSONL line has no cwd

Resolved 💬 3 comments Opened Apr 1, 2026 by kays0x Closed Apr 4, 2026

Bug

/desktop (CLI-to-Desktop session transfer) fails with "transcript has no cwd - cannot import" for roughly half of all sessions.

Root cause

importCliSession in the Desktop app reads only the first line of the session JSONL to extract cwd:

for await (const b of _) {
  const A = JSON.parse(b);
  typeof A.cwd == "string" && A.cwd.length > 0 && be.isAbsolute(A.cwd) && (a = A.cwd);
  break;  // exits after first line regardless
}
if (!a) throw new Error(`CLI session ${e} transcript has no cwd — cannot import`);

The first line of a session JSONL is nondeterministic. It can be:

  • progress - has cwd field, import works
  • file-history-snapshot - no cwd field, import fails
  • queue-operation - no cwd field, import fails

Out of 31 local sessions: 15 start with progress (would work), 12 with file-history-snapshot (broken), 4 with queue-operation (broken).

Expected fix

Replace the break with a loop that scans until it finds a line with a valid cwd:

for await (const b of _) {
  const A = JSON.parse(b);
  if (typeof A.cwd == "string" && A.cwd.length > 0 && be.isAbsolute(A.cwd)) {
    a = A.cwd;
    break;
  }
}

Repro

  1. Start a CLI session (claude in terminal)
  2. Use the session for a bit (especially if file tracking or /clear triggers a file-history-snapshot as the first entry)
  3. Run /desktop
  4. CLI says "Session transferred to Claude Desktop" but Desktop shows error dialog: "Couldn't open session" / "transcript has no cwd - cannot import"

Environment

  • CLI version: 2.1.87
  • Desktop app: latest (2025-03-31)
  • macOS

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗