« All posts

Claude Code Review Token Bills Cut 8-49x With Tree-sitter Call Graphs

A Tree-sitter call-graph blast-radius technique cuts Claude Code review token bills 8-49x, plus three traps that can silently erase the savings.

Teams running Claude Code for automated PR review often feed the model the entire repository -- or rely on RAG, which misses actual call relationships -- driving token bills far higher than necessary. One engineer solved this by capping review context to nodes within two hops of the diff on a call graph, a 'blast radius' BFS borrowed from security terminology. Measured across twelve repos, the technique cut token usage between 8x and 49x, with the biggest wins on large monorepos paired with small diffs.

The call graph itself is built with Tree-sitter: parsing function definitions, call expressions, and imports into SQLite, with incremental re-indexing via file hashing keeping prep cost near-zero (a 2,900-file project indexes in under two seconds). But three traps can silently blow the savings back up to whole-repo scale: treating heavily-called utility functions as normal nodes, letting base-class methods pull in every subclass and its callers, and counting test files as callers. Left unchecked, these can expand a one-line change's blast radius to 1,200 files; with caps applied, that drops to 23.

A second, orthogonal distinction matters for review quality: functions 'reached' by a change on the call graph aren't the same as functions whose behavior actually changes. A signature-preserving internal refactor reaches its callers mechanically but doesn't alter their contract, warranting a lighter review pass -- an LLM-estimated 'behavior-change' set layered on top of the mechanical 'reach' set. The approach breaks down for cross-cutting concerns like logging and auth, config-driven dispatch that static analysis can't see, and first-time reviews of unfamiliar repos, where the blast-radius shortcut hides real risk instead of reducing noise.