[BUG] /clear creates new session JSONL but never updates ~/.claude/sessions/<pid>.json — breaks PID-to-session mapping

Resolved 💬 2 comments Opened Mar 19, 2026 by NicoMunozZenity Closed Apr 17, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a user runs /clear, Claude Code creates a new JSONL file with a fresh sessionId but never updates the PID session file at ~/.claude/sessions/<pid>.json. The session file
continues to reference the old sessionId for the entire lifetime of the process, regardless of how many /clear transitions occur.

This makes the PID session file — the only entry point for mapping a running process to its active conversation — unreliable after the first /clear.

Observed behavior:

  • The sessionId in the PID file points to a stale or nonexistent JSONL after /clear
  • Accumulates with each /clear — a single long-running process can drift through many sessionIds. The session file knows about none of them after the first
  • The referenced JSONL may not exist on disk at all — the original sessionId.jsonl can be absent while the process is alive and using a completely different session
  • --resume compounds the problem — a process started with --resume <id> writes the new process sessionId to the PID file (not the resumed one), then /clear creates yet another

sessionId, leaving both the PID file and the --resume target stale

Experimentally confirmed — we traced a single PID through its full session chain:

| Time | sessionId | Origin | Size |
|------|-----------|--------|------|
| (process start) | aaaa-... | startup | — (no JSONL on disk) |
| 16:55 | bbbb-... | /clear | 127,978 |
| 21:30 | cccc-... | /clear | 27,061 |
| 21:33 | dddd-... | regular | 666,582 |
| 21:33 | eeee-... | /clear | 1,925 |

  • PID session file still references: aaaa-... (written at process start)
  • That JSONL exists on disk: No
  • 3 /clear transitions, 4 distinct sessionIds — the session file knows about none of them.

What Should Happen?

After /clear creates a new session, the sessionId field in ~/.claude/sessions/<pid>.json should be updated to reference the new active session:

```json
{
"pid": 12345,
"sessionId": "<should reflect the current active session>",
"cwd": "/path/to/project",
"startedAt": 1773840639115
}

The PID session file should remain a reliable source of truth for the lifetime of the process.

Error Messages/Logs

Steps to Reproduce

  1. Start a Claude Code session
  2. Confirm ~/.claude/sessions/<pid>.json exists with sessionId: "A"
  3. Have a conversation (creates A.jsonl in the project directory)
  4. Run /clear
  5. cat ~/.claude/sessions/<pid>.json → still shows sessionId: "A"
  6. List the project directory → a new JSONL exists with a different sessionId
  7. Repeat /clear — the session file never changes

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.79

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

_No response_

View original on GitHub ↗

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