How to save tokens with AI coding agents: we measured it, and the answer surprised us
· 14 min read · by EndorphinLab, the makers of ULU
Everyone says AI coding agents waste tokens reading files. We believed it too, and built a project memory, ULU Brain, to fix it. Then we did what almost nobody selling a token saver does: we ran the same tasks with the memory on and off and read the real bill. The first version we shipped made agents 47% more expensive. The fixed one makes them 35% cheaper on the questions it is built for, and saves nothing where one search is enough. And the biggest cost turned out to be something else entirely.
- On "what calls this, which tests cover it, what breaks if I change it" questions, ULU Brain made agents 35% cheaper, with 21 model calls where they had needed 33 and no wrong answers. Nine tasks on three open-source projects, three runs each.
- On simple lookups and ordinary edits in a small project it saved nothing. One search already answers those. ULU no longer asks the brain there.
- Reading files is not the big cost. The instructions an agent carries are. In a team run, about 95% of the tokens were the same instructions sent again on every call.
- A token sent for the first time cost us about 40 times what the same token cost when the model had it cached. So the bill depends less on how much an agent holds than on how often it has to be written again.
- We removed the "tokens saved" counter from ULU. It was flattering and it was not a measurement.
How we measured, so you can check us
A saving claim is only worth something if you can see how it was made. Ours comes from one method, and you can repeat it on your own project.
- Same task, twice. Once with ULU Brain, once without. Same model (Claude Sonnet), same tools, one session at a time.
- The bill comes from the agent, not from us. Cost, model calls and tokens are what Claude Code itself reports at the end of a session.
- A cheap wrong answer is not a saving. Each question has the right answer taken from the source code by plain search beforehand. An answer that misses a name counts as wrong.
- Three runs each, and a strict rule for "clearly". Agent runs vary. We call a difference clear only when the cost ranges of the three runs do not overlap. Everything else we call a direction, not a result.
- The plain copy must be truly plain. Our first baseline was contaminated: the test copy sat inside a folder whose instructions mentioned the brain, and the "plain" agent used it. Copies now live outside any project, and a plain run that reaches a brain fails.
That last point matters more than it looks. A contaminated baseline made our first numbers look far better than they were. If a vendor shows you a saving, ask where the baseline ran.
What a project memory saves, and what it does not
ULU Brain indexes a repository into a local graph: which function calls which, which tests cover what, which files change together, what was fixed where. An agent asks it a question and gets a short answer instead of searching.
Nine tasks: a lookup, an impact question and a change question on each of Redis, Flask and Gson.
| No memory | With ULU Brain | |
|---|---|---|
| Cost of the nine tasks | $0.216 | $0.141 (35% less) |
| Model calls | 33 | 21 |
| Tokens processed | 590,866 | 457,534 |
| Wrong answers, of 27 runs | 2 | 0 |
By kind of question:
| Kind of question | Cost with the brain | Model calls |
|---|---|---|
| What calls this, which tests cover it | 43% less | 14 down to 7 |
| What must change if I change this | 42% less | 11 down to 7 |
| Where is this defined | 22% more | 8 down to 7 |
What we can state as clear, by our own rule: the callers of a Redis function cost $0.011 with the brain against $0.044 without, in 2 calls instead of 5. The Flask callers question was clear too in one of our two setups. The totals point the same way on every impact and change question, but with three runs each they sit inside the spread, so read 35% as "about a third", not as a promise.
Now the part most articles leave out.
- Lookups got more expensive. "Where is this function?" is one search. Any memory you have to ask first is one more step. The right move is to stay out of the way, so ULU's agents now search directly when they already have the name.
- On ordinary edits in a small project, it tied. We gave a real team of agents two real changes in a mid-sized web app, with the full test suite as judge. Finding every caller took the plain agent one search. With the brain as a required step before every change, the runs came out 7% and 22% dearer, inside the spread of three runs but never cheaper. So it is no longer a required step.
- The version we first shipped was 47% dearer. It told agents to ask the memory before everything, never pointed them at the one command that answers "what calls this", and on one question left out a caller, which the agent trusted. All three are fixed, and we only know because we measured.
The honest summary: a code graph pays when the answer would otherwise take several rounds of searching. That is callers through a base type, tests that cover a change, a common name in a large codebase. It does not pay when one search does the job. Anyone who tells you their graph saves 90% on everything has measured against an agent that reads whole files, and agents do not work that way.
Where the tokens of an agent team really go
This is the finding we did not expect, and it is the most useful thing on this page whether or not you ever install ULU.
We recorded every model call of a team run. An agent in that team starts with about 110,000 tokens before it has read one line of your code: the coding tool's own prompt, the team's rules, the agent's skills, the list of other agents. The work itself, all the searching, reading and editing, added about 25,000 on top. Every call sends all of it again.
| What every call of the orchestrator carries | Tokens |
|---|---|
| The coding tool itself, with its tools | 17,500 |
| The team's rules | 18,800 |
| The list of agents | 7,200 |
| The list of skills | 7,200 |
| Project notes and the rest | about 16,000 |
| Starting prompt | about 67,000 |
That sounds like an argument for short instructions. It is not, and here is why. Those rules and skills are the reason a team of agents writes better software than one agent in a chat. Cutting them makes runs cheaper and work worse. We tried it, and the cheapest runs were the ones that stopped early.
The real lever is the prompt cache. A model provider can keep a prompt it has just seen and charge far less to read it again. We started the same 67,000-token session twice:
| Written fresh | Read from cache | Cost to start | |
|---|---|---|---|
| Prompt already cached | 0 | 67,000 | $0.007 |
| Same prompt, not cached | 55,400 | 11,600 | $0.22 |
About 40 times, on the model and plan we ran. So a large, careful set of instructions is cheap as long as it is read from cache, and expensive each time it has to be written again.
In our team runs it was written again at every agent start: about 100,000 tokens, roughly half the cost of the run. The cause was one small thing. The coding tool puts a snapshot of the repository's status into each agent's prompt. The orchestrator creates a new folder for each task before it starts an agent. The folder's name appears in the snapshot, the prompt differs by one line, and the whole thing is written fresh.
With that snapshot left out, in a controlled test the same agent with every rule and skill wrote about zero tokens at its start, and the session cost $0.26 instead of $0.50. Nothing was taken from the agent. In full team runs since, with every rule and skill kept, the agent's start was read from cache in 3 of 6 runs, and those runs cost $0.35 to $0.59 against $0.64 to $0.66 for the same team without the change. All 12 runs passed their tests and wrote their reports. One run missed the cache for a reason we have not found yet, so this is not in ULU yet. It goes in when it works every time.
What we changed in ULU because of this
- The brain is asked when it saves a search. Callers, tests and change impact go to it. A name the agent already has goes to plain search. New code that changes nothing existing does not ask at all.
- Its answers say what they cover. An impact answer ends with a check of every line in the project that names the symbol. If something could not be linked, it is listed. If the list is complete, it says so, and only then.
- Every line is read from your files at the moment of the answer. A stored graph goes stale. An answer checked against the disk can be acted on without opening the file to confirm.
- The "tokens saved" counter is gone. It compared each answer with reading whole files, which agents rarely do. It made us look good. ULU now shows what it can count: how often the brain was asked, and the real cost of each step.
- New in ULU 0.10: the brain builds the agent's task. When the orchestrator starts an agent, the brain attaches what that agent needs: the code the task names with every line that calls it, what the previous agent changed, the tests that cover it and the command that runs only those. A tester and a reviewer get different briefs than a developer. The agent starts informed instead of exploring.
Does a short answer still find the right code?
A small answer is only useful if it is the right one. We test that with a frozen set of 15 coding questions about a real open-source project. ULU Brain returned the expected result first in 15 of 15 questions, with no answer over its token budget, at about 737 tokens per answer on average.
Does it scale to a big codebase?
In an earlier build test, ULU Brain indexed the whole Linux kernel source tree: 66,063 code files, 1.29 million nodes and 4.28 million relationships, in about 30 minutes on an Apple Silicon Mac. That is one build on one machine, not a promise for every computer. We have not yet run the on-and-off cost test on a codebase that size. It is where a graph should help most, and we will say what we find either way.
Why ULU has its own brain instead of Neo4j or Graphify
Both are good tools, and the comparison is about fit, not about a number. We have not run a matched cost test against either, so we do not claim one.
| ULU Brain | Neo4j | Graphify | |
|---|---|---|---|
| What it is | A project memory for a team of coding agents | A general graph database, with tools to query it | A code and document graph builder for a coding agent |
| What you run | One program and one local file | A database server | A local tool, with AI passes for documents and media |
| The coding part | Included: indexing, call and test links, change tracking, agent setup | You build it on top | Included for code |
| Knows the team's own work | Yes: runs, reports, what each agent learned, open tickets | Only if you model it | Not its purpose |
| Keeping answers current | Each line is read from the file when the answer is given | Whatever you build | The graph is rebuilt on commit and checkout |
| Beyond code | Tests, docs, bugs, issues and Git history | Anything you model | Wider document and media support |
ULU Brain and Neo4j
Neo4j is a powerful graph database. It is not a coding tool. It does not read a repository, decide what a call points to, follow changes or set up an agent. Teams that report big savings with it built that layer themselves, for their own data. ULU Brain is that layer, for code, working on day one.
ULU Brain and Graphify
Graphify is the closer neighbour: a local code graph an agent can query. It also covers documents, diagrams and media, which ULU Brain does not. Two things made us keep our own.
ULU runs a team, not one agent. A graph that waits to be asked helps one agent at a time, when it remembers to ask. A team needs the knowledge handed to each agent as it starts, shaped by its job, with what the agent before it just changed. That is a different product from a query tool.
A wrong link costs more than no link. On a pinned set of 14 source files, with Graphify's deterministic extraction and no AI enrichment, Graphify recorded calls that do not exist when a Python function reused an imported name locally. ULU Brain did not. Where both were right, such as TypeScript import aliases and Python relative imports, they agreed. This is a correctness check on a small fixture, not a benchmark.
And one limit applies to every tool in this category, ours included: on a small project and a simple edit, search is already cheap. A code graph earns its place on the questions search answers slowly.
How to save tokens with AI coding agents, with or without ULU
- Measure on and off. Run one real task both ways and read the bill your tool reports. It takes ten minutes and it beats every claim, including ours.
- Keep the agent's instructions stable. Anything that changes at the top of a prompt, a date, a status snapshot, a file list, makes the model read all of it as new. Stable instructions are read from cache.
- Run related work close together. A cache does not last. Anthropic documents a default of five minutes and an option of one hour. In our runs a prompt was still cached 25 minutes later.
- Do not cut instructions that make the work good. Cheaper and worse is not a saving.
- Give one job per conversation, and name the place. A focused task with a file or function named reads less than "look around and improve things".
- Use a project memory for the hard questions. What calls this, what tests cover it, what breaks. Not for what one search finds.
Questions people ask
How do I reduce Claude Code token usage?
Start with the cache: keep the instructions at the top of the prompt unchanged between sessions and run related tasks close together. Then keep each task focused and name the place to work. Then give the agent a project memory for questions that take several searches. ULU does all three for a team of agents.
Will ULU Brain cut my AI bill by a third?
On questions about callers, tests and change impact, it did in our tests, by about a third. On simple lookups and small edits it did not. Your mix decides. A large, unfamiliar codebase has more of the first kind. ULU shows the real cost of every step of every run, so you see your own figure, not ours.
Does ULU Brain send my code to an AI service?
No, not for indexing and search. ULU Brain is a single program with a local file on your computer, and indexing and retrieval need no AI model. Your agent still sends its own work to its model, as it would without the brain.
Which coding agents does it work with?
Claude Code, Codex, Cursor and Antigravity, with one-click setup for a project. It speaks MCP, the common protocol agents use to call tools.
Do I need to code to use it?
No. In ULU, the brain is offered once per project, set up for you, and kept current as the project changes. If you are new to this, start with Claude Code without coding. For what agents cost in general, see What AI agents cost.
Try it
ULU is a team of AI agents that builds your software, with a memory of your project and the cost of every step in plain sight. It runs on Mac, Windows and Linux, and your first project is free. Install ULU.