If you use AI agents like Claude Code, Cursor, or Codex CLI on large codebases, you know how fast tokens burn through. Every grep, every file read, every directory scan — it all costs. CodeGraph (github.com/colbymchenry/codegraph, 43k+ stars) attacks the problem at its root: instead of having the agent discover the code structure by exploring the filesystem, it delivers a pre-built knowledge graph.
How it works
CodeGraph parses your codebase with Tree-sitter and builds a local SQLite database containing the complete code structure: function definitions, classes, imports, dependencies, and file relationships. It then serves this information through the Model Context Protocol (MCP), the open standard for agent tooling.
Instead of the agent executing a dozen tool calls to answer “how does the caching system work?”, it asks CodeGraph directly, which returns the relevant fragments in a single call.
The real numbers (verified)
CodeGraph published detailed benchmarks across 7 real codebases, 7 languages, measuring 4 rounds per test with Claude Opus 4.8. The verified averages:
| Metric | Improvement |
|---|---|
| Tokens consumed | 47% fewer |
| Tool calls | 58% fewer |
| Cost | 16% cheaper |
| Response time | 22% faster |
The savings are even more dramatic on large codebases:
| Codebase | Language | Files | Token reduction |
|---|---|---|---|
| VS Code | TypeScript | ~10,000 | 64% |
| Django | Python | ~3,000 | 60% |
| OkHttp | Java | ~645 | 54% |
| Alamofire | Swift | ~110 | 64% |
| Tokio | Rust | ~790 | 38% |
| Gin | Go | ~110 | 23% |
| Excalidraw | TypeScript | ~640 | 25% |
The logic is simple: larger codebases have more structure to discover, and the agent spends more tokens on discovery. CodeGraph eliminates that expense almost entirely.
100% local and no API keys
CodeGraph is completely local: the SQLite database lives on your machine, no data leaves, it doesn’t need external API keys, and there are no cloud services. It supports more than 20 languages via Tree-sitter (TypeScript, Python, Go, Rust, Java, C#, PHP, Ruby, C/C++, Swift, Kotlin, Dart, Lua, Svelte, and more).
It includes a native watcher (inotify on Linux, FSEvents on macOS, ReadDirectoryChangesW on Windows) that keeps the graph automatically synced as you code.
Compatibility
CodeGraph works as an MCP server, meaning it’s compatible with any agent that supports MCP: Claude Code, Cursor, Codex CLI, opencode, Hermes Agent, Gemini CLI, Antigravity IDE, and Kiro. Integration is simple: add the MCP server to your agent’s configuration and you’re done.
The honest caveat
CodeGraph’s benchmarks focus on architecture/understanding questions. For code generation tasks, bug fixing, or refactoring, the savings may differ. Also worth noting that results improve with codebase size — on small projects (<200 files), the improvement is modest and may not justify the setup.
That said, if you work on a medium or large codebase and your Claude/Cursor/Codex API bills hurt, CodeGraph will likely save you money from day one.