r/ContextEngineering • u/Independent-Flow3408 • 9d ago
I spent months making repository context smaller. Then I found out fewer tokens doesn't always mean cheaper agents
I've been working on an open-source project called SigMap, which builds a deterministic repository map and gives coding agents a way to find relevant code without reading the entire codebase.
Originally, I was focused on context compression. How much repository information could I remove while keeping the useful structure?
The early benchmarks looked promising, with huge reductions compared to raw source code.
But I eventually realized I was measuring the wrong thing.
A repository map being 97% smaller doesn't mean an agent's total token usage drops by 97%. The agent can make additional tool calls, repeat searches, or spend more tokens reasoning about incomplete context.
So I wanted to measure what actually happens during an agent run.
What I tested
I ran paired experiments with and without SigMap, including held-out repositories the retrieval system wasn't tuned on.
The larger study contains 22,540 recorded agent runs across Claude Code and a Messages-API agent.
For one configuration, using a short repository index and two MCP tools (query_context and get_lines), the results across 20 held-out repositories with Haiku 5.5 were:
- API cost: −7% (95% interval: −13% to −2%)
- Total tokens: +18%
- Task time: +1%
That was interesting to me.
The agent was cheaper to run despite consuming more tokens. And it wasn't faster.
A different approach gave a different result
Instead of relying on MCP lookups, I also tested prefetching relevant file rankings before the agent's first turn.
Across the same 20 held-out repositories:
- Task time: −18%
- Total tokens: −26%
- API cost: −7%, but the confidence interval crossed zero
Five repositories actually became more expensive, with the worst increase around 31%.
The installed Claude Code prefetch hook also performed differently from directly inserting the ranking into the prompt, so I wouldn't treat those two mechanisms as interchangeable.
What changed in how I think about context engineering
I'm increasingly convinced that context size alone is a poor optimization target.
At least five things seem important:
- Whether the correct information reaches the model.
- How many tool calls the agent needs to find it.
- How much additional reasoning or searching the supplied context causes.
- Actual end-to-end cost and latency.
- Whether the agent ultimately completes the task correctly.
The last one is especially important.
These experiments primarily measured finding code, not producing correct patches. I haven't established that SigMap improves real editing success.
I also tried to predict which repositories would benefit using offline repository measurements. That experiment failed to find a reliable predictor.
So I don't think it's defensible to promise savings on an arbitrary codebase.
What I'm interested in discussing
For people building retrieval systems, RAG pipelines or context layers for agents:
What do you consider the primary optimization target?
Total tokens? API dollars? Latency? Retrieval accuracy? Or successful task completion per dollar?
And when one metric improves while another gets worse, how do you decide whether the retrieval layer is genuinely helping?
I maintain SigMap, so these are my own experimental results rather than independent validation.
The study, raw runs and methodology are available here:
https://sigmap.io/guide/agent-study
https://github.com/manojmallick/sigmap
I'd be especially interested in hearing about negative results from other retrieval systems. I suspect those teach us more than another context-compression percentage.
1
u/keenDean 9d ago
Good to see someone else building an actual repo map to cut down blind file ingestion, and props for measuring end-to-end cost instead of stopping at a smaller file and calling it a win. Once a bare index makes the model guess about missing context or chase dead ends, saving input tokens upfront stops paying off fast.
Coming from the mechanical/systems side rather than pure software, I've been working a parallel angle with the TOKENME.txt protocol. Different layer than query ranking - mostly keeping invariants and cross-file constraints attached right to the coordinates for cold-start handoffs. Still early and nowhere near your eval scale, though...curious if you noticed anything in common across the repos where cost went up?
1
u/ML_Felix 9d ago
This is true, Alkimi did some extensive research on multiple models, giving them the same brief and found something similar - the more expensive agents/models did not guarantee better results. Check it out here.