Skip to main content

Module session_id

Module session_id 

Source
Expand description

Live Claude Code session id helpers.

task-journal already parses session ids out of Claude Code transcripts (session::parser) — that is a passive, read-only lookup of someone else’s identifier. This module is the other direction: additively stamping the live session id onto the events the journal itself emits (hooks + MCP tools), so downstream consumers can correlate those events with the originating session without time-window heuristics.

Source order: hook payload field session_idCLAUDE_CODE_SESSION_ID env var → None. None means standalone behaviour is unchanged — nothing is added to meta.

Functions§

live_session_id
Resolve the live session id: hook payload first, env var as fallback. None when neither source provides one (standalone — caller adds nothing).
session_id_from_env
Read CLAUDE_CODE_SESSION_ID from the environment. Empty counts as absent.
session_id_from_payload
Pull session_id out of a Claude Code hook payload (or a pending-v2 chunk, which carries the same field). Empty strings count as absent.
stamp_session_id
Additively record session_id into a free-form meta value.