TranscriptImport

The one reader of the Claude Code transcript format: it turns a <session-id>.jsonl file into the part's events, once, on adopt (trove-parts §TPN-7, §TPN-8).

Group libllmsession

In the namespace octomy::llmsession. Declared in src/libs/libllmsession/llmsession/TranscriptImport.hpp.

Detailed description

Claude Code writes one JSON object per line into ~/.claude/projects/<project>/<session-id>.jsonl. The official documentation calls the format internal and says that it changes between versions (§TPR-7). So the reader is lenient, and nothing else in the tree parses the format. Its rules:

  • An entry is one JSON object per line. An unknown type, an unknown content block and an unknown field are skipped, never an error. A line that is not JSON is skipped. When it is the last line, Claude Code was still writing it, and the result says truncated.
  • The transcript is a tree: each entry has uuid and parentUuid. The reader follows the main chain back from the last entry, through logicalParentUuid where a compaction cut the chain. It skips isSidechain entries and the entries of an abandoned branch. A tool result whose call is on the main chain stays, because parallel tool calls hang their results beside the chain.
  • One assistant reply spans several lines with one message.id. The reader joins them into one event per content block: a block that comes again, with the same apiBlockIndex or the same content, replaces the first one.
  • A user entry's content is a string or an array. Both are read. An image block becomes a placeholder block that names its media type.
  • isMeta entries, compact summaries, interrupt notes, local commands and system entries become system events.
  • message.usage becomes one usage event per reply, with the tokens in the form that the stream transport gives.

Each prompt starts a turn, and each turn ends with a turn_end of reason imported, so that a resume after the import counts its turns right. Every block carries "imported": true.

See also octomy::llmsession::SessionStore, octomy::llmsession::StreamSession.

In this section