Code Review Graph: Slash AI Coding Tool Tokens by 82× with Code Graphs
TL;DR: AI coding tools (Claude Code, Cursor, Copilot) re-read your entire codebase during code review, wasting tons of tokens. code-review-graph builds a code structure graph with Tree-sitter and feeds precise context to AI tools through the MCP protocol. Real-world tests show an 82× reduction in token consumption.
What Is This Project?
code-review-graph is a local-first code intelligence graph tool. Today (2026-07-21), it hit #1 on GitHub Trending, gaining 1,876 stars in 24 hours and crossing 22,900 total stars.
The core problem: When you use Claude Code or Cursor for code review, the AI re-reads a massive amount of code files—even if you only changed one function. For large projects, that means tens or hundreds of thousands of tokens per review.
The solution: code-review-graph parses code into ASTs (Abstract Syntax Trees) using Tree-sitter, then builds a graph of functions, classes, imports, and call relationships. When a file changes, the graph tracks all callers, dependencies, and affected tests. It calculates the "blast radius"—so the AI only needs to read those relevant files, not the whole codebase.
Benchmark results: - Median token reduction: 82× (tested across 6 open-source projects) - Best case: FastAPI project reduced 528× (950K tokens → 2,169 tokens) - Incremental updates: 2,900-file project re-indexed in under 2 seconds
Installation & Setup
System Requirements
- Python 3.10+
- A Git or SVN repository
- Recommended: uv (a faster package manager)
One-Command Install
# Install code-review-graph
pip install code-review-graph
# Or use pipx
pipx install code-review-graph
# Auto-detect and configure all supported AI coding tools
code-review-graph install
# Build the code graph (~10 seconds for 500 files on first run)
code-review-graph build
The install command auto-detects which AI coding tools you have installed (Claude Code, Cursor, Copilot, Gemini CLI, Codex, Kiro, etc.), writes the correct MCP config for each tool, installs platform-native hooks/skills, and injects graph-aware instructions.
Configure Specific Platforms
If you only want to set up a specific tool:
# Configure Claude Code only
code-review-graph install --platform claude-code
# Configure Cursor only
code-review-graph install --platform cursor
# Configure GitHub Copilot only
code-review-graph install --platform copilot
# Configure Gemini CLI only
code-review-graph install --platform gemini-cli
After installation, restart your editor or AI tool.
Quick Start
Step 1: Build the Graph
Run this in your project root:
cd /path/to/your/project
code-review-graph build
The first build parses all code files, extracts functions, classes, imports, and call relationships, and stores them as a graph database. About 10 seconds for a 500-file project.
Step 2: Use Your AI Tool
Open your AI coding tool (Claude Code, Cursor, etc.) and ask directly:
Build the code review graph for this project
The AI will query the graph through the MCP protocol to get precise code context.
Step 3: Review Code
When you do PR review, the AI tool will automatically: 1. Detect changed files 2. Query the graph to find all callers, dependencies, and affected tests 3. Read only those relevant files (instead of the entire codebase) 4. Generate targeted review comments
Example scenario: You modified the validate_token() function in auth.py. The graph tracks:
- Every file that calls validate_token()
- Classes inheriting from related base classes
- Related test files
- Other modules depending on these files
The AI only reads those files (usually 10–20), not the whole codebase (which could be thousands of files).
Advanced Features
How MCP Integration Works
code-review-graph communicates with AI tools through the MCP (Model Context Protocol). MCP is an open protocol that lets AI models access external tools and data sources.
Workflow: 1. AI tool receives a code review request 2. Calls code-review-graph tools through MCP 3. code-review-graph queries the graph and returns the minimum file set needed 4. AI reads only those files and generates review comments
Available MCP tools (30+):
- get_review_context: get review context
- get_blast_radius: get change impact scope
- get_callers: get function callers
- get_dependencies: get file dependencies
- get_test_coverage: get test coverage status
- ...
GitHub Action Integration
code-review-graph provides an official GitHub Action that automatically generates code review comments on PRs.
# .github/workflows/code-review-graph.yml
name: Code Review Graph
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: tirth8205/code-review-graph@v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Features:
- Each PR gets an auto-generated sticky comment
- Includes risk-scored functions, affected execution flows, and test gaps
- Comments update automatically on every push
- Optional fail-on-risk input to gate merges on review results
Local-first: The knowledge graph is built and queried entirely on the CI runner. Source code is never sent to any external service.
Incremental Updates & Watch Mode
With hooks or watch mode enabled, file saves and commit hooks trigger incremental updates:
# Enable watch mode (auto-update on file save)
code-review-graph watch
# Enable pre-commit hook
code-review-graph install --hooks
Incremental update flow: 1. Detect changed files 2. Use SHA-256 hashing to identify affected dependencies 3. Re-parse only the changed files 4. Update the graph database
Incremental updates on a 2,900-file project take under 2 seconds.
Custom Language Support
code-review-graph supports 40+ programming languages (Python, JavaScript/TypeScript, Go, Rust, Java, C/C++, C#, Ruby, Kotlin, Swift, etc.).
If your project uses an unsupported language, you can customize it in .code-review-graph/languages.toml:
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]
Tree-sitter parsers handle the extraction automatically—no code changes needed. See docs/CUSTOM_LANGUAGES.md for details.
Uninstall
# Preview what will be removed
code-review-graph uninstall --dry-run
# Confirm and uninstall
code-review-graph uninstall
# Skip confirmation
code-review-graph uninstall --yes
# Clean up all repos
code-review-graph uninstall --all-repos
# Keep the graph database
code-review-graph uninstall --keep-data
Uninstall only removes code-review-graph-related files and configs. It won't touch other MCP servers or tools.
Performance Benchmarks
code-review-graph was benchmarked on 6 real open-source projects (13 commits):
| Project | Full Codebase Tokens | Graph Query Tokens | Reduction |
|---|---|---|---|
| FastAPI | 951,071 | 2,169 | 528.4× |
| code-review-graph | 208,821 | 2,495 | 93.0× |
| Gin | 166,868 | 1,990 | 91.8× |
| Flask | 125,022 | 1,986 | 71.4× |
| Express | 135,955 | 3,465 | 40.6× |
| httpx | 89,492 | 2,438 | 38.0× |
Median: 82× reduction
Note: The 528× figure is the best-case scenario (FastAPI, the largest codebase). It's not typical. Actual reduction depends on project size and query type.
Baseline comparison: The "full codebase" numbers above are a theoretical upper bound. In practice, AI tools use grep-style identifier searches and only read the most relevant matches. code-review-graph's advantages: - Precise dependency tracking (not just text matching) - Includes call chains, inheritance relationships, and test coverage - Incremental updates avoid re-parsing
When to Use It
Great Fit
- Large codebases: 1,000+ file projects—where token waste is most severe
- Frequent code reviews: Teams handling multiple PRs daily
- Monorepos: Ultra-large projects with 27,700+ files
- CI/CD integration: Automated code review gates
- Multi-language projects: Supports 40+ languages
Less Useful
- Small projects: Under 100 files—token costs are already low
- Pure front-end projects: Limited benefit without complex dependency chains
- Non-Git/SVN projects: Currently only Git and SVN are supported
Summary
code-review-graph tackles a core pain point in AI coding tools: wasted tokens. By building a code structure graph, AI tools can get precise context instead of re-reading the entire codebase.
Key advantages: - ✅ Save tokens: Median 82× reduction, lower API costs - ✅ Precise reviews: Tracks dependencies, no blind spots in impact scope - ✅ Local-first: Code never leaves your machine—secure and compliant - ✅ Incremental updates: Re-index large projects in under 2 seconds - ✅ Broad integration: Works with Claude Code, Cursor, Copilot, Gemini CLI, and more - ✅ GitHub Action: Automated PR review
Next steps: 1. Install code-review-graph on your project 2. Build the graph and experience the token savings 3. Integrate into your CI/CD for automated code review 4. Check the official docs for advanced usage
Project links: - GitHub: tirth8205/code-review-graph - Website: code-review-graph.com - Discord: Join the community
Further reading: - Claude Code with DeepSeek V4: Terminal AI Programming Guide - 2026 Terminal Emulator Showdown: Ghostty vs Tabby vs Alacritty vs Kitty - OpenCode: Open-Source Terminal AI Coding Agent Guide