Code-Review-Graph Cuts Claude Token Usage 8.2x with Local Knowledge Graph
A new open-source tool called 'code-review-graph' uses Tree-sitter to build a persistent structural map of a codebase, allowing AI coding assistants like Claude to read only relevant files and dramatically reduce token usage.
Why it matters
This tool represents a pragmatic, developer-side optimization strategy to address the central economic and technical constraint of large language models: context window limits and their associated costs.
Key Points
- 1Code-review-graph builds a local knowledge graph of a codebase using Tree-sitter, a robust incremental parsing library
- 2This allows the tool to identify only the specific files relevant to a developer's query, instead of processing the entire codebase
- 3Initial testing shows an average 8.2x reduction in tokens needed by Claude, and up to 49x reduction for certain daily coding tasks
- 4The tool also provides features like 'blast-radius' analysis to trace affected callers, dependents, and tests for safe refactoring
Details
Code-review-graph is an open-source tool that aims to address the inefficiency of AI coding assistants like Claude, which typically process large chunks of code through their context window, consuming expensive tokens on files that may be irrelevant to the task at hand. The tool uses Tree-sitter to build and maintain a structural map of the codebase, understanding relationships between files, functions, classes, and dependencies. When a developer asks Claude a question, the tool first queries its local graph to identify only the specific files that are directly relevant, and then feeds that subset to Claude, instead of the entire repository or a large, manually selected slice. Initial testing on six real-world repositories shows significant efficiency gains, with an average 8.2x reduction in tokens needed by Claude, and up to 49x reduction for certain daily coding tasks. The tool also provides features like 'blast-radius' analysis to trace every caller, dependent, and test affected by a proposed code change, a crucial feature for safe refactoring. The open-source nature of the tool and its editor-agnostic design make it accessible to developers and teams using paid, token-based AI coding assistants.
No comments yet
Be the first to comment