Bug: deleted session's UUID gets reused for a brand-new session (stale lastSessionId pointer)
Repro
- Run
claudein a project, then delete that session's transcript file (~/.claude/projects/<encoded-cwd>/<uuid>.jsonl) while the CLI is not running. - Launch a fresh, bare
claudein the same project directory. - Check
~/.claude.json→projects["<cwd>"].lastSessionId.
Result
lastSessionId still points at the UUID of the session that was just deleted in step 1. The new claude invocation reuses that same UUID for its own (brand-new, unrelated) session file, instead of generating a new one.
Why this matters
- The deleted session's UUID "comes back to life" attached to completely different content, which is confusing when cross-referencing IDs (e.g. in logs,
/resumehistory, or scripts). - If anything external keeps a reference to the old UUID (notes, bug reports, tooling), it will silently now resolve to unrelated content once the ID is recycled.
- More generally,
lastSessionIdis never invalidated/cleared when the session file it points to is removed, so this pointer can go stale any time a session is deleted out from under the CLI.
Verified
Reproduced live: deleted a session's .jsonl, confirmed via direct inspection that ~/.claude.json's lastSessionId for that project still referenced the deleted UUID, then launched a fresh claude and observed the new session file created on disk using that exact recycled UUID.
(Related to #85907 — same root cause class of "per-project state not cleaned up on session deletion," but this one is the lastSessionId pointer specifically rather than orphaned session files.)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗