代码审查图:持久化代码图,降低 Claude Code 的 token 使用量
2 分•作者: tirthkanani•5 个月前
嗨,HN!我是 Tirth。我开发了 code-review-graph,因为我厌倦了每次任务都看着 Claude Code 重新阅读我的整个代码库。<p>当你让 Claude Code 审查一个提交或添加一个功能时,它会读取文件来理解代码库。在一个小项目上,这没问题。但在 FastAPI (2,915 个文件) 或 Next.js (27,732 个文件) 上,它会扫描数千个与你的更改无关的文件。你为毫无价值的 token 付费,而且更多的噪音会让审查变得更糟。<p>code-review-graph 使用 Tree-sitter 构建一个持久的代码结构图。每个函数、类、导入、调用和继承关系都存储在本地 SQLite 数据库中。当你编辑一个文件或提交时,它会在 2 秒内仅重新解析已更改的文件及其依赖项。然后,Claude 查询该图,找到已更改的内容和依赖于它的内容,并仅读取相关文件。<p>在具有真实提交的生产仓库上的基准测试:<p>• httpx (125 个文件):减少 26.2 倍的 token
• FastAPI (2,915 个文件):减少 8.1 倍的 token
• Next.js (27,732 个文件):审查时减少 6.0 倍的 token,实时编码任务时减少 49 倍
• 审查质量:8.8 分 vs 7.2 分(满分 10 分)<p>一些技术细节:<p>• SQLite WAL 模式,用于并发读取,无需外部数据库
• 限定名称 (src/auth.py::AuthService.login),用于无冲突的节点标识,无需作用域解析
• SHA-256 哈希跳过:完全跳过已触及但未修改的文件
• 可选的向量搜索,作为二进制大对象存储在同一个 SQLite 文件中,无需单独的向量数据库
• NetworkX 用于 BFS 图遍历,带有在写入时重建的缓存有向图
• 通过 Tree-sitter 支持 12 种语言:Python、TypeScript、JavaScript、Go、Rust、Java、C#、Ruby、Kotlin、Swift、PHP、C/C++<p>无云服务。无遥测。无需注册。一个 SQLite 文件,位于 .code-review-graph/ 中,仅此而已。PostEdit 和 PostGit 钩子会自动保持图的最新状态。你的工作流程不会改变。<p>设置大约需要 30 秒:<p><pre><code> pip install code-review-graph
code-review-graph install
</code></pre>
或者作为 Claude Code 插件:
claude plugin add tirth8205/code-review-graph<p>MIT 许可证。大约 3,700 行带类型的 Python 代码,包含 770 行测试代码。<p>GitHub:https://github.com/tirth8205/code-review-graph
PyPI:https://pypi.org/project/code-review-graph/<p>很乐意回答关于增量引擎、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.