Expand description
Claude Code subagent transcripts.
Claude Code (2.1.x) writes each subagent’s conversation to a file of its
own, <dir of transcript_path>/<session id>/subagents/agent-<id>.jsonl,
next to an agent-<id>.meta.json. The main transcript holds none of the
subagent’s assistant lines or usage, so a hook that tails only
transcript_path misses every token a subagent spends (VIS-1078).
Every line in those files carries the subagent’s agentId and the parent
sessionId. The stream hook sends each file’s new lines under the parent
session, one file per request, with transcript_offset counted within that
file; the server keys the chunks on the line’s own agentId, so they never
collide with the main transcript’s chunk indexes.
Functions§
- offset_
path - The file that holds how far
transcripthas been sent, keyed by its file stem (agent-<id>). Separate from the main transcript’s.stream_offset. - read_
batch read_new_lines, reading no further than the line that reachesmax_bytes, and telling where each line ends (seecrate::commands::stream::TranscriptBatch).- read_
new_ lines - Read the lines appended to
transcriptsince the offset stored inoffset_path(0 when absent). Returns(lines, start_offset, end_offset)with the meaning ofcommands::stream::read_new_transcript_lines:start_offsetgoes on the request astranscript_offset,end_offsetis the next read position. - transcripts
- The session’s subagent transcripts, sorted by path so a hook sends them in
a stable order. Empty when the session has none (or
transcript_pathis empty, as with fileless agents). Onlyagent-<id>.jsonlis taken: the directory also holdsagent-<id>.meta.jsonand forked-skill sidecars. - try_
lock - Take the exclusive lock on the file
offset_pathkeys, without waiting.Nonemeans another hook of the session holds it. - write_
offset - Persist
offsetas the next read position of the fileoffset_pathkeys. Replaced atomically: a hook killed mid-write must leave the old offset, not an empty file every later read rejects as corrupt.