Feature Request: Expose session ID programmatically
Summary
When running multiple concurrent Claude Code sessions, there's no programmatic way to access the current session ID. This makes it difficult to reliably resume specific sessions in multi-instance environments.
Use Case
In environments where multiple Claude Code instances run concurrently (e.g., tmux sessions for parallel work), --continue is unreliable because it picks the most recent conversation across all sessions, not the one in the current terminal.
The /status command displays the session ID, but it's not exportable or accessible programmatically.
Proposed Solutions
Any of these would solve the problem:
- Environment variable: Expose
$CLAUDE_SESSION_IDin the shell environment during a session - CLI command: Add
claude --print-session-idorclaude session-idto output the current session ID - File-based: Write session ID to a predictable location (e.g.,
/tmp/claude-session-$$.id)
Current Workaround
Pre-generate session IDs before starting:
SESSION_ID=$(uuidgen)
echo "$SESSION_ID" > /tmp/claude-session-alpha.id
claude --session-id "$SESSION_ID"
This works but requires external tracking and doesn't help with sessions already running.
Environment
- Claude Code version: 2.1.15
- Platform: Linux (GKE devpod)
- Use case: Multiple concurrent Claude sessions in tmux
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗