Feature request: Expose session_id to the conversation context
Problem
Claude Code's session_id is available in the JSON piped to statusLine commands and hooks, but is not accessible from within the conversation itself — not as an environment variable, not through any tool, and not in any system context.
This makes it difficult for tools and plugins that need Claude to write session-keyed data (e.g., task status files, session-specific caches) because Claude cannot discover its own session ID without a workaround.
Current Workaround
The workaround we implemented for the ccstatusline task-objective widget:
- The statusLine command receives
session_idin its stdin JSON - It walks up the process tree (
ps -o ppid=,comm=) to find the Claude CLI PID - It writes the session ID to
~/.cache/ccstatusline/sessions/<claude-pid> - Claude runs
echo $PPIDto get the CLI PID, then reads the file to discover its session ID
This works but is fragile (Unix-only, requires process tree walking) and adds latency to every statusLine render.
Proposed Solution
Expose session_id as an environment variable (e.g., CLAUDE_SESSION_ID) in the shell environment used by the Bash tool. This would allow Claude to directly reference it without any discovery mechanism.
Alternatively, exposing it in a system context field that Claude can read would also work.
Use Cases
- Task tracking widgets: Status line tools that show what Claude is working on, keyed by session
- Session-specific caches: Tools that need to store per-session state
- Multi-session coordination: When multiple Claude sessions run concurrently in the same project, session ID is the only reliable differentiator
- Session resume: The session ID is stable across
--resume, making it better than PID for keying persistent data
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗