AI Coding Agent Token Costs Hide an Amnesia Tax
AI coding agent token costs hide an amnesia tax. Price it, then pick the right lever from caching, indexing, experience reuse, or distillation.

In this article
- 1.Pricing the Amnesia Tax on One Fresh Session
- 2.The Three Waste Streams Driving AI Coding Agent Token Costs
- 3.Re-Discovering Familiar Facts (about 18,000 tokens)
- 4.Loading Unused Tools (about 9,000 tokens)
- 5.Repeating Unsuccessful Approaches (about 18,000 tokens)
- 6.Four Levers Compared, From Caching to Distillation
- 7.Prefix Caching
- 8.Repository Indexing
- 9.Experience Reuse
- 10.Harness Distillation
- 11.Why Caching and Indexing Leave Money on the Table
- 12.When Experience Reuse Beats the Other Levers
- 13.Three Failure Modes Unique to Reused Experience
- 14.Staleness After Refactors
- 15.Negative Transfer
- 16.Experience Logs as a Privacy Surface
- 17.The Decision Rubric and Deployment Order
- 18.Outlook: Paying the Tax Once
Every fresh session, your coding agent pays a toll it paid yesterday. It re-reads the repository layout, reloads tools it never calls, and retries the approach that failed last Tuesday. Most teams treat this as noise on the invoice, but a big slice of AI coding agent token costs comes from three distinct waste streams, and the four familiar cost levers split unevenly across them.
Stay in the loop.
Get the latest posts and exclusive content delivered to your inbox.
Join 18 readers. No spam. Unsubscribe in one click, anytime.
Prefix caching discounts the tax without shrinking it. Repository indexing covers exactly one stream. Harness distillation, training a smaller model on your agent's runs, bakes experience in at the highest fixed cost. Experience reuse is the only lever that touches all three, and the only one that introduces failure modes that get worse over time.
The defensible order for most teams is cache, index, reuse, distill.
Pricing the Amnesia Tax on One Fresh Session
The amnesia tax is the slice of AI coding agent token costs spent re-acquiring what a previous session already learned: where the tests live, which tools matter, which approaches dead-end. It excludes the actual task work. It is the setup you re-pay every time the context resets.
Price one representative session, with every assumption stated:
- Input side, about 35,000 tokens. System prompt, tool schemas, and the exploration reads (directory walks, file opens, greps) that re-establish where things are in a mid-sized repository.
- Output side, about 10,000 tokens. The commands, listings, and misfires the agent generates while orienting itself.
- Total: about 45,000 tokens that produce no task progress.
At Claude Sonnet-class list prices of $3 per million input tokens and $15 per million output tokens, that session costs 35,000 × $3/M plus 10,000 × $15/M, roughly $0.26, under $0.30. Note the asymmetry: output is the smaller count but carries roughly five times the input rate, so misfires dominate the dollar bill. List prices differ by vendor and change often, so treat this as an estimate and verify against your provider's current rate card, for example OpenAI's pricing page.
Now annualize it. Twenty engineers running five agent sessions each per day, at $0.26 of pure re-orientation per session, is about $26 per day, on the order of $6,000 per working year. The per-session number is small enough to ignore and the annual number is large enough to fund a platform project, which is how this cost survives scrutiny.
The Three Waste Streams Driving AI Coding Agent Token Costs
The profiling behind TokenEconomizer put Claude Code through 60 SWE-Bench tasks, running each repository's tasks in sequence, and found waste clustering into three streams (the TokenEconomizer paper):
- Once a repository had five finished tasks behind it, 30% of its tool calls re-ran an action first performed in an earlier task. Only 7% matched other repositories, so the re-learning is repo-specific.
- The agent received 23 tool descriptions on every turn, and 16 were never called.
- The 17% of tasks that failed accounted for 32% of total spending.
Map those findings onto the 45,000-token session, and each stream gets a share you can hunt in your telemetry.
Re-Discovering Familiar Facts (about 18,000 tokens)
How to run the tests, which build command works, where the config lives. The 30% repetition rate says the agent re-derives these facts session after session. To spot it, compare first-session input against steady-state in the same repository and count commands that recur across sessions.
Loading Unused Tools (about 9,000 tokens)
Sixteen of 23 tool descriptions were never called, roughly 70% dead weight in the schema budget, and it compounds with MCP-style setups: mount several MCP servers and their unused definitions can run to thousands of tokens every turn. To spot it, log which tool definitions ride along in each request and which tools actually get invoked.
Repeating Unsuccessful Approaches (about 18,000 tokens)
This is the expensive stream. Failed tasks were 17% of the workload but 32% of the spend, because retry loops burn output tokens at the premium rate and an agent with no memory of failure has no reason to change strategy. To spot it, plot turns per task: a long right tail usually means sessions stuck repeating a move that stopped working.
Four Levers Compared, From Caching to Distillation

The four levers attack the tax differently, and only one removes tokens from all three streams.
Prefix Caching
Providers reuse the key-value state of a repeated prompt prefix, so identical leading tokens bill at a steep discount. Anthropic's list pricing bills cached prompt reads at about one-tenth of the base input price, charges a premium for cache writes, and expires caches on the order of minutes to hours. OpenAI's prompt caching guide describes an automatic discount of half or more on cached input tokens depending on the model. Prompt caching therefore discounts the amnesia tax rather than shrinking it: cached tokens still occupy the context window and still consume the attention budget that degrades on long contexts.
Repository Indexing
Embedding the codebase, the approach Cursor popularized, trades re-reading for retrieval, and the real costs are index upkeep and retrieval-quality variance. Embeddings go stale after refactors much the way memory notes do: the rename that would break a learned note also silently degrades chunks still referencing the old symbol until you re-index. Chunk boundaries decide whether retrieval beats a wholesale re-read: a function scattered across chunks returns fragments the agent must reassemble, and reassembly can cost more than the re-read. Indexing pays when one full orientation read costs more than targeted fetches plus reassembly. It loses on small repositories, because a full read there is cheap. A 40-file service fits in one pass; a monorepo's orientation pass can be the priciest move in the session, and retrieval wins.
Experience Reuse
TokenEconomizer is the reference implementation: an open-source, training-free, plug-and-play plugin from UC Berkeley, Microsoft Research, and Microsoft Security that turns completed sessions into guidance for later ones, without touching the agent or its model (TokenEconomizer project page). It acts through three mechanisms. Micro-skills capture recurring patterns as one-line notes, added only after several sessions confirm them and retired when contradicting evidence arrives. Tool pruning drops tools that history suggests will go unused, always retaining the core tools for commands and file edits. Failure-loop intervention watches for an agent hitting the same failure, uses a judge model to decide whether it is truly stuck, and injects a note suggesting a different approach. Setup needs no separate API key. Of the four levers, this is the only one that touches all three waste streams.
Harness Distillation
Train a smaller model on traces from your best agent runs for one stable task family, then route that family to the cheap model. The break-even sketch writes itself from the session math above: divide your fixed training and evaluation quote by $0.26 of re-orientation waste per session. A hypothetical $1,000 quote breaks even near 3,800 sessions, roughly 75 a week across a working year, and only for that one family. The trap is frozen weights: when the task family drifts, the distilled model cannot notice, while experience reuse retires contradicted notes and relearns. That is model distillation applied to the harness.
A fifth familiar lever needs no tooling: dial reasoning effort down or route to a cheaper model. The TokenEconomizer evaluation uses it as the trade-off baseline: similar or larger savings, but with substantial performance degradation, where reuse holds Pass@1 broadly stable. It discounts every stream, removes none, and sits outside the ranking.
The coverage matrix, stream by stream:
| Lever | Fact rediscovery | Unused tools | Failed retries | Cost shape |
|---|---|---|---|---|
| Prefix caching | Discounts | Nothing | Subsidizes | Usage fee, no engineering |
| Repository indexing | Removes tokens | Nothing | Nothing | Flat setup plus index upkeep |
| Experience reuse | Removes tokens | Removes tokens | Removes tokens | Small controller overhead |
| Harness distillation | Removes (in scope) | Removes (in scope) | Partial | Large fixed training cost |
| Lower effort or cheaper model | Discounts | Discounts | Discounts, can deepen | Free, pays in accuracy |
Why Caching and Indexing Leave Money on the Table
The cheap levers fail in specific, predictable ways.
Cache lifetimes run minutes to hours, so the afternoon cold start stays cold. Prefix invalidation is the sharper problem. Anything that changes before the cache breakpoint, a reordered tool list, a timestamp, a dynamic instruction, breaks reuse from the first differing token. For agents, the unstable parts of the prompt are the front-loaded parts, the tool schemas and context preamble, so the expensive prefix is the hardest to keep stable.
The deeper problem is what caching does to failure loops. A cheaper retry is still a retry, and output tokens are never cached, so the priciest part of a stuck session stays at full price. Prompt caching makes repeating unsuccessful approaches cheaper rather than rarer.
Indexing has the mirror-image limitation. Retrieval fixes fact lookup, but the sixteen unused tool descriptions still load on every turn, and the agent still has no memory that yesterday's approach failed. Both belong early in the order. Neither is a strategy.
When Experience Reuse Beats the Other Levers
When does agent memory beat prompt caching? The benchmarks answer with a gradient, not a yes. Experience reuse is a bet on repository recurrence: savings run 18.4 to 30.9 percent when tasks return to the same repositories, 16.0 to 21.2 percent on sequential multi-task work, and 6.4 to 19.6 percent when every task lands fresh. Read the curve as a decision rule: the more your tasks revisit known repositories, the more reuse pays; the more they land fresh, the closer you slide to single digits.
The receipts from TokenEconomizer's launch evaluation, controller overhead netted out:
| Benchmark | Scope | Cost per task | Task performance |
|---|---|---|---|
| SWE-Bench | 277 tasks, five agent-model combinations | 18.4 to 30.9 percent lower | Pass@1 broadly stable, rising in four of five |
| Sequential web development | Multi-task projects | 16.0 to 21.2 percent lower | Not reported separately |
| Security auditing | Fresh repositories | 6.4 to 19.6 percent lower | Not reported separately |
Costs fell in every repository tested, and while early tasks can cost more as the controller learns, cumulative cost dropped below the default by the sixth task: reuse pays once history exists.
The bet pays off when three measurable triggers line up: sessions per week in the same repositories, the share of tasks revisiting code the agent already knows, and how rarely the mounted tools and schemas change.
The compounding trick is ordering. Compress the prompt with reused experience first, then cache the compressed prefix. You protect a smaller, more stable prefix, because learned notes change less often than tool lists, so the cache hit rate rises. This is context engineering as a sequence, not a menu: the levers compound when ordered correctly and merely coexist otherwise.
Three Failure Modes Unique to Reused Experience

Prompt caching cannot go stale, and an index cannot mislead you about a different codebase. Reused experience, the newest form of AI agent memory, can do both, plus one thing neither does: create a privacy surface.
Staleness After Refactors
A function is renamed from parse_config to load_settings, and a learned note still steers the agent toward the old call, turning a two-line fix into a debugging detour. Mainstream coding agents already ship hand-written experience reuse as memory files, CLAUDE.md memory files in Claude Code and rules files in Cursor, with the same staleness failure mode. The CLAUDE.md versus Cursor rules choice is one mechanism in two wrappers, and both wrappers drift. Verify it in your own repository today: open the memory file and count the commands that no longer exist. Mitigations are experience TTLs, retirement on contradicting evidence, and re-validating notes against the code they describe.
Negative Transfer
A pattern that worked in one context gets applied to a similar-looking one where it is wrong. The retry-with-backoff fix that saved a stateless API service gets suggested for a workflow step with side effects, and the agent now re-triggers a payment three times. Mitigations are context gating, so patterns fire only when their preconditions match, scoping experience per repository or module rather than globally, and checking the current structure before applying a learned move.
Experience Logs as a Privacy Surface
Session logs retain code fragments, secrets, and user data, and they live outside the repository, outside code review, and often outside your data-loss-prevention tooling. A memory system that accumulates this material across months builds an artifact nobody has audited. Mitigations are scrubbing on write, a retention policy with real expiry, and keeping experience local to the developer machine, which TokenEconomizer does by design.
The Decision Rubric and Deployment Order
Deploy in this order, with these triggers:
- Cache first. It is provider-side, needs near-zero engineering, and pays on day one. The only work is measuring your cache hit rate so you know what you actually saved.
- Index second. One-time setup per repository with immediate effect on the rediscovery stream. Trigger when sessions spend their opening turns reading files they did not need.
- Reuse third. Trigger when you run dozens of sessions per week in the same repositories on recurring task families with a stable toolset. Do the privacy review first: decide what the logs may retain, for how long, and where they live.
- Distill last. Trigger when one task family is high-volume and stable enough that the fixed training cost amortizes. Treat it as a commitment, not a toggle.
Then run this four-line recipe from your billing dashboard to reduce token usage in AI coding agents with numbers instead of vibes:
tokens_30d = 30-day input and output totals for agent workloads
rediscovery = avg first-session input - steady-state input + unused tool-description tokens
cost_session = rediscovery x blended price per token
annual_tax = cost_session x sessions per week x 52
That annual figure is your amnesia tax, priced from your own data. Take it to the coverage matrix, pick the lever that matches your worst stream, and defend the choice with the trigger conditions above. That is LLM cost optimization with receipts.
Outlook: Paying the Tax Once
The amnesia tax is a design choice, not a law of inference. Agents start blank because we build them that way, and the memory files already shipping in mainstream tools are hand-written proof that reuse works. The open question is whether automated experience accumulation can keep its knowledge fresh, correctly scoped, and private. The direction of travel is argued in the Era of Experience paper: agents that learn from accumulated experience rather than re-paying for it each session. The teams that get the order right pay for orientation once, then spend the difference on actual work.
Stay in the loop.
Get the latest posts and exclusive content delivered to your inbox.
Join 18 readers. No spam. Unsubscribe in one click, anytime.
About the author
Tyler Brooks
Tools Analyst
Tyler has tested developer tooling for a decade, first as a platform engineer and now as an independent analyst. He reviews models, frameworks, and APIs the way he would want them reviewed before relying on them for real work.
Related Posts
Agent Host Protocol Moves the Transport, Not the State
The Agent Host Protocol as a build spec: the state your app must externalize before sessions hop devices, and what a roaming session costs to secure.
AI Agents for Data Science Lost to a 76.5% Baseline
AI agents for data science lost to a two-line Titanic baseline, scoring 72.96% in one hour. See why tabular ML breaks coding agents and what to keep.
What Multi-Node vLLM Serving Really Costs Per GPU
Multi-node vLLM serving audited: we normalize the 607.8 tok/s two-station GLM-5.3 demo per GPU, price the all-reduce tax, and derive a scale-out rule.


