Building a Local Code Knowledge Graph with code-review-graph for Claude Code
The article explains why AI coding tools need a persistent code map, describes how the open‑source code‑review‑graph parses a repository into a SQLite‑backed graph of functions, classes, imports and tests, and shows step‑by‑step how to expose this graph to Claude Code via MCP for faster, context‑aware code review.
Why AI needs a code map
Current AI coding assistants (e.g., Claude Code) can answer simple questions in small projects, but when a repository grows to thousands of files or becomes a monorepo the model must repeatedly read large portions of the codebase. This repeated scanning is slow, costly, and fragile because the AI lacks a stable, structured, reusable memory of the project.
Local knowledge graph + MCP
A local code knowledge graph abstracts the repository into nodes (functions, classes, imports, test functions, documentation, images) and edges (call relationships, inheritance, import links, test‑coverage links). The Model Context Protocol (MCP) exposes this graph to Claude Code, allowing the assistant to query the graph instead of raw files.
Local repository
↓
code-review-graph builds the graph
↓
Local graph data (SQLite)
↓
MCP server
↓
Claude Code queries nodes, relationships, impact rangeHow code-review-graph works
Running code-review-graph build first uses Tree-sitter to parse source code into an abstract syntax tree (AST). From the AST it extracts entities and relationships and stores them as graph nodes and edges.
Nodes : functions, classes, import statements, test functions, documentation files, images.
Edges : call relationships, inheritance, import dependencies, test‑coverage links.
For example, if function A calls function B, a call edge is created; if a test file covers a business function, a test‑coverage edge is added.
Local SQLite storage
The generated graph is stored in the project’s .code-review-graph/ directory using SQLite, so the code never leaves the developer’s machine. This design is important for private or sensitive codebases.
Blast‑radius analysis
The core capability of code-review-graph is blast‑radius analysis, which determines the minimal set of files affected by a change. The analysis proceeds in five steps:
Identify the changed files and functions.
Trace all callers of the changed functions.
Trace all dependencies of the changed functions.
Find related test files and test functions.
Compute the smallest affected file set.
The result is sent to Claude Code via MCP, allowing the assistant to work with a focused context instead of the entire repository.
Incremental updates
Full re‑indexing would be impractical, so the tool updates the graph incrementally. On each file save or Git commit it hashes the changed files (SHA‑256) and re‑parses only those files, updating related nodes locally. In practice, a project with 2,900 files can be re‑indexed in under 2 seconds , keeping the graph up‑to‑date without noticeable delay.
Quick‑start guide
Prerequisite : Python 3.10 or newer. python --version Install the tool with one of the following commands:
# Install with pip
pip install code-review-graph
# Or install in an isolated environment with pipx
pipx install code-review-graph
# Detect and configure supported AI platforms
code-review-graph install
# Build the graph for the current project
code-review-graph buildTo configure Claude Code exclusively, run:
code-review-graph install --platform claude-codeThis writes the MCP configuration to ~/.claude.json or .claude/settings.json. After restarting Claude Code you can ask questions such as:
If I modify the authentication module, which call paths are affected?CLI workflow
# Build the graph
code-review-graph build
# Incremental update (only changed files)
code-review-graph update
# Show graph statistics
code-review-graph status
# Watch mode – automatically update on file changes
code-review-graph watch
# Visualize the graph in various formats
code-review-graph visualize --format graphml
code-review-graph visualize --format svg
code-review-graph visualize --format obsidian
code-review-graph visualize --format cypher
# Detect change impact and risk score
code-review-graph detect-changes
# Start the MCP server
code-review-graph serveExcluding unwanted files
Generated code, third‑party libraries, or vendor directories can be excluded with a .code-review-graphignore file placed at the project root. Example content:
generated/**
*.generated.ts
vendor/**
node_modules/**If the project is a Git repository, code-review-graph automatically respects .gitignore and only indexes files reported by git ls-files.
Windows troubleshooting
A common error on Windows is:
Invalid JSON: EOF while parsing
MCP error -32000: Connection closedFour checks usually resolve the issue:
Ensure fastmcp version ≥ 3.2.4.
Avoid using a cmd /c wrapper in the MCP configuration.
Call the .exe directly.
Set the environment variable PYTHONUTF8=1.
Minimal MCP server configuration example:
{
"mcpServers": {
"code-review-graph": {
"command": "C:\\path\\to\\venv\\Scripts\\code-review-graph.exe",
"args": ["serve"],
"env": {"PYTHONUTF8": "1"}
}
}
}Multi‑repository and daemon mode
For teams maintaining several repositories, the daemon mode can manage all graphs centrally:
# Register repositories
crg-daemon add ~/project-a --alias proj-a
crg-daemon add ~/project-b
# Start the daemon
crg-daemon start
# Check status
crg-daemon status
# View logs for a specific repo
crg-daemon logs --repo proj-a -f
# Stop the daemon
crg-daemon stopSlash commands in Claude Code
/code-review-graph:build-graph– build or rebuild the code graph /code-review-graph:review-delta – review changes since the last commit /code-review-graph:review-pr – full PR review with blast‑radius analysis
MCP tools overview
get_minimal_context_tool– fetch minimal context for a query get_impact_radius_tool – compute the blast radius of a change get_review_context_tool – generate token‑optimized review context query_graph_tool – query callers, callees, tests, imports, inheritance detect_changes_tool – risk scoring and impact analysis semantic_search_nodes_tool – name or semantic search of code entities
Conclusion
AI coding assistants struggle with large codebases because they repeatedly read files, which is slow and expensive. A local, SQLite‑backed code knowledge graph provides stable, structured context that dramatically reduces the amount of code the model must ingest. For small scripts the overhead may not be worth it, but once a project reaches multiple modules and complex call chains, the graph’s benefits become evident.
GitHub repository: https://github.com/tirth8205/code-review-graph
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
