CodeGraph cuts Claude Code token usage by pre-indexing codebases
HIROKI II's CodeGraph tool pre-indexes codebases into a local SQLite knowledge graph served via MCP, reducing Claude Code token usage by an average of 47% and tool calls by 58% across 7 open-source projects.
Score breakdown
Pre-indexing a codebase with CodeGraph before running Claude Code or similar agents can meaningfully reduce both token costs and latency on real-world projects, with the largest gains on larger codebases.
- 01Across 7 codebases, CodeGraph averaged 47% fewer tokens, 58% fewer tool calls, and 16% lower costs for Claude Opus 4.8.
- 02On VS Code's ~10,000-file codebase, token usage dropped from 1.79 million to 640K (64% reduction) and tool calls from 21 to 4 (81% reduction).
- 03CodeGraph uses `tree-sitter` to parse files into ASTs, supporting 20+ languages with structural understanding rather than regex-based grep.
HIROKI II's post introduces CodeGraph, a tool designed to eliminate what the author calls the "exploration tax" — the 50–70% of an AI coding agent's token budget spent simply locating relevant files rather than understanding or writing code. The typical agent workflow involves chained `grep` and file-read operations: each grep is a tool call, each file read loads the entire file into context, and when the agent guesses wrong it repeats the cycle. In a concrete example, answering a single architectural question about a payment flow consumed 6 tool calls and 5,400 tokens just to find the right files.
Benchmarks ran the same architectural question against 7 open-source projects using Claude Opus 4.8, each test repeated 4 times with median results reported.
CodeGraph addresses this by running `codegraph init -i` once to scan the project (skipping `node_modules`, build artifacts, and `.gitignore` entries), parsing every file into an Abstract Syntax Tree via `tree-sitter` (which supports 20+ languages and understands code structure rather than raw text), and storing extracted nodes (functions, classes, methods) and edges (calls, imports, extends, implements) in a local SQLite database with FTS5 full-text search. An MCP server then exposes eight tools to the agent — including `codegraph_explore`, `codegraph_callers`, `codegraph_callees`, `codegraph_impact`, and `codegraph_search` — returning structured symbol and relationship data instead of raw file contents.
Benchmarks ran the same architectural question against 7 open-source projects using Claude Opus 4.8, each test repeated 4 times with median results reported. The largest gains appeared in the biggest codebase: VS Code (~10k files) saw 64% fewer tokens, 81% fewer tool calls, and 18% lower cost, with the "with CodeGraph" agent making zero file reads or grep calls. Smaller projects also benefited — Alamofire (110 files, Swift) achieved 40% cost savings. Even break-even cases like Tokio (Rust) and Excalidraw (TypeScript) still recorded 38–40% fewer tokens and 25–44% fewer tool calls, with cost parity attributed to CodeGraph's responses being slightly more verbose due to structured context. The post notes the tool is strongly recommended for projects over 500 files, where the exploration tax scales linearly with codebase size.
Key facts
- 01Across 7 codebases, CodeGraph averaged 47% fewer tokens, 58% fewer tool calls, and 16% lower costs for Claude Opus 4.8.
- 02On VS Code's ~10,000-file codebase, token usage dropped from 1.79 million to 640K (64% reduction) and tool calls from 21 to 4 (81% reduction).
- 03CodeGraph uses `tree-sitter` to parse files into ASTs, supporting 20+ languages with structural understanding rather than regex-based grep.
- 04Extracted symbols and relationships are stored in a local SQLite database with FTS5; all data stays on-device with no external transmission.
- 05Eight MCP tools expose the graph, including `codegraph_explore`, `codegraph_impact`, `codegraph_callers`, and `codegraph_callees`.
- 06Alamofire (110 files, Swift) achieved 40% cost savings, showing benefits extend to small codebases, not just monorepos.
- 07The author attributes agent inefficiency to an 'exploration tax' where 50–70% of token budgets are spent finding files rather than understanding or writing code.
Topics
Summary and scoring are generated automatically from the original article. We always link back to the publisher and never republish images or paywalled content. Last processed Jun 8, 2026 · 10:27 UTC. How this works →