When AI Reads Your Code: code-review-graph Builds a Persistent Map of Your Codebase
You ask Cursor to modify a function, and it first spends 30 seconds scanning the whole repository. Then you ask it to modify the neighboring function—it scans for another 30 seconds. Same repository, same structural information, read from scratch every time.
This isn't because AI isn't smart enough. It's because it has no map.
tirth8205/code-review-graph solves exactly this: it builds a persistent structural map of your codebase so AI tools only read the small piece they actually need.
The Problem: AI Coding Tools' "Goldfish Memory"
Current AI coding tools (Cursor, Claude Code, Copilot) share a common hidden cost: they start understanding the codebase from zero in every conversation.
The typical flow: you ask "where is this function called," and the tool either greps the whole repo (slow and noisy) or uses vector retrieval to find similar text snippets (which can miss exact call relationships). Either way, every conversation rescan feeds results into the context window.
For a 100k-line codebase, an AI tool may burn 50k+ tokens per conversation just to "understand context." It's like having to relearn your office layout—where the door, desk, and meeting rooms are—every time you walk in.
The root problem is a granularity mismatch: AI tools work at "file + line" granularity, but a codebase's structural information lives at "function + call relationships + module dependency" granularity. Understanding code with the wrong granularity is like looking at a map under a microscope—plenty of magnification, but you'll never see the whole road.
The Approach: Build the Map First, Then Ask for Directions
code-review-graph works in three steps:
Step 1: Structured parsing with Tree-sitter. Tree-sitter is GitHub's open-source incremental parsing library, able to parse source code into syntax trees in milliseconds. Instead of relying on language-specific LSPs (Language Server Protocol), code-review-graph uses Tree-sitter to uniformly handle all languages—Python, TypeScript, Rust, Go all go through the same pipeline.
Step 2: Store the parse results as a graph. Not a file tree, not a symbol table, but a relationship graph: function A calls function B, class C inherits from class D, module E depends on module F. The graph is persisted in local SQLite. When an AI tool asks "who calls this function," there's no repo scan—just a graph query.
Step 3: Expose it to AI tools via MCP. MCP (Model Context Protocol) is Anthropic's standard protocol for letting AI tools access external data sources uniformly. code-review-graph implements an MCP server, so any MCP-capable tool (Claude Code, Cursor, etc.) can query the code graph directly.
Why a "Map" Beats "Search"
Traditional AI coding tools acquire context in a search-driven way: ask a question, search for relevant files, stuff results into context. Every search starts from scratch.
code-review-graph is map-driven: it pre-builds the code's structural graph, turning AI questions into graph queries rather than text searches.
| Dimension | Search-driven | Map-driven | |------|---------|---------| | First query | Full repo scan | Graph query (milliseconds) | | Subsequent queries | Rescan | Graph query (milliseconds) | | Context consumption | 50k+ tokens | A few hundred tokens | | Call relationships | Fuzzy grep matching | Exact graph edges | | Incremental updates | None | Only changed parts |
Key figure: SQLite graph queries typically return in 1-5 ms, while a traditional full-repo grep on a 100k-line codebase takes 200-500 ms. The 100x speed difference doesn't come from a faster engine—it comes from smarter granularity.
This Is Not RAG
Some will ask: isn't this just RAG (Retrieval-Augmented Generation) for code?
No. RAG uses vector retrieval to find "semantically similar" text snippets, but code call relationships aren't captured by semantic similarity. Function A calling function B may involve two functions with completely different names and semantics—yet the call relationship is an exact structural fact.
RAG's core assumption is "semantic similarity ≈ relevance," and that assumption fails in rule-based worlds. The Euclid-MCP experiment already showed that a 480B-parameter LLM is as bad as an 8B model at rule-based reasoning over 1,000 facts. Code call graphs are exactly such a rule world: A calls B—that's a fact, not a probability.
code-review-graph doesn't do semantic retrieval; it does structural queries. It answers not "which files are relevant to this question" but "who calls this function, what does it call, what modules does it depend on." Exact facts, no probability needed.
"Local-first" Isn't Decoration
code-review-graph emphasizes "local-first"—all data lives in local SQLite, nothing uploaded to the cloud. This isn't just a privacy consideration; it's a performance one.
Cloud solutions (like Sourcegraph) have 100-500 ms latency; local SQLite queries take 1-5 ms. For AI coding tools, 100 ms of query latency means 0.1 extra seconds per conversation—minutes accumulated over a day. Local-first isn't a "privacy-friendly" marketing line; it's an engineering choice that's "100x faster."
Conceptual Lineage: From "Brute-Force Search" to "Structural Map"
code-review-graph's core insight fits a larger conceptual lineage:
- Octopus RNA editing: DNA as pretraining + RNA as inference-time computation—change the blueprint's execution, not the blueprint
- Slime mold externalized memory: memory externalized in slime trails, no neurons needed
- Avian quantum magnetoreception: amplifier and sensor separated—division of labor beats unification
- Euclid-MCP reasoning offloading: let the LLM be the poet, let Prolog be the accountant
- code-review-graph structural map: externalize code structure into a persistent map; AI tools query instead of scan
- Cursor/Claude Code users: if your codebase exceeds 10k lines, per-conversation context scanning costs are already significant. code-review-graph can cut context consumption by an order of magnitude.
- MCP ecosystem participants: code-review-graph is a flagship implementation of MCP in the code-intelligence domain—worth studying for its interface design.
- Codebase maintainers: even without AI tools, the structural graph helps you understand dependency relationships in large codebases.
- Only supports languages Tree-sitter can parse: obscure languages may not be covered
- Graph quality depends on Tree-sitter syntax trees: semantic-level relationships (like design patterns) can't be captured
- Incremental updates are still early-stage: incremental performance on large monorepos isn't fully validated
All five point to the same principle: don't do the same thing harder—solve the problem at a different level. AI tools don't need stronger search; they need a pre-built map.
Who Should Use It
Limitations
Closing
The next breakthrough in AI coding tools won't come from bigger models—it will come from better context engineering. code-review-graph upgrades "understanding code" from "re-searching every time" to "querying a persistent map," which matches how human programmers work: you don't relearn the office layout every time you walk in—you have an internalized map.
A map is 100x faster than search not because its engine is stronger, but because a map doesn't need to be redrawn every time.
---
GitHub: https://github.com/tirth8205/code-review-graph Website: https://code-review-graph.com MCP Protocol: https://modelcontextprotocol.io