Documentation
¶
Overview ¶
Package transcript reads token usage out of a Claude Code session transcript: one JSON object per line, appended as the session runs. Only counts, model ids and entry ids leave it, never message text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LastModel ¶
LastModel is the model of the transcript's last main-thread assistant line, "" when none is within its last few MiB.
func Read ¶
Read counts the usage written to the transcript at path, and to its subagent files, since from. A missing main file is an error; an undecodable line is skipped, and a partial last line is left for the next read.
func SubagentDir ¶
SubagentDir is where Claude Code writes a session's subagent transcripts.
Types ¶
type Position ¶
type Position struct {
Offsets map[string]int64 `json:"offsets"`
LastIDs map[string]string `json:"last_ids,omitempty"`
}
Position is how far each file has been read: the byte offset after the last complete line, and the message id counted last, since one API message spans several lines that each repeat its usage.
type Usage ¶
type Usage struct {
Tokens
ByModel map[string]Tokens
Subagents Tokens
// Model is the last model the session's own messages ran on.
Model string
// Through is the uuid of the last entry counted in the main file.
Through string
}
Usage is what a read counted: the session's own messages, by model, and its subagents' (sidechain) messages apart.