code-review-graph is a local-first code-structure graph tool. It uses Tree-sitter to parse source code, writes calls, imports, inheritance, tests, and other relationships to a SQLite graph database inside the repository, and exposes structured context to Codex, Claude Code, and other tools through its CLI and MCP server.
Rather than “let AI automatically approve PR”, it solves the problem of reducing the cost of AI re-searching the entire repository for every review and helping reviewers locate cross-file calls, potential impact areas, and testing gaps. The final conclusion still comes back to Git diff, test results and human judgment.
Project address: tirth8205/code-review-graph
When is it worth using?
More suitable for:
- Repositories containing hundreds to thousands of files;
- monorepo or multilingual project;
- Frequently review cross-file and cross-module modifications;
- Need to track callers, dependencies, tests and execution flows;
- Want core graph data to stay local.
Not necessarily suitable for:
- Small projects with only a few files;
- Modifications are concentrated in a single independent file;
- Mainly review documents, configurations or pictures;
- The team is not prepared to maintain index freshness;
- One-time task, faster to read diff directly.
For a small diff, the graph query result may be larger than the original diff. Minimal context and change detection should be used first before deciding whether to expand the impact radius.
Working principle and data boundaries
The main process is:
|
|
Core composition and querying can be done locally, without requiring code to be uploaded to the cloud. Optional embeddings may use on-premises models or cloud providers; code shipping boundaries and team policies should be confirmed before enabling cloud embeddings.
In the Git repository, only tracked files returned by git ls-files are indexed by default. To exclude generated files or third-party code that are still tracked by Git, create in the repository root:
|
|
Graph databases are typically located at:
|
|
It is a rebuildable artifact and should not be submitted unconditionally to Git.
Prepare Python environment before installation
Project requirements Python 3.10 or higher:
|
|
It is recommended to use pipx to isolate the global CLI:
|
|
You can also install it directly:
|
|
Post-installation verification:
|
|
If the shell cannot find the command, first check whether the bin directory of Python Scripts or pipx has entered PATH. Do not repeatedly install multiple copies.
Configure MCP for Codex or Claude Code
The unified installation command will detect the installed platform:
|
|
Configure only Codex:
|
|
Configure only Claude Code:
|
|
The installer will write the corresponding MCP configuration and add hooks, skills or rule descriptions on supported platforms. Back up the existing configuration before execution and check the diff after execution to avoid accidentally overwriting team customizations.
Restart the AI tool when finished. Claude Code can check connectivity via /mcp; other clients should confirm that the code-review-graph server is connected and lists the tools.
Build the code graph for the first time
Enter the root directory of the repository to analyze:
|
|
status should at least show non-zero file, node, and edge counts, and record build branches and commits. If the node is zero, common reasons include:
- The current directory is not the target repository;
- The file is not tracked by Git;
- The extension is not recognized by the parser;
.code-review-graphignoreexcludes all content;- The build failed midway.
Before formal use, select a known function to test the structure query to confirm that the calling relationship can return to the real file.
Daily updates and change detection
Run incremental updates after code changes:
|
|
When concise output and context-saving information are needed:
|
|
update Update change files; detect-changes analyze current Git changes and impact. The two have different meanings, and you should not assume that the graph is up to date just because detect-changes works.
For long-term development, you can use:
|
|
However, in large repositories CPU, file listening caps, and generated directory noise should be observed; CI environments are generally better suited to explicit execution of build or update.
Let Codex or Claude Code review PR
After installing MCP and completing the composition, you can propose:
|
|
Projects also provide workflow templates, such as:
review_changes: Review current changes;architecture_map: Understand the architecture;debug_issue: troubleshoot along relationships;onboard_developer: Generate getting started context;pre_merge_check: Pre-merge check.
Whether using templates or free prompts, the order should be maintained:
- Confirm that the graph database is fresh;
- Read the actual Git diff;
- Query changed nodes;
- Expand callers, dependencies and tests;
- Run real tests;
- Manual review conclusion.
How to interpret Token savings
Currently CLI can display context saving panels in detect-changes --brief and update --brief. The default number is a project-defined estimate and does not equal the exact Token in the bill.
To use tokenizer cross-validation, you need to install additional dependencies and add --verify:
|
|
Record during assessment:
- Raw diff and repository size;
- The context length returned by the graph;
- The file that the AI actually continues to read;
- False negatives and false positives;
- Review takes time;
- Test whether any problems not shown in the picture are found.
Don’t apply the highest multiple from the official benchmark directly to the team budget. Small repositories, single file modifications, language parsing coverage, and questioning methods all change the results.
What the GitHub Actions example does
The following is a self-maintenance example compiled by this site, not the GitHub Action officially released by the project. It only installs CLI, restores the local map cache, performs incremental updates, and outputs reports. It does not automatically approve PR or write the results back to the comment area.
First create:
|
|
Example:
|
|
When enabling it for the first time, it is recommended to remove the cache step, confirm that the clean build is successful, and then add the cache. Caching is not a source of correctness; a complete rebuild should be allowed after changes to the parser, schema, or project structure.
Cache key and graph freshness
The example submits the PR baseline into the cache key in order to reduce the probability of directly reusing old images between different baselines. You can also add a summary of the dependency lock file:
|
|
The cache should be deleted and restarted in the following cases build:
- Upgrade code-review-graph or Tree-sitter parser;
- Modify exclusion rules;
- Massive directory renaming;
- Abnormal decline in graph statistics;
- Local and CI results cannot be reproduced;
- Schema or database compatibility changes.
The acceptance cache hit should not only check the Actions display cache-hit, but also check the branches, commits, number of files, number of nodes, and number of edges of status.
Permission boundaries for Fork PR
Core analysis only needs read access to the checked-out source code. It does not require repository write permission and should not use deployment secrets. Keep the following permissions:
|
|
Do not use pull_request_target on unreviewed Fork code to execute commands after checking out the PR head; this combination may expose underlying repository permissions or Secret.
If comments are to be automatically posted in the future, they should be broken into independent controlled steps and the report content, permissions and sources should be reviewed. The most secure first version only uploads artifacts for review by maintainers.
Monorepo and Big Changes
.code-review-graphignore can be used in a monorepo to exclude build directories and vendors that are explicitly not subject to review. Don’t exclude shared libraries for speed, otherwise the analysis will lose cross-package relationships.
Very large diffs should first obtain a list of files:
|
|
If the automatic detection of MCP does not respond for a long time, you can pass a clear list of changed files to the impact analysis tool to avoid repeated execution of Git detection with an excessive scope on the backend.
The project also provides boundary environment variables for limiting very large fronts, such as CRG_MAX_CHANGED_FUNCS, CRG_MAX_TRANSITIVE_FRONTIER, and CRG_TOOL_TIMEOUT. Record the default behavior before adjusting. Limits that are too low will reduce recalls.
Troubleshoot Windows MCP connection failures and stalls
CLI is normal but MCP reports Invalid JSON: EOF while parsing or Connection closed:
- Upgrade code-review-graph;
- Execute
installagain to update the configuration; - Confirm that version FastMCP meets the current requirements of the project;
- Let MCP directly execute
.exein the virtual environment; - Set
PYTHONUTF8=1; - Restart the client and view the MCP log.
Schematic configuration:
|
|
CLI’s status and detect-changes are very fast, but when the MCP call times out, the result of git diff --name-only is first explicitly passed to the tool to distinguish between the slow change detection of Git and the slow graph query.
How to recover when graph data is wrong
Record the scene first:
|
|
Then perform an incremental update:
|
|
If the result is still incorrect, back up or remove the rebuildable .code-review-graph directory and perform a full build. Before removal, confirm that the directory is inside the intended repository so that unrelated data is not deleted.
This should also be re-run after upgrading:
|
|
install is used to refresh the platform configuration, and build is used to refresh the graph data. Do not confuse the two steps.
Uninstall and rollback
Preview first:
|
|
Uninstall after confirmation:
|
|
Only remove the integration and keep the graph data:
|
|
Then check whether there are any remaining MCP items in the Codex, Claude Code and other configurations, and confirm that the original configuration backup can be restored.
Final acceptance checklist
|
|
Summary
code-review-graph works as a structural index for AI-assisted code review, not as an automated approver. A reliable workflow is to build the graph in the correct repository, keep it incrementally updated, retrieve only the necessary context through MCP, and confirm conclusions with the Git diff, tests, and human review.
When accessing GitHub Actions, you should first ensure that the clean build is reproducible, and then gradually add cache and artifacts. Permissions remain read-only, Fork PR does not use Secret, and being able to fall back to a normal diff and full rebuild when the graph fails is more important than chasing the highest Token savings in a single benchmark.