Stop Letting Your AI Read Files: The Token Economics of Code Intelligence
Why a code graph is one of the highest-leverage ways to cut AI-agent token spend — and which tool to use.
Bottom line up front. Put a code graph between your AI agents and your codebase. In a recent evaluation (~18 APIs, Python FastAPI, React SPA, Postgres, roughly 48k lines of code), answering one structural question through a graph took a single bounded query (~a couple thousand tokens); the grep-and-read equivalent took ~a dozen tool calls and tens of thousands of tokens — roughly an order of magnitude more, for a worse answer. Recommendation: adopt a structural graph (Codegraph) as the everyday breadth layer, keep a Code Property Graph (Joern) for taint/security on critical paths, and skip semantic-search and browser-based options for agent workflows.
Why it’s expensive today
An agent doesn’t know your code — it rediscovers it every session: grep, open five files, read them whole (imports, boilerplate, and all), grep again, open three more. You pay for that in tokens and round-trips, then pay again next session. Structure is a fixed fact; re-deriving it inside the model’s context window is the costliest possible way to know it.
The token math
A recent real-world exploration needed a module’s routes and every backend call-site. A graph returned it in one bounded query — the few files that mattered, the call edges among them, plus an unprompted “this has no test.” The grep-and-read version: ~a dozen calls and five whole files; on large server-side files the gap widens to ~20–40k tokens to surface a handful of relevant lines. One call vs. a dozen, signal vs. noise — and the graph’s answer was more complete.
Graph beats semantic search
Embeddings return the k most-similar chunks — approximate, so you over-fetch and still verify — and they have no edges, so they can’t answer “what calls this?” or “what breaks if I change it?” A graph returns the exact symbol, its neighbors, and the blast radius. For an agent about to make a change, the blast radius is the whole point.
The verdict
| Tool | What it is | Decision |
|---|---|---|
| Codegraph | Local structural graph — symbols + call edges + blast radius, MCP | Adopt — authoritative breadth layer; broad languages including Dart |
| Joern | Code Property Graph — adds data-flow / taint analysis | Adopt — security on critical paths (no Dart; heavier build) |
| GitNexus | In-browser / WASM structural graph (tree-sitter, 13 langs) | Skip — wrong model for headless agents; language gaps |
| Claude-Context | Semantic retrieval — vector DB + embeddings | Skip — approximate, no edges, heavier infra |
The principle
Scaffolding beats model. Code structure is a fixed cost: pay it once at index time (a cheap parse), not every session inside the context window (the most expensive rate there is). If you’re running agents on a codebase you intend to keep, don’t let them read files to learn its shape. Build the graph; pay it once.
Tools: Codegraph (local structural graph + MCP); Joern (CPG); GitNexus; Claude-Context. Token figures are observed from a real evaluation, not a benchmark — order-of-magnitude, which is all the decision needed.
Originally published on LinkedIn, June 30, 2026.