code-review-graph:给 AI 编程助手建一张本地代码关系图,中位数减少 65 倍 token 用量
code-review-graph: A Local Code Graph for AI Assistants That Cuts Token Use 65x at the Median
by Mycelium Protocol
AI 编程助手在做代码审查的时候有个根本问题:它不知道哪些文件和这次改动有关,所以要么读整个代码库(费 token),要么靠提示词猜(不准)。
code-review-graph 的解法是:在本地用 Tree-sitter 把代码库解析成一张关系图,记录函数之间的调用关系、类的继承关系、测试覆盖情况,存在 SQLite 里。代码审查时,MCP 工具查询这张图,计算出这次改动的”爆炸半径”(Blast Radius)——所有可能受影响的调用方、依赖方和测试——只把这个最小集合交给 AI 助手。
GitHub: https://github.com/tirth8205/code-review-graph | ⭐ 29,472 | Python | MIT
Token 减少了多少
六个真实开源仓库的基准测试(每个仓库 5 个样本问题,取均值):
| 仓库 | 全量 token | 图查询 token | 减少倍数 |
|---|---|---|---|
| fastapi | 948,793 | 2,653 | 375.6x |
| flask | 143,594 | 2,196 | 71.0x |
| code-review-graph 自身 | 208,821 | 3,190 | 68.1x |
| gin | 166,868 | 2,766 | 61.9x |
| httpx | 142,356 | 2,661 | 60.6x |
| express | 136,052 | 3,936 | 36.0x |
六个仓库中位数:约 65 倍。范围是 36x–376x,376x 是最佳单例(fastapi),不是典型值。
工作原理
代码库
↓ Tree-sitter 解析(函数/类/导入/调用/测试节点)
SQLite 关系图
↓ 提交 hook 或 watch mode 触发增量更新
图查询(Blast Radius 计算)
↓ MCP 工具
AI 助手只读受影响的最小文件集
- 构建关系图:解析所有源文件,提取函数、类、导入、调用关系、测试覆盖。
- 增量更新:文件保存或 commit 时,只重新解析 SHA-256 哈希变化的文件,3000 文件项目约 2.5 秒(其中 ~1.4 秒是进程启动开销)。
- Blast Radius:某文件改变时,图追踪所有调用方、依赖方和关联测试,计算最小必读集合。
- MCP 交付:通过标准 MCP 协议把结果交给 AI 助手;助手只读需要读的文件。
安装与使用
pip install code-review-graph # 或 pipx install code-review-graph
code-review-graph install # 自动检测已安装的 AI 平台并配置 MCP
code-review-graph build # 解析代码库,建图
install 会自动检测本机有哪些 AI 编程工具,为每个工具写入正确的 MCP 配置,并注入图感知指令。之后打开项目,在 AI 助手里说:
Build the code review graph for this project
支持 15+ AI 编程平台
自动检测并配置:Claude Code、Codex、Cursor、Windsurf、Zed、Continue、OpenCode、Gemini CLI、Antigravity、Kiro、Qwen、Qoder、GitHub Copilot(VS Code)、GitHub Copilot CLI、CodeBuddy Code。
可以单独指定平台:
code-review-graph install --platform claude-code
code-review-graph install --platform codex
code-review-graph install --platform cursor
支持 30+ 编程语言
Python、JavaScript/TypeScript/TSX、Go、Rust、Java、C/C++、C#、VB.NET、Ruby、Kotlin、Swift、PHP、Scala、Solidity、Dart、R、Perl、Lua/Luau、Objective-C、Shell、Elixir、Zig、PowerShell、Julia、GDScript、Nix、Verilog/SystemVerilog、SQL、Terraform/HCL、Ansible、Vue/Svelte SFC、Astro、Jupyter/Databricks Notebook(.ipynb)等。
需要额外语言可以在 .code-review-graph/languages.toml 里自定义配置:
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
GitHub Action(CI PR 审查)
在 CI 里对每个 PR 做 Blast Radius 分析,在 PR 页面自动评论风险评分和受影响的执行流,每次 push 更新评论(sticky comment)。代码图在 CI Runner 本地构建,源代码不发往外部服务。
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: tirth8205/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
可选 fail-on-risk 把审查结果变成合并门控。
Mycelium Protocol — 追踪 AI 系统的底层演化
关于 Mycelium
菌丝协议。持续追踪 AI 工具、系统和实验的内容节点。
code-review-graph: A Local Code Relationship Graph That Cuts AI Token Usage by 65× Median
by Mycelium Protocol
AI coding assistants have a fundamental problem on review tasks: they don’t know which files are relevant to a change, so they either read the whole codebase (expensive) or guess from the prompt (imprecise).
code-review-graph’s solution: parse the codebase locally with Tree-sitter into a relationship graph — functions, classes, call sites, imports, test coverage — stored in SQLite. At review time, an MCP tool queries this graph to compute the “blast radius” of the change: every caller, dependent, and test that could be affected. Only this minimal set goes to the AI assistant.
GitHub: https://github.com/tirth8205/code-review-graph | ⭐ 29,472 | Python | MIT
How Much Does It Help
Benchmarked across 6 real open-source repositories (5 sample questions each):
| Repo | Whole-corpus tokens | Graph tokens | Reduction |
|---|---|---|---|
| fastapi | 948,793 | 2,653 | 375.6× |
| flask | 143,594 | 2,196 | 71.0× |
| code-review-graph (self) | 208,821 | 3,190 | 68.1× |
| gin | 166,868 | 2,766 | 61.9× |
| httpx | 142,356 | 2,661 | 60.6× |
| express | 136,052 | 3,936 | 36.0× |
Median across 6 repos: ~65×. Range is 36×–376×; 376× is the single best case (fastapi), not the typical result.
How It Works
- Build the graph — Tree-sitter parses every source file into nodes (functions, classes, imports, calls, tests) and edges (call relationships, inheritance, test coverage), stored in SQLite.
- Incremental updates — On file save or commit hook, only files whose SHA-256 hash changed are re-parsed. On a ~3,000-file project, a 2-file edit re-indexes in about 2.5 seconds (of which ~1.4s is process startup).
- Blast radius — When a file changes, the graph traces every caller, dependent, and associated test to compute the minimal set the AI actually needs to read.
- MCP delivery — Results are delivered to the AI assistant via standard MCP protocol. The assistant reads only what matters.
Install
pip install code-review-graph # or: pipx install code-review-graph
code-review-graph install # auto-detects AI tools, writes MCP config for each
code-review-graph build # parse codebase and build graph
Then open your project and tell your AI assistant: Build the code review graph for this project
15+ Supported Platforms
Auto-detects and configures: Claude Code, Codex, Cursor, Windsurf, Zed, Continue, OpenCode, Gemini CLI, Antigravity, Kiro, Qwen, Qoder, GitHub Copilot, GitHub Copilot CLI, and CodeBuddy Code.
GitHub Action — CI PR Reviews
On each pull request, posts a sticky comment with risk-scored functions, affected execution flows, and test gaps — updated on every push. The graph is built on your CI runner; no source code leaves your environment.
- uses: tirth8205/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Optional fail-on-risk input turns the review into a merge gate.
Mycelium Protocol — tracking the deep evolution of AI systems
© 2026 Mycelium Protocol. All rights reserved.
关于本站 · 免责声明
🍄 Mushroom Research Blog 是非营利、免费公开的个人科技观察博客与公众号 XStack18,不接受商业合作、不代表任何企业或机构立场,也不谋求商业利益。我们以个人视角客观中立地记录和分析 AI、Web3 等领域的最新模型发布与技术动态——不止转述新闻标题或二手信息,而是给出有独立思考的深入分析,希望帮更多人获得有价值的一手科技认知。
⚠️ 文中介绍的开源代码与模型,仅供学习交流与技术借鉴。它们大多仍处于早期阶段,有待进一步研究和验证,请勿直接用于工作或生产环境;如需采用,请先自行充分测试,并核实其许可证与安全性。
Open-source code and models featured here are shared for learning and reference only. Most are early-stage and still need further study and verification — please don't use them directly in your work or in production. Test them thoroughly and check their licenses and security first.
- 本站文章均为作者基于公开信息的个人研究与观点整理,不代表文中提及的任何公司、产品、模型的官方立场,未与其构成商业关联或合作关系。
- 科技行业信息更新极快,我们尽力保证内容准确、及时,但不对完整性、实时性做绝对保证,具体请以相关企业/项目官方公告为准。
- 文中引用的第三方商标、产品名称、图片、数据等版权归原权利人所有,我们会尽量注明来源;如你认为存在版权疑问或侵权,请通过下方邮箱联系我们,收到通知后会尽快核实处理(更正、加注来源或删除)。
- 文章内容仅为技术科普与个人观点,不构成投资、法律或其他专业建议,据此进行任何决策的后果需自行判断和承担。
📮 侵权 / 勘误 / 合作咨询:[email protected]
💬 评论与讨论
使用 GitHub 账号登录后发表评论