code-review-graph 透過結構化程式碼地圖,大幅降低 AI 程式開發的 token 消耗與雜訊
code-review-graph 透過結構化程式碼地圖,大幅降低 AI 程式開發的 token 消耗與雜訊。
code-review-graph 解決了現有 AI 程式開發工具在處理任務時,因重複讀取整個程式庫而導致的資源浪費與效能下降問題。透過建立本地結構化地圖,該工具能精準提供 AI 所需的上下文,顯著提升開發效率與程式碼審查品質。
核心痛點:現有的 AI 程式開發工具(如「Claude Code」)在執行任務時,往往會重複讀取整個程式庫,這不僅造成 token 的大量浪費,更會因為過多無關資訊產生「雜訊」。這導致 AI 陷入「迷失在中間」(lost in the middle) 的困境,即長上下文中的關鍵細節被忽略,進而降低審查品質。在像「Next.js」這種擁有 27,000 個檔案的專案中,這種低效的掃描方式尤為嚴重。
技術架構:該工具利用「Tree-sitter」將程式碼解析為節點(函數、類別、導入)與邊(呼叫、繼承、測試關係),並儲存於本地的「SQLite」資料庫中。
- 當程式碼發生變更時,系統僅會重新解析變更部分及其依賴項,整個流程在 2 秒內即可完成。
- 採用「SQLite」的 WAL 模式,無需外部資料庫,確保 100% 本地運行,無雲端依賴或遙測。
- 支援 19 種程式語言,並提供選擇性的向量搜尋功能,無需額外的向量資料庫。
實際影響:根據生產環境的基準測試,該工具在多個專案中展現了顯著的 token 節省效果,同時提升了審查品質:
- 在「Next.js」專案中,token 使用量減少了 49 倍。
- 在「FastAPI」專案中,減少了 8.1 倍。
- 在「httpx」專案中,減少了 26.2 倍。
- 審查品質評分從 7.2 分提升至 8.8 分(滿分 10 分),證明了減少無關資訊能讓 AI 更專注於關鍵變更。
整合與使用:該工具透過「MCP」(Model Context Protocol) 與多種 AI 開發工具(如「Cursor」、「Claude Code」、「Windsurf」等)整合。
- 安裝僅需 30 秒,透過
pip install code-review-graph即可啟用。 - 它提供「blast radius」(影響範圍)分析,確保 AI 僅讀取與變更相關的檔案,而非掃描整個專案,從而徹底改變了 AI 處理大型程式庫的方式。
🧵 I got tired of Claude Code re-reading my entire codebase on every single task.
— Tirth Kanani (@tirth_8205) March 9, 2026
So I built code-review-graph: a persistent structural map of your code that cuts token usage by 6.8x on average.
📉 49x reduction on monorepos.
🟢 Open source. Local-only. Zero cloud.
👉…
😤 The problem:
— Tirth Kanani (@tirth_8205) March 9, 2026
When you ask Claude Code to review a commit or build a feature, it reads files to understand your codebase.
On a 27,000-file repo like Next.js, that means scanning thousands of irrelevant files.
💸 You're burning tokens on code that has nothing to do with your…
⚡ code-review-graph parses your codebase once with Tree-sitter and builds a structural graph in a local SQLite database.
— Tirth Kanani (@tirth_8205) March 9, 2026
Every function, class, import, call, and test relationship. 12 languages.
When you edit a file, it re-parses only what changed and its dependants. Done in…
📊 Benchmarked on production repos with real commits:
— Tirth Kanani (@tirth_8205) March 9, 2026
🐍 httpx (125 files): 26.2x fewer tokens
⚡ FastAPI (2,915 files): 8.1x fewer tokens
▲ Next.js (27,732 files): 49x fewer tokens on coding tasks
And review quality went UP:
⭐ 8.8 vs 7.2 out of 10
More signal. Less noise.…
🔍 How it actually works:
— Tirth Kanani (@tirth_8205) March 9, 2026
1️⃣ Parse codebase into nodes and edges (functions, classes, imports, calls)
2️⃣ On edit or commit, re-parse only changed files and their dependants
3️⃣ Claude queries the graph to find the blast radius and dependencies
4️⃣ Reads only the relevant files…
🧠 Some tech decisions I'm proud of:
— Tirth Kanani (@tirth_8205) March 9, 2026
🗃️ SQLite WAL mode: concurrent reads, no external DB ever
🏷️ Qualified names (file::class.method): collision-free node identity
#️⃣ SHA-256 hash skip: touched but unchanged files aren't re-parsed
🔎 Optional vector search stored as SQLite…
⚙️ Setup takes 30 seconds:
— Tirth Kanani (@tirth_8205) March 9, 2026
pip install code-review-graph
code-review-graph install
Or: claude plugin add tirth8205/code-review-graph
🌐 Works with Python, TS, Go, Rust, Java, C#, Ruby, Kotlin, Swift, PHP, C/C++
📜 MIT licence
⭐ Star it, try it, break it:
👉…
But here’s what really surprised me:
— Tirth Kanani (@tirth_8205) March 9, 2026
It’s not just about saving tokens.
LLMs suffer from the “lost in the middle” effect. When context gets long, important details buried in the middle often get ignored, even if they’re critical.
On a 27k-file repo, you’re not just burning…
