Feature request: expose CLAUDE_SESSION_ID environment variable to child processes

Resolved 💬 3 comments Opened Mar 26, 2026 by khmarochos Closed Mar 30, 2026

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_PORT and CLAUDE_CODE_ENTRYPOINT are 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
  • lsof on parent PID — Claude opens .jsonl per-write, no persistent fd
  • SSE port API — undocumented, not designed for this

View original on GitHub ↗

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