How GitDB cut our agents' retrieval tokens: 65% measured, 95% per read
The token math behind both numbers — 12 measured code-navigation tasks against grep and ranged reads, the per-read math against whole-file reads, what each one does and doesn't cover, and how to reproduce them.
Updated October 2026 with end-to-end measurements against grep and ranged reads, plus the costs and limits our benchmark runs turned up.
There are two numbers in this post, and they answer different questions:
- 65% fewer tokens, measured end to end. Across 12 measured code-navigation tasks, each question was answered twice with the same queries: once with grep and ranged reads on a local checkout, once through GitDB. GitDB returned 6,718 tokens to the agent; local search returned 19,391. Grep plus ranged reads is already an efficient baseline, far leaner than whole-file reads.
- 95% fewer tokens per read, against whole-file reads. This is the gap when an agent that would otherwise dump a whole file asks GitDB for one function instead.
If you only remember one, remember the 65%. It's measured against grep and ranged reads, not against whole-file dumps. The per-read math is below because it's what most people ask about.
The headline isn't novel; the industry has been documenting the same shape for a year. Augment Code's research and independent measurements on Medium both converge on the finding that 60–80% of an AI coding agent's tokens go to finding things, not answering the question. A carefully reported case study on a 200-file TypeScript project swapped grep-based search for AST-level subgraph retrieval and watched Claude Code's input tokens fall from 8,200 to 2,100 on the same task — a 74% reduction from one change to the retrieval substrate. Our numbers aren't a different phenomenon; they're the same wedge.
The measured number: 65% against grep and ranged reads
Setup. One open-source repository at a single pinned commit (bad48a0e): about 1,800 files of JavaScript, TypeScript, Python, Go and shell. GitDB had indexed that exact commit, and the local checkout was verified at the same commit. Each of 12 code-navigation questions was answered twice:
- Local: what a careful agent would actually run —
rgfor searching (with--textwherever plainrgwould silently skip a tracked file),git difforlswhere one of those answers the question, then line-numbered reads of only the line ranges it needed. - GitDB: the GitDB tool built for that question, with its default output.
Both sides used the same queries. Where the local side needed an extra step (search, then read), that step was counted too. Every answer on both sides was checked against a completeness oracle — the facts the question requires — and every answer passed.
Where the numbers come from. Eight of the tasks (rows 1–8) come from our pre-registered official run: the tasks, queries and oracles were fixed before the first call. The other four (rows 9–12) were measured and archived separately, at the same commit and under the same rules. The raw answers from both sides are archived with checksums.
What we counted. Only the output tokens each side returned to the agent: the search results and code it had to read. We didn't count the model's own reasoning; the request each side sends was measured separately and isn't in the table. Tokens were counted with OpenAI's o200k_base tokenizer (via tiktoken) as a stand-in for Claude's, so treat the ratios as solid and the absolute counts as approximate.
| Task | Local | GitDB | Change |
|---|---|---|---|
| Grep an identifier across the repo | 833 | 741 | −11% |
| Read one function, end line unknown | 531 | 268 | −50% |
| Find the production callers of a function | 394 | 329 | −16% |
| Which function owns a given line | 316 | 42 | −87% |
| Concept search, then read the match | 3,763 | 1,467 | −61% |
| Natural-language code question | 406 | 398 | tie |
| Trace a call graph two levels deep | 2,808 | 268 | −90% |
| Read three line ranges from a file | 726 | 658 | −9% |
| Diff one function between two releases | 562 | 383 | −32% |
| Read a class by name, end unknown | 1,046 | 627 | −40% |
| Map a package's architecture | 4,304 | 1,116 | −74% |
| Grep with the enclosing function of every match | 3,702 | 421 | −89% |
| Total | 19,391 | 6,718 | −65% |
Across these 12 measured tasks, GitDB won 11 and tied 1. The production-callers task excludes test code on both sides; GitDB's answer also names how many test callers it left out. The wins are biggest where a structured question replaces several rounds of grepping and reading: call graphs, "which function is this line in", the enclosing function of every grep match, finding code by meaning rather than by name, and mapping a package's architecture. Where the job really is "show me these lines", local search is already lean and GitDB's margin is small.
These 12 measured tasks cover code navigation only.
The per-read number: 95% against whole-file reads
Most coding tasks need one function, not a file. When an agent asks "where is process_payment?" without a function-level index, the usual path is:
- Grep the codebase — already a multi-tool dance.
- Read the entire file the function lives in — ~9,000 tokens for a typical implementation file.
- Decide whether the function found is actually the one called from
auth_middleware.rs.
That last step is the killer. Because grep is lossy, agents often re-read the same file from a different angle just to confirm. One logical operation becomes two or three reads of the same file.
GitDB turns that into a lookup and a ranged read:
function lookup: "process_payment"
→ ~50 tokens out — a pointer, not the file
location: src/payments/handler.rs
line_range: 142..198
ast_node_id: ...
Then the agent reads exactly the lines it wants:
gitdb_read_lines("src/payments/handler.rs", 142, 198)
→ ~420 tokens — the function plus signature, nothing else
Total: about 470 tokens. Compared to the ~9,000-token full-file read, that's 95% less, per call. This comes from our internal sample codebase: about 850 files averaging 1,100 lines each, a fairly typical mid-sized Rust + TypeScript project.
The 95% only applies when the alternative is a whole-file read. An agent that already greps and reads ranges, which is what the 65% measurement uses as its baseline, saves less. In that measurement, "read one function, end line unknown" went from 531 tokens to 268 (−49.5%), not 95%.
Where it adds up: one feature, four agents
We tracked a month of agent activity on that internal codebase in April and zoomed into one 24-hour window where four coding agents had collectively done the following:
- Read 38 unique files
- Opened those files an average of 6.2 times each (the same file getting read by different agents in the swarm)
- Used ~1.4M input tokens
- Spent about $28 in raw LLM cost across the four agents
For one feature: a rate-limiting middleware.
Most of those 1.4M tokens were whole-file reads, many of them repeats. That is exactly the case the per-read math covers.
What this doesn't help with, and what it costs
A few things stay expensive after GitDB, and I'd rather call them out than leave them implied:
- Output tokens. If your agent writes 800 lines of code, that's 800 lines of tokens regardless of how it read the codebase. GitDB shrinks the prompt, not the response.
- Pure reasoning tasks. If the agent spends 10,000 tokens thinking about an algorithm design, that's chain-of-thought, not retrieval. We don't touch that.
- Code generation against unfamiliar libraries. External docs aren't in GitDB yet (something we're working on). Agents still pull from search or docs sites.
An earlier October run of the benchmark also surfaced costs the token table doesn't show:
- Tool definitions take up context. At the time of that run, GitDB exposed 56 tools. An agent that loaded every definition up front spent about 16,000 tokens at the start of a session — at the saving measured in that run, about 700 tokens per task, it took roughly 23 lookups to pay back. Clients that load tool definitions only when they're first used (Claude Code listed them by name, about 600 tokens) paid back after a handful of lookups.
- Each call is a network round trip. GitDB calls took about 300–900 ms each in that run, against under 15 ms for local
rg. Fewer tokens, but not faster. - Some structural answers were incomplete. At the time of that run, "who calls this function" found every production caller but missed calls made inside anonymous test callbacks — 23 of 31 call sites once test code was included. The call graph missed one function that was passed as a value rather than called by name; that run counted the answer anyway. Top-level constants could be listed but not looked up by name. We're fixing these, and until then a plain grep for the name is the safety net.
"95% off your LLM bill" is a tempting headline, and it isn't what we measured. The honest framing is a cut to the retrieval layer: 65% measured across 12 tasks against grep and ranged reads, up to 95% per read against whole-file reads. For coding-heavy workloads that layer is most of the bill, which is why we focused there. For chat-style agents, the wins will look different.
How to measure this on your own codebase
If you want to check whether the same shape would show up for you:
- Instrument your current agent runner to log per-call input token counts.
- Run a feature end-to-end. Record total in/out tokens and how many file reads happened.
- Bucket reads into "file dumps" vs "targeted line ranges." The full-file bucket is where most of the savings tend to live.
A rough lower bound for any team is the percentage of input tokens that come from full-file reads. If your agents mostly dump whole files, expect something closer to the per-read number. If they already grep and read ranges, expect something closer to the measured 65%. If you run a comparison like ours, count the same thing on both sides: the tokens returned to the agent, for the same questions with the same search terms. Your mileage will vary based on the codebase shape.
If you'd like to compare notes on the actual benchmark setup, please reach out. I'd be glad to share the raw numbers and the comparison script.
— Danny