agent-ledger v0.1.1

What did that task cost?

Claude Code already writes every token it spends to a transcript on your disk. agent-ledger reads them and tells you, per session, branch or day, what each piece of work cost — and why.

npx @allan_nava/agent-ledger

Node 18+. No dependencies, no API key, nothing leaves the machine.

One row per ticket

branch             sessions  resp       peak ctx   billable  cache read    hit    cost
-----------------  --------  ----  -------------  ---------  ----------  -----  ------
feat/rate-limits          3   180  252,446 (25%)  1,053,962  15,623,949    97%   $9.30
fix/webhook-retry         1    26  106,379 (11%)    115,987   1,523,596  99.9%  $0.918
chore/deps                1    18    79,010 (8%)     80,013     824,489  99.9%  $0.578
refactor/billing          1   140  546,356 (55%)    677,007  39,242,202  99.9%  $15.10
-----------------  --------  ----  -------------  ---------  ----------  -----  ------
total                     6   364                 1,926,969  57,214,236    99%  $25.89

Sample data, generated by scripts/sample.mjs — the shape of a real week, not a real project. --by branch puts every session spent on a branch in one row. Here the rate limiter, done in three short sessions, never passes 25% of the window; the one long billing session reaches 55% and costs more than the whole feature. The same data as the --html report →

What it gets right

Each response once

Claude Code writes one API response as several transcript entries, each repeating its usage. Summing entries roughly doubles every figure; agent-ledger counts by message ID.

Cache priced by TTL

Cache writes are 1.25× for five minutes and 2× for an hour; reads are 0.025× to 0.1× depending on the model. The transcript says which — so the cost does too.

Subagents included

A subagent's transcript sits beside its parent's. Its tokens land in the session that launched it, so a cheap-looking session that fanned out shows its real cost.

Unknown is not free

A model with no price in the dated table is marked and left out of the total — never silently priced at zero.

On a subscription

Pro and Max are not billed per token. There the cost column is what the same traffic would cost on the API: a way to compare tasks, models and habits, not your bill.