How to Save 70% of Claude's Tokens with Targeted Code Access
A developer built a PHP + SQLite tool to make Claude Code more efficient on large projects. Two scripts, buildGraph and claudeSearch, build a dependency graph of the project and give the agent targeted access to code: a specific method, a class's fields, an inheritance chain, or the SQL queries touching a table. Instead of reading entire files, the approach saved 70% of the context window.
AI-processed from Habr AI; edited by Hamidun News
A developer has written a tool that saves 70% of Claude's context window on large projects. Instead of reading whole files, the AI agent gets targeted access to the code it needs, exactly what the task requires.
The problem: valuable context goes to waste
Claude Code knows the project's architecture from CLAUDE.md and understands which files are responsible for what. In practice, though, the agent still reads whole files. If it needs one method, it reads the entire class with all its methods. If it needs to find where a function is called, it reads directory after directory looking for patterns. The context melts away before any useful work has been done.
A typical scenario: a developer asks Claude to find a field in an entity. The agent opens the whole file, even though only the first 20 lines, with the field definitions and the constructor, are needed. Or, more simply: the task is to understand how database tables relate to each other. Claude reads entire SQL files, when table names and keys would have been enough to answer.
The context window is the main resource when working with AI on large projects. Out of 200K tokens, 100K can go to reading code that could have been obtained more cleverly.
The solution: a dependency graph and targeted access
The developer wrote two PHP scripts that work together:
buildGraph.php scans the project once and builds a dependency graph in SQLite. It parses PHP and JavaScript code and extracts classes, methods, functions, imports and inheritance chains. It runs incrementally: on subsequent runs it updates only the files that have changed. This takes 100–200 milliseconds for an average project.
claudeSearch.php is a CLI interface for agents. With a single command, it gives Claude exactly what it needs:
- A specific class method, with its signature and body
- All of a class's fields and its constructor
- The full inheritance chain for an entity
- All SQL queries that touch a given table
- A list of all calls to a function across the whole project
- Dependencies between modules
Instead of `Read(path/to/huge-file.php)`, Claude now writes `search("User", "fields")` and gets back 15 lines. Instead of reading three directories, it writes `search("saveOrder()", "calls")` and sees every place where that method is used.
Language support and speed
For now, the tool fully supports PHP and JavaScript. Go support has already been added. C will come later.
Parsing speed is critical: the graph must update at least as fast as the developer changes code. Incremental updating solves this. The first pass analyzes the whole project (which can take a few seconds on a large repo), and subsequent passes update only the changed files in 100–200 ms.
What it delivers in practice
According to the author's calculations, the tool cuts token consumption by 70% for a typical mid-sized project. That does not mean every individual request saves 70%. It means that over a single development session, the context is used three times more efficiently. Instead of spending 150K tokens on reading and then 50K on work, a developer can spend 70K on search and 80K on work.
The tool is especially useful for CLI assistants and bots that cannot see the file system themselves. For them, the graph becomes the source of truth about the project's structure.
What this means
The tool points in a direction: scaling work with Claude on large projects takes more than architectural decisions and a well-written CLAUDE.md. It requires intelligent access to code. Targeted reading instead of full reading. A graph instead of the file system. When context becomes the constraint, the agent should read based on what is actually needed, not on how much code there is.
- Nov 1, 2026Local models lose to Opus and Codex: 0.21 on a MacBook versus 1.00 for Codex
- Nov 1, 2026Kimi scores 96.2% on a 1C database analytics test and emerges as a fallback if Claude access is blocked
- Nov 1, 2026OpenAI Rewrites GPT Behavior Rules: Five Values and a Chain of Command
- Nov 1, 2026Google admits AI Mode cuts search revenue, shares fall 15%
Key Questions Answered
What are the key details on The problem: valuable context goes to waste?
Claude Code knows the project's architecture from CLAUDE.md and understands which files are responsible for what. In practice, though, the agent still reads whole files. If it needs one method, it reads the entire class with all its methods. If it needs to find where a function is called, it reads directory after directory looking for patterns. The context melts away before any useful work has been done. A typical scenario: a developer asks Claude to find a field in an entity. The agent opens the whole file, even though only the first 20 lines, with the field definitions an
What are the key details on The solution: a dependency graph and targeted access?
The developer wrote two PHP scripts that work together: buildGraph.php scans the project once and builds a dependency graph in SQLite. It parses PHP and JavaScript code and extracts classes, methods, functions, imports and inheritance chains. It runs incrementally: on subsequent runs it updates only the files that have changed. This takes 100–200 milliseconds for an average project. claudeSearch.php is a CLI interface for agents. With a single command, it gives Claude exactly what it needs: A specific class method, with its signature and body All of a class's fields and its
What are the key details on Language support and speed?
For now, the tool fully supports PHP and JavaScript. Go support has already been added. C will come later. Parsing speed is critical: the graph must update at least as fast as the developer changes code. Incremental updating solves this. The first pass analyzes the whole project (which can take a few seconds on a large repo), and subsequent passes update only the changed files in 100–200 ms.
Build & Ship Production AI Agents Without Boilerplate Code
Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.