transcript

package
v0.68.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func LastModel(path string) string

LastModel is the model of the transcript's last main-thread assistant line, "" when none is within its last few MiB.

func Read

func Read(path string, from Position) (Usage, Position, error)

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

func SubagentDir(path string) string

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.

func Start

func Start(path string) (Position, error)

Start is the position at the current end of the main file and of every subagent file, so a read from it counts only what is written later.

type Tokens

type Tokens struct {
	Input      int
	Output     int
	CacheWrite int
	CacheRead  int
}

Tokens is one API usage, or a sum of them.

func (Tokens) Zero

func (t Tokens) Zero() bool

Zero reports no tokens at all.

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.

func (Usage) Zero

func (u Usage) Zero() bool

Zero reports a read that counted nothing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL