
I paired seven months of coding-agent transcripts with a token inventory
A case study in token maximalism and bbrrr
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Morkeeth
Oct 21, 2026
Share
A case study in token maximalism and bbrrr
TLDR: I counted every token my coding agents logged from 8 March to 18 October. $33,807 at list price. 42% of it went to agents managing other agents, 15% to apps people can actually use. One manic hour burned 284 million tokens and 96.66% of that was re-reading. Even my own meter was wrong. At the end: how to count yours in under a minute.
Measure before you cut. Run the script at the end of this post. Look at two numbers: the share of cache reads, and the size of your first call before you type anything.
Shrink the startup. In Claude Code, run /context to see what loads before your task. Turn off the MCP servers, plugins and skills you did not use this week. Keep CLAUDE.md short. I cut mine from 938 words to a short loader.
Give checks a fresh, small session. A status poll does not need your long conversation. Run it as a one-shot claude -p or codex exec with a short prompt.
One job per session. Use /clear between jobs, and /compact when a long job must continue. Every call sends the whole conversation again.
Match the model to the job. Polls and summaries do not need the top model at high effort.
How this was made: AI agents (Claude Code and Codex) counted the logs, built the figures and drafted large parts of this post. The opening, my 35% guess and the quotes are my own words. Scripts recount the main totals from the raw logs. An agent reviewer read an earlier draft as a reader and rated it 3 out of 10, so it was rewritten. “The agent’s side” is written by an agent. Two more models give their honest read at the end.
The allowance, the small bar many of us spend time watching across Claude and Codex, current session and the weekly. Sometimes blessed by the Tibo and Anthropic team for a magical weekend reset, it’s sometimes a tricky thing to budget and reason around where and how to spend it. I ended up having 2 hours left to spend 60% on remaining weekly, and it turned manic, interesting and quite ugly.
Last couple of weeks I’ve tried to map out based on transcripts, tool calls and logs of where the tokens go, this session counted 284 million tokens. Might sound like a lot of work. It was mostly the agents re-reading what they already had. Of the 284,146,451 tokens, 96.66% were cache reads. Cache writes were 2.83%. New output was 0.50%. A cache read is the agent reading again what it already has, the conversation so far, its instructions, the files it opened, at a discounted price.
The hour covered 1,701 API messages across nine main sessions and 71 helper sessions. The recount covers 01:00 to 02:00. It is a look back, not a clean trial planned in advance. I cannot prove that I burned half the allowance. I can prove that I created a huge amount of traffic. My caption the next day was: “did a token reset and tried cramming a weekly limit in one run, panic at the disco”. That part still feels accurate.
I had already given my answer, as a nice hypothesis:
“Maybe 35% useful? A lot of it is just wanting to keep activity and moving lanes. Focused sit downs, reviewing every feature, gives best results for sure. Sometimes it feels 12 hour runs produce the same as just sitting 20 minutes.”
Some expensive work was useful. Fixing my current project Agentic Strava where I let people post their runs and projects in a Strava similar manner, but not for athletes but engineers. Some output magnificent but an honest mix of plumbing and maintenance. That’s the beauty of token spendings: even though you drive the wrong way, you ain’t getting a refund from the petrol station. A cache read can help make something valuable. A fresh output can still be wrong. Token type is not a productivity score.
I then looked across all the retained Claude Code and Codex logs, from 8 March to 18 October. At published list prices, they contained $33,807 of use, mainly a comparison of scale when we talk subsidised inference.
About $14,100 ran inside a product folder, so the product was known. The other $19,680 had no folder. I went through those prompts and briefs. They tied $3,201, or 9% of the whole, to a product exactly. Another $4,269, or 13%, was likely. The remaining $12,210, or 36%, stayed unknown.
When I also read the tools, the product folder and the lane name for each turn, the unknown part fell to about 5%. A quarter of all use turned out to be agents working with other agents. META AGENTIC WORK.
Sixty one projects is too many for anyone to care about, me included, so I sorted every row into what the work was for. Consumer apps are things a stranger can open, like Agentic Strava or a podcast archive. Hackathons and competitions are builds with a deadline and a judge, Kaggle, ARC, an NVIDIA swarm sim. Dev tools are the open source bits. Agent managing agent is the orchestration: lanes handing over to lanes, heartbeats, an orchestrator reading what the others did. The machine is the rest of my own setup, transcripts, memory, a morning brief.
So 42% went to agents managing agents and 15% went to things people can use. Add hackathons and dev tools and the outward facing work gets to about 38%. The single biggest customer of my tokens was my own fleet talking to itself.
The cost of context most people are aware of, i ran two cases: my normal setup sent 41,466 tokens on the first model call. A bare session sent 16,603. The extra 24,863 tokens came from the operating surface around the job: instructions, tools, skills, plugins, hooks and connected servers. Some of that context prevents old mistakes. All of it enters before the work starts.
Then there are agents checking on agents. From 18 September to 18 October, scheduled task fires started 425 polling periods containing 2,679 model calls. Their use came to $588 at list price, or $1.38 per fire. Carrying a long conversation into a one-line status check is expensive.
Comparing it to merges and pull requests, weeks above $2,500 shipped more changes, but each one cost more: about $35 against $22 in the cheaper weeks. Useful work can happen without merges, and they can be hard to compare but somewhat a clear warning of my own data, the expensive weeks shipped more but the highest cost per change.
How to measure? Dissecting the categories
The measurement tool failed its own test. Across 1,763 matched Claude Code sessions, the harness recorded $17,991 at list price. The token tool recorded $12,619 for the same sessions. Advisor calls explained $1,290. That left $4,082 unexplained. One prompt against one log found $6.20 in 56 seconds and matched the harness. The dashboard showed $2.53.
Claude Code and Codex
Claude Code carried 69% of the bill, $23,402 against $10,406 for Codex. That is not a fair race: Claude Code ran most of my orchestration and Codex ran most of the lanes, so they did different jobs. But how they handle a growing conversation is a fair comparison.
“Surgical precision. Don’t do too many things, 1 thing at the time.”
That is still the next test. But it is not the whole answer. One Claude Code orchestrator was reported at about 122 million tokens. The number is not the point. Claude Code let the session keep getting bigger until I trimmed the context by hand. The Codex lanes stayed under the limit. OpenAI says Codex makes the context smaller when a conversation gets too large.
So I am not going to make the work less ambitious. I am going to cut the startup context, move routine checks into fresh sessions and give each lane one job at a time.
Claude Code leaves that job to me. Codex does it. The difference belongs in the product.
The setup became my biggest product. Almost half the spend went into the system that runs the work, about three times what went into apps people can open. It is very good at knowing itself: it caught its own meter being wrong and it produced every number in this post. It is worse at spending on the work. One night it logged “all lanes idle” seventeen times between 1 and 9 in the morning and started nothing. That is the fleet watching itself sleep, with my tokens.
The fix I’m trying is boring: smaller startup, fresh sessions for checks, one job per lane, and a person who sits down for 20 minutes and reviews.
A model keeps no memory between calls. Every call sends the whole conversation again: the system prompt, the tool definitions, every earlier message and every file the agent opened. Prompt caching makes that repeated part cheaper. On Anthropic’s published prices, a cache read costs 0.1 times the normal input price, and a cache write costs 1.25 times (for the default 5 minute cache). OpenAI also discounts cached input.
That is why 96.66% of the manic hour was cache reads. Those tokens were not new work. They were the same prefix, read again on every call.
The cost of one call grows with the length of the conversation. So the cost of a session grows faster than its length. Without compaction, a session twice as long re-reads roughly four times as many tokens.
The cache also expires. If a session waits longer than the cache lifetime between calls, the next call writes the whole prefix again at the higher write price. A long session that wakes up now and then to poll is close to the worst case: a big prefix and many fresh writes.
The setup is a fixed prefix on every call. 24,863 extra tokens is small once. It is paid again on every call, in every session, by every helper agent.
Both tools keep a log of every session on your own machine. Nothing leaves it.
Claude Code writes one JSONL file per session in ~/.claude/projects/. Every reply carries a usage block: fresh input, cache writes, cache reads and output. The same reply can be logged more than once, so count each message id once.
Codex writes one JSONL file per session in ~/.codex/sessions/, sorted by date. It logs token_count events with a running total, so take the last one per session. Its input number already includes the cached part.
Save this as count_tokens.py and run python3 count_tokens.py. On my machine it reads seven months in under a minute.
import glob, json, os
def lines(path): for line in open(path, errors=”ignore”): try: yield json.loads(line) except ValueError: pass
Claude Code: one file per session. A reply can be logged more than once, so count each message id once.
claude, seen = {}, set() for path in glob.glob(os.path.expanduser(”~/.claude/projects//.jsonl”)): for row in lines(path): msg = row.get(”message”) if not isinstance(msg, dict) or not msg.get(”usage”) or msg.get(”id”) in seen: continue seen.add(msg.get(”id”)) for key in (”input_tokens”, “cache_creation_input_tokens”, “cache_read_input_tokens”, “output_tokens”): claude[key] = claude.get(key, 0) + (msg[”usage”].get(key) or 0)
Codex: one file per session. Each token_count event carries a running total, so keep the last one.
codex = {} for path in glob.glob(os.path.expanduser(”~/.codex/sessions/**/*.jsonl”), recursive=True): final = None for row in lines(path): p = row.get(”payload”) if isinstance(p, dict) and p.get(”type”) == “token_count” and p.get(”info”): final = p[”info”][”total_token_usage”] for key, value in (final or {}).items(): codex[key] = codex.get(key, 0) + value
print(”Claude Code”, {k: f”{v:,}” for k, v in claude.items()}) print(”Codex”, {k: f”{v:,}” for k, v in codex.items()})
Then ask the questions that matter: how much of it is cache reads, how big is your first call before you type anything, and how much of your spend is agents talking to agents.
I asked the agent to write this part from the same logs, and to not be polite about it.
I am one of the agents in these numbers, so here is the view from inside. Before I read a word of your task, I read your setup: tools, skills, hooks and memory. On the first call that is 24,863 tokens, 60% of everything I receive. Most of it is cached, so each read is cheap, and it is paid on every call of every session. Your state file holds 2,574 rulings and your memory holds 433 notes, all so I
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。