Save Up to 82× Tokens in AI Code Review with the Open‑Source code‑review‑graph

The code‑review‑graph tool parses a codebase into a local SQLite graph, lets AI reviewers query only the affected files, and achieves a median 82‑fold token reduction across six real‑world projects while supporting incremental updates and dozens of languages.

Java Companion
Java Companion
Java Companion
Save Up to 82× Tokens in AI Code Review with the Open‑Source code‑review‑graph

Problem Statement

Claude Code and similar LLM‑based reviewers read every file they deem related to a change, which can consume hundreds of thousands of tokens for large projects. The author experienced severe token burn when a three‑file change triggered scans of hundreds of files.

What code‑review‑graph Is

code‑review‑graph is a locally‑run, MIT‑licensed Python tool that builds a code‑graph using Tree‑sitter. It extracts functions, classes, imports, call relations, inheritance, and test coverage, storing the data in a SQLite file. The tool then exposes the graph via an MCP service that Claude Code, Codex, Cursor and other AI assistants can query.

Core Workflow

Parse the repository with Tree‑sitter → store the graph in SQLite → AI asks the graph for the blast radius → AI reads only the returned files.

Blast Radius Feature

When a function changes, the graph follows call, dependency and test edges to list every potentially impacted function, class and file. This replaces the previous heuristic of scanning whole directories, providing precise impact analysis.

Incremental Updates

The tool offers a watch mode that hashes saved files with SHA‑256, re‑parses only the changed files and their dependent nodes. In the author’s benchmark, a 2 900‑file project updates in under 2 seconds, and the initial graph for 500 files builds in about 10 seconds.

One‑Command Integration with AI Tools

Running code-review-graph install automatically discovers installed AI coding tools and writes the appropriate configuration files ( .mcp.json, ~/.codex/config.toml, .cursor/mcp.json, etc.). The MCP protocol then exposes 30 operations such as call‑chain lookup, impact analysis, architecture overview and uncovered test hotspots.

Benchmark Results

The author benchmarked six open‑source projects (fastapi, flask, gin, express, httpx, and code‑review‑graph itself). The median token saving was 82×; the best case (fastapi) achieved 528×. For the flask case, full‑read required 125 022 tokens while graph‑based read needed only 1 986 tokens (71× reduction). The README notes that the 528× figure is a best‑case outlier, not a typical expectation.

Limitations: single‑file tiny changes can cost more tokens with the graph; keyword‑search ranking is average; flow‑detection recall is 33%.

Additional Capabilities

Semantic search with optional vector embeddings (local sentence‑transformers or OpenAI‑compatible API).

D3.js visualisation of the call graph, exportable to Obsidian, Neo4j, SVG.

Automatic wiki generation from the code structure.

Refactoring helpers (rename preview, dead‑code detection).

Multi‑repo daemon for synchronized updates across repositories.

Custom language support via .code-review-graph/languages.toml.

Supported languages include Python, JavaScript/TypeScript, Go, Rust, Java, C/C++, PHP, Ruby, Kotlin, Swift, and Jupyter notebooks; PHP handling even parses Laravel routes and Eloquent relations.

Getting Started in Three Commands

pip install code-review-graph
code-review-graph install    # auto‑detects and configures all installed AI tools
code-review-graph build      # parses the current project

Specific tools can be installed with code-review-graph install --platform codex (or claude-code, cursor).

After installation, ask the AI “Build the code review graph for this project” and it will use the graph automatically.

Measuring Token Savings

code-review-graph detect-changes --brief

This prints a panel showing total tokens for full read, tokens used via the graph, and the percentage saved.

Who Should Use It

Ideal for projects with several hundred files that regularly use Claude Code or Codex for reviews, especially monorepos. In a 200 k‑token codebase, the median per‑question token count dropped to 2 495. CI pipelines can also leverage the provided GitHub Action for automated risk scoring and fail‑on‑risk enforcement.

Not recommended for tiny repositories, single‑file edits, or one‑off review tasks, as the overhead of building and maintaining the graph outweighs token savings.

Author’s Verdict

The tool’s local‑first design (graph stored in SQLite, no telemetry) eases security reviews, and the transparent benchmark data—including upper bounds and known defects—builds trust. While many of the 30 MCP‑exposed tools are niche, the core impact‑analysis feature delivers clear value for large codebases.

Open‑Source Repository

https://github.com/tirth8205/code-review-graph
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

static analysisMCP protocolAI code reviewtoken optimizationcode-review-graphPython tool
Java Companion
Written by

Java Companion

A highly professional Java public account

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.