~/.claude/sessions/{PID}.json sessionId field doesn't refresh on /clear — only updatedAt does
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
- start a cc session in any workspace
- note the pid file:
cat ~/.claude/sessions/<PID>.json— it showssessionId: "A", matching/status - run
/clearinside the session ls -t ~/.claude/projects/<workspace-slug>/*.jsonl— you'll see a new uuid B's jsonl being actively written, and A's jsonl frozen- read the pid file again:
cat ~/.claude/sessions/<PID>.json
sessionIdstill reads "A" (stale)updatedAtis 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:clearhook fires and literally prints the new sessionId inadditionalContext— 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_FILEnot 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:clearmatcher 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗