Expose session ID to PID mapping for crash recovery

Resolved 💬 3 comments Opened Feb 15, 2026 by kirpigiller Closed Feb 18, 2026

Problem

When running multiple Claude Code sessions (e.g. 9+ terminal tabs in PyCharm), there is no way to map a running process (PID) to its session ID from outside the process.

This matters when:

  • IDE freezes and you need to recover sessions from a regular terminal
  • You need to identify which running process corresponds to which session
  • claude --resume picker doesn't provide enough context (e.g. shows "user interrupted..." instead of meaningful info)

Current behavior

  • ps aux | grep claude shows PIDs and TTYs but no session IDs
  • Session JSONL files exist in ~/.claude/projects/*/ but aren't kept open by the process (can't use lsof to map)
  • No PID file, lock file, or any other artifact links PID ↔ session ID
  • The only way to see session ID is /status inside the running session — useless when the IDE is frozen

Proposed solutions (any would help)

  1. PID file per session: write ~/.claude/sessions/<session-id>.pid (or ~/.claude/sessions/<pid>.session) on startup, remove on exit
  2. claude sessions list CLI command: show active sessions with PID, TTY, session ID, project, and first user message
  3. Environment variable: set CLAUDE_SESSION_ID in the process environment so it's readable via /proc/<pid>/environ or similar

Workaround

I wrote a script that shows running processes and recent sessions side-by-side, but they can't be linked:

=== Running Claude processes ===
PID     TTY        ELAPSED      PROJECT
19362   ttys000    30:17        bautone
1951    ttys001    01-21:38     bautone
...

=== Recent sessions ===
02-15 07:28  516K  1f8c5f2b-...  Вчера запустил квалификацию...
02-15 01:50  860K  e1890b5b-...  Какой у нас лучший кандидат...

No way to know which PID owns which session.

Environment

  • Claude Code 2.1.34
  • macOS (PyCharm terminal integration)
  • 9+ concurrent sessions across 2 projects

View original on GitHub ↗

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