Playbook
Five Ways to Cut Your AI Coding Agent’s Token Bill
Token bills balloon because agents re-read the same files to answer overlapping questions. Here are five concrete levers, in rough order of impact.
If your AI coding agent's bill is climbing faster than your output, the culprit is almost always discovery — the agent reading files to figure out where things are. Generation is cheap; looking is expensive. Here are five levers, in rough order of impact.
1. Give it a code map, not the repo
The single biggest lever. When the agent can query a structure that already knows every symbol, import, and call edge, it stops pulling whole files into context to find three relevant lines. Discovery drops from thousands of tokens to a lookup. This is what OpenVisio does over MCP — and it typically cuts discovery tokens by 30–90× depending on repo size.
2. Scope the prompt to a surface, not a goal
"Refactor the auth system" invites the agent to read everything. "In
lib/auth/session.ts, split validate() into validate() and
refresh()" gives it a starting anchor. You don't have to hand-hold every
step — one good path:line in the prompt saves a dozen exploratory reads.
3. Turn off reflexive full-file reads
Many agent configs read an entire file when they only need a signature. If your tooling supports ranged reads or symbol lookups, prefer them. A 20-line function body beats a 600-line file for the same answer.
4. Reuse context across turns
Re-asking related questions in one session is far cheaper than starting fresh each time, because the relevant neighborhood is already in context. Batch your related asks; don't spread them across cold sessions.
5. Keep the map fresh, not constant
Re-indexing on every keystroke is wasteful; re-indexing never means the agent works from a stale graph and reads files to "check." Index on meaningful change — a commit, a branch switch — so the map is accurate without churn.
Put a budget around discovery
Cost control works better when it is observable. Track how many tool calls and input tokens happen before the first edit, then compare similar tasks over time. Set a soft limit that prompts the agent to summarize what it knows and name what is missing. That checkpoint catches circular exploration early without forcing every task into the same rigid allowance.
Cache stable answers within a session, especially repository skeletons, public type definitions, and dependency neighborhoods. Do not cache blindly across revisions: attach the commit or index version so a branch switch invalidates old structure. The aim is reuse with provenance, not a second source of stale context.
Finally, choose a model and context size appropriate to the phase of work. Discovery usually needs precise tools more than the largest model. Reserve expensive, long- context reasoning for ambiguous design decisions or the final cross-cutting review. The cheapest token is still the one the agent never needed to ingest.
Measure cost per completed change
Token counts alone can reward bad behavior. An agent that uses very few tokens but misses a caller is not efficient, and a difficult migration may correctly consume more context than a localized bug fix. Group tasks by shape, then track input tokens, tool calls, elapsed time, review corrections, and successful completion together. The useful unit is cost per verified outcome, not cost per prompt.
Create a representative benchmark from real work and run it before changing models, retrieval, or prompts. Include a symbol lookup, a cross-module trace, an ambiguous product-language question, and an impact analysis. Keep repository revisions fixed so comparisons are meaningful. When a new configuration costs less, inspect the returned evidence and resulting patch before declaring victory.
Reduce waste without starving the task
Set progressive budgets. Give initial discovery a small allowance, require a compact summary of known facts and gaps, then grant more context only where the evidence points. This prevents runaway exploration while allowing complex tasks to expand. Prefer exact snippets and typed relationships, but preserve access to full source when local nuance or generated patterns demand it.
Watch for false economies: minified tool output that drops source anchors, stale caches reused across branches, or prompts so narrow they hide a public contract. The goal is not to make every session tiny. It is to stop paying repeatedly for structure the toolchain can index once while continuing to fund the reasoning and verification that safe changes require.
The pattern underneath all five
Every lever above is really the same move: stop paying to rediscover structure you already know. A repository's shape doesn't change between two questions asked a minute apart — but a naive agent re-derives it every time. Persist that structure once, query it cheaply, and the token bill follows.
npm install -g openvisio # the map + MCP server, free and local
A code map isn't a silver bullet for reasoning quality — the model still has to think. But it removes the dumbest, most repetitive cost in the loop, and that is usually where the money is going.
- tokens
- cost
- AI agents
- productivity
See it on your repo
Paste a GitHub URL or open a folder — the map builds in your browser in seconds. No install, no account, nothing uploaded.
Try it freeor npm install -g openvisio for the MCP server