[FEATURE] Expose CLAUDE_SESSION_ID to Bash commands and Claude's context

Resolved 💬 3 comments Opened Jan 16, 2026 by thielm Closed Jan 20, 2026

Problem

Claude Code knows the session_id and passes it to hooks/statusline via JSON input. However:

  • Bash commands cannot access it - no environment variable available
  • Claude (the AI) cannot access it - not in Claude's context

When a user asks Claude "What session are we in?" - Claude genuinely cannot answer. The information exists in Claude Code but isn't exposed to Claude or Bash.

Use Cases

  • Multi-session coordination: Multiple Claude sessions working in the same repo need unique identifiers for temp files, locks, or state tracking. Without session_id, workarounds using timing or shared queues are unreliable with concurrent sessions.
  • Session-scoped resources: Creating files or caches tied to a specific session (e.g., git --index-file=/tmp/index-$CLAUDE_SESSION_ID)
  • State management: Tracking which session is doing what in multi-agent workflows
  • Debugging: Understanding session context when investigating issues

Current State

| Context | Has session_id? |
|---------|-----------------|
| Statusline (JSON input) | ✅ |
| Hooks (JSON input) | ✅ |
| Bash commands | ❌ |
| Claude AI context | ❌ |

The session_id already exists and is passed to external scripts - it just needs to be exposed more broadly.

Proposed Solution

Expose session_id as an environment variable available to Bash commands:

export CLAUDE_SESSION_ID=7617cc48-8480-4d24-b52d-4b107c2a7701

This would allow:

# Session-scoped temp files
TMPFILE="/tmp/claude-work-$CLAUDE_SESSION_ID.txt"

# Session-aware state management  
jq --arg sid "$CLAUDE_SESSION_ID" '.sessions[$sid].status = "working"' state.json

Related Issues

  • #13733 - Closed as duplicate of #13735, but this is a distinct request. #13735 is about persistent env vars across Bash calls; this is about exposing a specific value that Claude Code already has.

View original on GitHub ↗

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