~/.claude/sessions/{PID}.json sessionId field doesn't refresh on /clear — only updatedAt does

Resolved 💬 3 comments Opened Apr 24, 2026 by seanmartinsmith Closed Jun 3, 2026

summary

cc maintains ~/.claude/sessions/{PID}.json with fields like pid, sessionId, cwd, startedAt, updatedAt. when /clear rotates the session and writes a new transcript jsonl with a new uuid, the pid file's updatedAt keeps refreshing (heartbeat-style) but the sessionId field stays frozen at the pre-/clear value.

tooling that walks the process tree → finds cc's pid → reads ~/.claude/sessions/{PID}.json to identify the current session ends up with a stale id post-/clear.

reproduction

  1. start a cc session in any workspace
  2. note the pid file: cat ~/.claude/sessions/<PID>.json — it shows sessionId: "A", matching /status
  3. run /clear inside the session
  4. ls -t ~/.claude/projects/<workspace-slug>/*.jsonl — you'll see a new uuid B's jsonl being actively written, and A's jsonl frozen
  5. read the pid file again: cat ~/.claude/sessions/<PID>.json
  • sessionId still reads "A" (stale)
  • updatedAt is fresh

evidence

tested on v2.1.119, windows 11. captured pid file state pre/post /clear:

  • pid file before: {"pid":45152,"sessionId":"4d417de0-...", "updatedAt":1777069791355,...}
  • pid file after: {"pid":45152,"sessionId":"4d417de0-...", "updatedAt":1777069985337,...} — only updatedAt changed
  • workspace dir after: 4d417de0-....jsonl (frozen mtime) + 0613650d-....jsonl (new, actively writing)
  • last line of new jsonl: "sessionId":"0613650d-..." (the actual current session)
  • the SessionStart:clear hook fires and literally prints the new sessionId in additionalContext — so cc knows

impact

any tool that reads the pid file to identify the current session — looking up transcript paths, attributing work, auditing activity — gets the pre-/clear value. this is independent of #14433 (CLAUDE_ENV_FILE not re-sourced on /clear): even tools that avoid env vars and go straight to the pid file still hit a stale value.

related

  • #14433 — CLAUDE_ENV_FILE not sourced after /clear (closed not-planned)
  • #6428 — SessionEnd hook doesn't fire with /clear (open)
  • #28692 — /clear doesn't fire SessionStart (closed duplicate, appears resolved — SessionStart:clear matcher does fire on v2.1.119)

the SessionStart:clear firing closed the hook-event gap. refreshing sessionId in the pid file on each session rotation would close the identity-resolution gap for tools that need a stable per-process signal across /clear.

View original on GitHub ↗

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