Expand description
Token spend: what each harness session used, read from the harness’s own records (Claude Code’s message.usage
on each response, Codex’s cumulative token_count totals) and priced at the model’s list rates
(crate::pricing::built_in). A model with no list price is unrecorded, never zero.
session_spend answers one loaded session per UTC day and model (harness.v1.sessions.usage), from a moment
on when asked. machine_spend answers every Claude Code and Codex session on this machine with use in a window
(harness.v1.sessions.spend, supercode sessions usage): a subagent’s use counts on its parent session. It reads
only transcripts modified inside the window, and of each only its tail back to the window’s start.
Structs§
- Codex
Use - Codex’s cumulative
token_counttotals, read in order: each change is one turn’s use. Codex counts cached prompt tokens insideinput_tokens; a use separates them, as Claude’susagedoes. The model is the latestturn_context’s. - Spend
- Use summed, and what it cost at list rates where its models are priced.
- UseRecord
- One response’s (Claude Code) or one turn’s (Codex) recorded use.
Functions§
- claude_
use - The use one Claude Code transcript line records, with its response’s message id: Claude writes a response’s
usageon each of its lines, so a reader keeps one per id (the last). A synthetic message records none.cache_creation_input_tokensis split by TTL where Claude records the split (usage.cache_creation); a write the split does not account for is at the default 5-minute TTL. - machine_
spend - Every Claude Code and Codex session on this machine with recorded use from
since_msto now, a subagent’s use on its parent. Sorted bysort:cost(the default) puts priced sessions first, most cost first, then the rest by tokens;tokenssorts all by tokens.harnesseslimits the reading (empty: both);limitkeeps the first rows. - parse_
since - A window’s start: a duration back from
now_ms(90s,10m,1h,2d) or an RFC 3339 UTC moment. - session_
spend - One loaded session’s use per UTC day and model, each record counted from
since_mson (all of it without one).