pub fn claude_stream_session_id(stdout: &str) -> Option<String>Expand description
Read the CLI-emitted session_id from a Claude --output-format stream-json JSONL capture: the top-level session_id of the LAST
system/init event. None for any other capture shape.
The stream sibling of claude_session_id, and it carries that function’s
D-04 / T-28-04 discipline for the same reason — read its doc comment
before changing anything here. Only the event’s TOP-LEVEL session_id is
read, via a direct serde_json::Value::get; the
[json_find_key]/[json_scan] traversal helpers are NOT to be used. They
descend into nested objects, and a stream carries agent-authored text in
every result event — including the DEVFLOW_RESULT marker JSON that
[parse_marker_lines] deserializes. A traversal would make a session_id
the agent planted in its own marker reachable, handing it the ability to
name the session DevFlow later resumes into (T-30-11). Regression test:
claude_stream_session_id_ignores_agent_planted_value.
The LAST init event wins, consistent with the last-result-wins
convention. Verified against the archived capture: its three init events
(lines 5, 32 and 47) all carry the same session_id, so last-wins and
first-wins agree on today’s evidence — but only last-wins stays correct if a
future capture rotates the value mid-stream. Three init events do NOT mean
three sessions: session continuity must never be keyed off “have I seen an
init event”.
No session_id field is added to AgentResult — see
claude_session_id’s doc comment for why that design stays rejected.