Why does an AI coding agent use so many tokens?
Because the whole context is sent again on every call. A model doesn't remember the previous step; the agent re-sends everything it needs, every time.
Instructions
System prompt and rules files, on every call.
Tool definitions
Every enabled tool's description, whether it's used or not.
History
The conversation so far, growing with every turn.
Files
Whatever the agent has read, often whole files.
Tool output
Test runs, build logs and search results, frequently the biggest single item.
Re-explaining
The background you paste into every new session because the agent forgot it.
The last one is the sneakiest. Each session starts from zero, so you (or a long rules file) re-supply the same decisions and conventions every time, and pay for them every call.
10 ways to cut AI coding token costs
Roughly in order of how much they save.
- Stop re-explaining. Keep decisions, preferences and fixes in persistent memory, and inject only the ones relevant to the task, instead of pasting the same background into every session.
- Start a fresh session for each task. One endless conversation pays for its whole history on every call. A new task rarely needs the last one's transcript.
- Compact long sessions. When a session must continue, summarise the history into the facts that matter. Most agents have a command for this.
- Point, don't paste. Name the files and functions that matter rather than pasting whole files or folders.
- Trim tool output. Cap long test runs and build logs, show failures not passes, and filter noise before it reaches the model.
- Disable tools you don't use. Every enabled tool's definition is sent on every call. Unused integrations are pure overhead.
- Use prompt caching. Providers charge less for input that repeats exactly. Keep stable instructions at the start of the prompt and don't edit them mid-session.
- Right-size the model. Use a smaller, cheaper model for simple subtasks like renames, formatting or summaries, and save the big one for hard reasoning.
- Keep rules files short. Instruction files are re-read every session. Move rarely needed detail out, and keep only what applies to most tasks.
- Measure every change. Track tokens and cost per task, so you know which change actually helped and which only felt like it did.
How much can persistent memory save?
A lot, because it replaces the largest repeated cost: history.
| Accuracy | Tokens per question | Cost, 1,540 questions | |
|---|---|---|---|
| Whole conversation | 89.3 | ~20,800 | $3.36 |
| Memory, 40 results | 86.6 | ~3,700 | $0.73 |
| Memory, 20 results | 78.8 | ~2,000 | $0.47 |
On the LoCoMo benchmark, with the same model answering and judging, retrieved memories kept 97% of the whole-conversation accuracy while reading 82% fewer tokens, at about a fifth of the cost. On a far larger history (about 1.27 million tokens per question, too big for any model), memory read 98.5% fewer tokens and still answered 83% correctly. More in long context vs RAG vs memory.
What shouldn't you cut?
Anything the agent actually needs. Starving the context is a false saving.
- The task and its constraints. A vague prompt leads to a wrong answer and a second, longer attempt.
- Decisions that still apply. Forgetting them means the agent re-does or undoes work.
- The relevant code. Guessing at an interface it hasn't seen produces bugs you pay to fix.
The goal is a small context, not an empty one. See context engineering for AI agents for how to decide what earns a place.
How do you measure token usage?
Per task, not per month.
Most coding agents can show usage for a session, and every model provider's dashboard breaks down spend. Pick a few typical tasks, measure them before and after a change, and keep only what moves the number.
Frequently asked questions
Why does my AI coding agent use so many tokens?
The whole context (instructions, tool definitions, history, files and tool output) is re-sent on every call, so long sessions pay for their own history repeatedly.
What is the fastest way to reduce token usage?
Start a fresh session for each task, and stop pasting the same background into every session; persistent memory that injects only what's relevant replaces most of it.
Does prompt caching reduce costs?
Yes, for the parts of the prompt that repeat exactly. Keep stable instructions first and unchanged during a session.
Will cutting tokens make the agent worse?
Not if you cut noise rather than signal. Retrieved memories reached 97% of full-conversation accuracy with 82% fewer tokens in our tests.
How much can persistent memory save?
On a 1,540-question benchmark, $0.73 instead of $3.36 with the same model, about 4.6 times less.
Benchmark figures measured by us on LoCoMo and LongMemEval-M, October 2026, with the same model answering and judging within each comparison; costs at API list prices on the day of the run.
Stop paying to re-explain your project.
Open Agentic Brain and Memory is an open-source, self-hosted memory layer for AI coding tools. It remembers decisions across sessions and tools, and hands each new session only what's relevant, so you stop paying for the same context twice.
curl -fsSL https://raw.githubusercontent.com/rohithhn/Open-Agentic-Brain-and-Memory/main/install.sh | bash