代码审查图:持久化代码图,减少Claude代码令牌的使用。
嗨,HN,我是Tirth。我创建了code-review-graph,因为我厌倦了Claude Code在每个任务中都要重新阅读我的整个代码库。
当你请求Claude Code审查一个提交或添加一个功能时,它会读取文件以理解代码库。在一个小项目中,这样做是可以的。但在FastAPI(2,915个文件)或Next.js(27,732个文件)中,它会扫描成千上万与您的更改无关的文件。你为那些毫无价值的token付费,而更多的噪音只会让审查变得更糟。
code-review-graph使用Tree-sitter构建了一个持久的代码结构图。每个函数、类、导入、调用和继承关系都存储在本地的SQLite数据库中。当你编辑文件或提交时,它会在不到2秒的时间内重新解析仅更改的文件及其依赖项。然后,Claude查询图形,找出哪些内容发生了变化以及哪些依赖于它,并仅读取相关文件。
在真实提交的生产库上的基准测试结果:
• httpx(125个文件):减少26.2倍的token
• FastAPI(2,915个文件):减少8.1倍的token
• Next.js(27,732个文件):审查时减少6.0倍的token,在实时编码任务中减少49倍
• 审查质量:8.8分(满分10分)对比7.2分
一些技术细节:
• SQLite WAL模式支持并发读取,无需外部数据库
• 使用合格名称(src/auth.py::AuthService.login)避免节点身份冲突,无需作用域解析
• SHA-256哈希跳过:触及但未修改的文件将被完全跳过
• 可选的向量搜索以二进制大对象形式存储在同一个SQLite文件中,无需单独的向量数据库
• 使用NetworkX进行广度优先搜索图遍历,具有在写入时重建的缓存有向图
• 通过Tree-sitter支持12种语言:Python、TypeScript、JavaScript、Go、Rust、Java、C#、Ruby、Kotlin、Swift、PHP、C/C++
没有云服务。没有遥测。没有注册。只需在.code-review-graph/中有一个SQLite文件,仅此而已。PostEdit和PostGit钩子会自动保持图形的最新状态。你的工作流程不会改变。
设置大约需要30秒:
```
pip install code-review-graph
code-review-graph install
```
或者作为Claude Code插件:
```
claude plugin add tirth8205/code-review-graph
```
MIT许可证。大约3,700行类型化Python代码,包含770行测试。
GitHub: https://github.com/tirth8205/code-review-graph
PyPI: https://pypi.org/project/code-review-graph/
欢迎提问关于增量引擎、Tree-sitter集成或基准测试方法论的问题。
查看原文
Hi HN I'm Tirth. I built code-review-graph because I got tired of watching Claude Code re-read my entire codebase on every single task.<p>When you ask Claude Code to review a commit or add a feature, it reads files to understand the codebase. On a small project that's fine. On FastAPI (2,915 files) or Next.js (27,732 files) it scans thousands of files that have nothing to do with your change. You're paying for tokens that add zero value, and more noise makes the review worse.<p>code-review-graph builds a persistent structural map of your code using Tree-sitter. Every function, class, import, call, and inheritance relationship lives in a local SQLite database. When you edit a file or commit, it re-parses only the changed files and their dependants in under 2 seconds. Claude then queries the graph, finds what changed and what depends on it, and reads only the relevant files.<p>Benchmarks on production repos with real commits:<p>• httpx (125 files): 26.2x fewer tokens
• FastAPI (2,915 files): 8.1x fewer tokens
• Next.js (27,732 files): 6.0x fewer tokens on reviews, 49x on a live coding task
• Review quality: 8.8 vs 7.2 out of 10<p>Some technical details:<p>• SQLite WAL mode for concurrent reads, no external DB
• Qualified names (src/auth.py::AuthService.login) for collision-free node identity without scope resolution
• SHA-256 hash skip: files touched but not modified are skipped entirely
• Optional vector search stored as binary blobs in the same SQLite file, no separate vector DB
• NetworkX for BFS graph traversal with a cached directed graph that rebuilds on writes
• 12 languages via Tree-sitter: Python, TypeScript, JavaScript, Go, Rust, Java, C#, Ruby, Kotlin, Swift, PHP, C/C++<p>No cloud. No telemetry. No sign-ups. One SQLite file in .code-review-graph/ and that's it. PostEdit and PostGit hooks keep the graph current automatically. Your workflow doesn't change.<p>Setup takes about 30 seconds:<p><pre><code> pip install code-review-graph
code-review-graph install
</code></pre>
Or as a Claude Code plugin:
claude plugin add tirth8205/code-review-graph<p>MIT licence. Around 3,700 lines of typed Python with 770 lines of tests.<p>GitHub: https://github.com/tirth8205/code-review-graph
PyPI: https://pypi.org/project/code-review-graph/<p>Happy to answer questions about the incremental engine, the Tree-sitter integration, or the benchmark methodology.