Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Code-Review-Graph Cuts Claude Token Usage 8.2x with Local Knowledge Graph

Code-Review-Graph Cuts Claude Token Usage 8.2x with Local Knowledge Graph

A developer released 'code-review-graph,' an open-source tool that uses Tree-sitter to build a persistent structural map of a codebase. This allows Claude to read only relevant files, cutting average token usage by 8.2x across six real repositories.

GAla Smith & AI Research Desk·4h ago·7 min read·8 views·AI-Generated
Share:
Code-Review-Graph Cuts Claude Token Usage 8.2x with Local Knowledge Graph

A new open-source tool called code-review-graph promises to dramatically reduce the token consumption—and therefore the cost—of using AI coding assistants like Claude Code by building a local, persistent knowledge graph of a developer's entire codebase.

The core problem it solves is inefficiency. When an AI assistant like Claude analyzes a codebase to answer a question or suggest a change, it typically processes large chunks of code through its context window, consuming expensive tokens on files that may be irrelevant to the task. Code-review-graph acts as a pre-processor and intelligent indexer. It uses Tree-sitter, a robust incremental parsing library, to build and maintain a structural map of the codebase. This graph understands relationships between files, functions, classes, and dependencies.

When a developer asks Claude a question—for example, "What tests will break if I change this function?"—the tool first queries its local graph. It identifies only the specific files that are directly relevant: the function in question, its callers, its dependents, and the associated test files. It then feeds only that subset to Claude, instead of the entire repository or a large, manually selected slice.

What's New & Key Results

The tool is distributed as a 100% open-source project. According to the announcement, initial testing on six real-world repositories shows significant efficiency gains:

  • 8.2x Average Token Reduction: This is the headline figure, representing the average decrease in tokens Claude needed to process across the tested repos.
  • 49x Reduction on Daily Tasks: For certain routine, localized coding tasks, the token savings were even more extreme, reaching a 49x reduction.
  • Blast-Radius Analysis: The graph can trace every caller, dependent, and test affected by a proposed code change, a feature crucial for safe refactoring.
  • Incremental Updates: After the initial parse, the tool re-parses only changed files in under 2 seconds, keeping the knowledge graph up-to-date with minimal overhead.
  • Broad Editor Compatibility: It reportedly works out-of-the-box with AI-powered editors and IDEs including Claude Code, Cursor, Windsurf, and Zed.

How It Works: The Technical Approach

The architecture leans heavily on Tree-sitter, which is uniquely suited for this task. Tree-sitter can parse source code into concrete syntax trees (CSTs) quickly and, critically, incrementally. When a file changes, Tree-sitter can update its parse tree by re-processing only the modified sections, which is why code-review-graph can update its graph in seconds.

Here’s a simplified workflow:

  1. Initial Indexing: The tool scans the target codebase, using Tree-sitter parsers for each language to build syntax trees for every file.
  2. Graph Construction: It extracts key entities (functions, classes, methods, imports) and the relationships between them (calls, inherits from, contains). This data forms a knowledge graph stored locally.
  3. Query Interception: When a developer queries their AI assistant, code-review-graph intercepts the query (or the context being sent). It analyzes the query to determine the "code context" needed.
  4. Graph Query & Context Pruning: It queries its local graph to find all relevant files and code snippets. It assembles a minimal, focused context payload.
  5. AI Processing: This pruned context is sent to the AI model (e.g., Claude), drastically reducing the token count.
  6. Continuous Sync: As the developer edits code, the tool watches for file changes and triggers incremental Tree-sitter parses to update the graph.

What This Means in Practice

For developers and teams using paid, token-based AI coding assistants, this directly translates to cost savings and potentially faster response times (smaller context means less processing latency). It also enables more accurate "blast-radius" analysis for refactoring, as the AI can reason over a complete, accurate map of dependencies that might be too large to fit into a standard context window.

The open-source nature lowers the barrier to adoption, allowing developers to self-host and inspect the tool. Its editor-agnostic design means it can slot into existing workflows without forcing a switch to a specific editor.

gentic.news Analysis

This development is a direct, pragmatic response to the central economic and technical constraint of large language models: context window limits and their associated costs. While model providers like Anthropic and OpenAI compete on expanding context windows (Claude 3.5 Sonnet's 200K context, GPT-4o's 128K), this tool represents a developer-side optimization strategy. It acknowledges that throwing an entire massive codebase into a context window is often wasteful and expensive.

This aligns with a growing trend of "graph-augmented" AI tooling. We've covered similar approaches in research, such as knowledge graphs for improving RAG systems or enterprise search. However, code-review-graph is notable for applying this principle to the specific, high-frequency domain of software development and making it work locally and incrementally. It's less about giving the AI new knowledge and more about giving it a smarter, more efficient way to access the knowledge it already has (the codebase).

The use of Tree-sitter is a key technical insight. Its incremental parsing capability is what makes maintaining a live, up-to-date graph feasible for a dynamic codebase. A tool that required a full re-parse on every change would be too slow for daily use. This follows the broader industry pattern of moving complex processing to the edge—in this case, the developer's machine—to reduce latency, cost, and data privacy concerns associated with cloud APIs.

If the claimed 8.2x average token reduction holds in broader usage, it could significantly alter the cost-benefit calculation for teams considering enterprise-wide AI coding assistant licenses. The next step will be to see how the tool handles exceptionally large, polyglot codebases and whether its parsing accuracy matches the demands of complex refactoring tasks.

Frequently Asked Questions

How does code-review-graph connect to my editor?

The tool likely operates as a local server or background process that integrates with your editor via a plugin or extension. It monitors your project files, maintains the knowledge graph, and interfaces with your AI assistant's API or plugin to provide the pruned context before requests are sent to the cloud. The announcement states it works with Claude Code, Cursor, Windsurf, and Zed "out of the box," suggesting pre-built integrations or a compatible API.

Is my code sent to a third party when using this tool?

No. A core benefit of code-review-graph is that it runs locally on your machine. The knowledge graph is built and stored on your system. Only the final, minimized context you choose to send to your AI provider (e.g., Anthropic's Claude API) leaves your machine, and that is the same data that would be sent without the tool, just in a much smaller amount.

What programming languages does it support?

The support is determined by the underlying Tree-sitter library. Tree-sitter has robust, community-maintained parsers for a wide array of languages including JavaScript, TypeScript, Python, Go, Rust, Java, C++, and many more. The tool's language support will be as comprehensive as the available Tree-sitter grammars for your codebase.

Does this only work with Claude, or with other AI models too?

While the initial announcement highlights Claude Code, the tool's architecture is likely model-agnostic. It works by pruning the code context sent to any AI assistant. Therefore, it should be compatible with any coding assistant that allows you to provide context from your local files, including those powered by GPT-4o, Claude 3.5 Sonnet, or open-source models, as long as the editor integration can be configured to use the tool's output.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

The release of code-review-graph is a significant milestone in the practical application of AI to software engineering. It moves beyond the paradigm of simply feeding larger contexts to LLMs and instead introduces a structured, graph-based intermediary layer. This is conceptually similar to how a database index works: it doesn't change the data, but it makes querying it orders of magnitude more efficient. Technically, the choice of Tree-sitter is non-trivial and highlights the importance of incremental computation in developer tools. The 2-second update time is likely a key usability metric that separates a viable tool from a novelty. This development also implicitly critiques the current "chat-with-your-codebase" interface, suggesting that raw text context is a poor representation for the highly structured, relational data of a software project. From a market perspective, this creates an interesting dynamic. If such local optimization tools become widespread and effective, they could pressure AI coding assistant vendors to either lower prices (as token consumption drops) or to build similar proprietary graph-based indexing directly into their offerings. It represents a democratization of efficiency, shifting some leverage from the model provider back to the developer.
Enjoyed this article?
Share:

Related Articles

More in Products & Launches

View all