A week of agent work, measured

I burned through a weekly quota by Thursday and could not explain why. The week did not feel unusual. Same repositories, same kind of work, a couple of long investigations.

So I opened the agent's built-in cost meter. It gave me a number, and the number did not match my sense of the week at all. The gap was too large to be rounding. Something structural was missing from the count, so I went looking for it.

The data is already sitting on your disk

Claude Code writes every session to a local file under ~/.claude/projects/, one JSON record per line. Other agent tools do something similar. That matters because each assistant record carries the message.usage block straight from the API response. It is not an estimate from len(prompt) / 4. It is the same accounting the provider billed against, sitting in a file you own.

The block looks roughly like this:

{
  "input_tokens": 12,
  "cache_creation_input_tokens": 18422,
  "cache_read_input_tokens": 241097,
  "output_tokens": 1834
}

Those four counters are not interchangeable. Fresh input is material the model has never seen. Cache reads are tokens the provider stored earlier in the same session and re-read at a discount, roughly a tenth of the fresh-input rate. Cache writes are what it costs to put them there in the first place. Only the first number is what most people picture when they think "the agent read my code".

I wrote a Python script to walk those files. About 600 lines, no vendor, nothing leaving the machine. It emits a static HTML report. The whole thing exists because the built-in meter answers a different question than the one I had.

The first thing I got wrong

My working assumption was that the built-in meter and the transcripts should agree, and that any difference would be a bug in my parser.

It is not a parser bug. The built-in meter tracks the main conversation thread. Subagents, the separate agent processes you spawn when you want work done in parallel, never appear in it. Every transcript record carries an isSidechain flag, and when I split on it, subagent work came out at 17.2% of the week's consumption once each counter is weighted by what it costs.

So roughly a fifth of what I used was invisible to the tool telling me what I used, and it is the fifth I create on purpose, by fanning a search out across five repositories or handing a grunt task to a cheaper model. The more work you push out to subagents, the more wrong the meter gets.

Once I saw that, "the meter is lying" stopped being the interesting part.

Two ways to produce a confidently wrong number

I hit two bugs before any of the numbers were worth trusting, and both of them produce results that look completely plausible.

The first is double counting. One API response does not map to one line in the transcript. Streaming, tool blocks and thinking blocks all mean a single response gets written out as several records, and each of those records carries the full usage block. Sum the lines naively and you inflate the total by about 2x. The fix is to deduplicate on requestId, falling back to message.id and then the record uuid when the field is missing on older records.

seen_requests = set()
for record in records:
    request_key = record.get("requestId") or record["message"].get("id") or record["uuid"]
    if request_key in seen_requests:
        continue
    seen_requests.add(request_key)
    add_usage_to_totals(record["message"]["usage"])

A few lines of bookkeeping, and without them every conclusion below is twice as large and equally wrong.

The second bug is subtler, and it wrecks rankings rather than totals. A flat token sum treats all four counters as the same unit. Cache reads cost a tenth of fresh input. Five-minute cache writes cost 1.25x. One-hour writes cost 2x. Output costs several times input.

Rank sessions by raw token volume and you are really ranking them by cache reads, because cache reads dominate volume by two orders of magnitude. The session that did the most actual thinking can land halfway down the list. So I weight each counter by its published per-model rate before comparing anything.

That weighting is a proxy for ranking, nothing more. It is not a bill, and it knows nothing about subscription pricing. It exists so that "session A cost more than session B" means something.

What the week actually looked like

Across seven days I ran 34 sessions and 6,603 deduplicated API calls, about 40.9 calls per hour of elapsed wall-clock window.

Here is the token mix by volume:

CounterTokensShare of volume
Cache reads2.0B97.7%
Cache writes42.7M2.1%
Output3.8M0.2%
Fresh input64.5K0.0%

Fresh input rounds to zero. Sixty-four thousand tokens of new material across a week in which the agent made six and a half thousand API calls.

That is the finding I keep coming back to. In volume terms, a coding agent barely reads your code. It re-reads a context it already paid to build, thousands of times, appending a small edit on each pass. The cache reuse ratio for the week was 98%.

Which reframes what "context management" is for. I used to think of the context window as a capacity problem, something you manage so the model does not fall off the end. On these numbers it is closer to a unit-economics problem. Every token you put in context gets re-read on every subsequent turn of that session, at a tenth rate, for the life of the session. A 40K-token file you loaded once and never referenced again is a tax on every call that follows.

The output side is small but not uninteresting. Of 3.8M generated tokens, 1.1M were thinking tokens, 29% of everything the model produced. Nearly a third of generation never reaches the transcript as visible text.

The most expensive single call of the week took 607.1K input tokens and produced 3.1K output tokens. Every one of the heavy hitters had that shape. Enormous in, tiny out.

Averages hid the part I most wanted to see

Two distributions surprised me once I stopped looking at weekly totals.

The first is how concentrated the week was. The single largest session accounted for 21% of the weighted consumption on its own, spanning 120.1 hours of wall-clock time and 901 API calls. The top three sessions together were about 41%. A week of agent usage is a handful of long-running investigations with a lot of small work scattered around them.

The second is the subagent split. The weekly figure was 17.2%, and I nearly wrote that down as a stable property of how I work. Per session, on comparable kinds of work, the subagent share was 82%, then 74%, then 44%, then 2%. The weekly average is the mean of a distribution with nothing in the middle. It describes none of the sessions it summarises.

That variance is the actionable part, because it tracks a decision I make without noticing. In some sessions I delegate almost everything and keep the main thread as a coordinator. In others I do all the work inline. Same class of task. The cost difference between those two habits is large, and I had no idea I was toggling between them.

Each call also carries attribution fields for the agent that made it and the skill it was running under, a skill being a named set of instructions the agent loads for one kind of task. My most-used skill accounted for 9.7% of the week across 1,058 calls. That one is a heavy database-inspection helper, and knowing its share told me more about where to spend optimisation effort than the weekly total ever did.

Why I stopped trying to get the total right

The ending here is unsatisfying. I now have two independent ledgers for the same week, and on the seven sessions where both exist, they disagree by about 19%.

They disagree in both directions, and both are lower bounds.

The built-in meter misses subagents entirely, so it undercounts the parallel work. My transcript parse misses calls that compaction removed from the file when a long session summarised its own history, plus background calls the tool makes on its own behalf, like generating a session title. Neither is a superset of the other. There is no reconciliation that makes them meet, because each is blind to something the other sees.

I could have kept chasing the gap. Instead I wrote the discrepancy into the report header and stopped. The honest claim this tool supports is about shape and ranking. Cache reads dominate volume. Subagent work is a real fraction the meter cannot see. Sessions concentrate hard. This skill costs more than that one. Those hold under either ledger, because they are ratios within a consistent counting method, and a lower bound that is consistently low still ranks correctly.

What the tool cannot support is a total. Anyone who tells you their exact agent spend from a local parse is quoting a floor and calling it a number.

Two things changed in how I work after that week. I stopped loading large reference files speculatively, because the re-read tax compounds on every turn that follows. And I started delegating deliberately rather than by mood, because the 82% session and the 2% session were doing the same work at very different prices, and until I measured it I could not tell you which one I had just done.