glossary//run-accounting
run accounting
Run accounting records the per-stage costs of one pipeline run, listing the model, tokens used, duration, and confidence in each value.
The word run is doing the real work here. Run accounting attributes cost to the stages of one named workflow execution after the fact so the record can be audited later. That differs from live cost monitoring, which watches spend as it happens and alerts on thresholds, and from general observability, which logs request telemetry without tying it to a single run's shape.
Agents cannot see their own token spend, so asking them produces a guess with a confident face on it. What separates run accounting from a dashboard is who writes the numbers.
The rule the whole thing rests on
Agent run cost attribution calls this the anti-gate-theater partition: each metric is written only by the component that can actually observe it. The orchestrator writes wall-clock timestamps and a rework flag. Token and turn counts come from a SubagentStop hook at the harness layer, keyed by attempt_id, reading the finished transcript as a file the orchestrator cannot access.
But the arithmetic is less obvious than it looks. Claude Code stores a transcript as JSONL, one line per content block, and every line of the same assistant message carries an identical cumulative usage object. Summing usage across lines, the obvious move, counts each message once per block it contains. On one real transcript, 75 assistant lines collapsed to 33 distinct message IDs: 6,223,502 tokens naive against 2,786,193 deduplicated, a ratio of 2.23. A subagent transcript gave 1,654,348 against 606,616, a ratio of 2.73. Every measured ratio exceeded 2x.
Confidence is part of the record
The first instrumented run reported 38,612,740 tokens processed with confidence marked partial. The orchestrator's own 34,176,808 across 121 turns was exact. All 27 specialist spawns were unmatched, and the rework ratio and active spawn time were honest zeros rather than false confidence. A run accounting file that cannot say what it missed is worse than one that reports a smaller number.
That layer is also auditable, and was audited. A clean audit run proves nothing documents an external model finding five real defects in it on the first pass and three more on an identical re-run, with the same failure classes recurring in adjacent code paths: cost attributed on the mere presence of a session identifier rather than proven identity, and a rollup stamping a bucket exact when its inputs were degraded.