Feature request: expose CLAUDE_SESSION_ID environment variable to child processes
When building automation skills (shell scripts invoked by Claude Code via hooks or slash commands), there is no programmatic way to determine the current session ID from within a child process.
Use case
We maintain a project with GitLab issue tracking and custom Claude Code skills (/workflow-start, /workflow-testing, /workflow-done, /commit). We want to include the Claude Code session ID in GitLab issue comments for traceability — linking which Claude Code session worked on which issue, enabling claude --resume <id> to continue the work.
Current state
- Session IDs (UUIDs) are used as filenames in
~/.claude/projects/<project>/<uuid>.jsonl CLAUDE_CODE_SSE_PORTandCLAUDE_CODE_ENTRYPOINTare exported, but not the session ID- The only workaround is heuristic (most recently modified
.jsonl), which is unreliable with parallel sessions
Proposed solution
Export CLAUDE_SESSION_ID=<uuid> to the environment of all child processes (Bash tool, hooks, skills). This is a minimal, non-breaking change that enables powerful automation workflows.
Alternatives considered
- Parsing the most recently modified
.jsonl— unreliable with concurrent sessions lsofon parent PID — Claude opens.jsonlper-write, no persistent fd- SSE port API — undocumented, not designed for this
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗