claude-code - 💡(How to fix) Fix ~/.claude/sessions/{PID}.json sessionId field doesn't refresh on /clear — only updatedAt does [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53037Fetched 2026-04-25 06:14:05
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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.

extent analysis

TL;DR

Update the sessionId field in the pid file when a new session is started after /clear to reflect the current session ID.

Guidance

  • The issue is caused by the sessionId field in the pid file not being updated after /clear, resulting in tools reading a stale session ID.
  • To verify, check the pid file before and after running /clear and compare the sessionId field with the actual current session ID in the new jsonl file.
  • A potential workaround is to update the tooling to read the sessionId from the latest jsonl file instead of relying on the pid file.
  • The SessionStart:clear hook firing with the new session ID in additionalContext could be used to update the pid file with the correct sessionId.

Example

No code snippet is provided as the issue does not imply a specific code change, but rather a logical update to the pid file.

Notes

The issue is specific to the behavior of the /clear command and the updating of the pid file. The SessionStart:clear hook provides a potential solution to update the pid file with the correct sessionId.

Recommendation

Apply a workaround to update the tooling to read the sessionId from the latest jsonl file or use the SessionStart:clear hook to update the pid file, as updating the pid file directly may require changes to the underlying system.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING