I've been using Claude Code for a while now. Undeniably powerful, but one thing has always bothered me: its粗暴 approach to reading files.
Ask it to modify a function, and it first reads the entire file. Upon discovering a dependency in another file, it reads that one too. After that, it realizes it needs to check a class definition, so it reads a third file.
A simple request ends up reading three or four files, with tokens flowing away like water. Coupled with OpenAI cutting three products in a week and Claude tightening usage limits again: Is the golden age of AI over?, the standard $20 official subscription often runs out after just a couple of tries.
This isn't really a flaw specific to Claude Code; it's a common ailment across all AI coding agents.
Agents lack the concept of browsing a directory structure. Their default behavior is: Uncertain? Read the file. Still uncertain? Read another one.
Recently, I discovered a tool called 'cx' specifically designed to address this issue. The results after using it have been impressive, so I'm sharing it with everyone.
Why do agents read so many files?
Let's first understand the root of the problem.
When a human programmer opens a new project, they first look at the directory structure, then search for a function name, jump to its definition, and a glance at a few lines is usually enough.
The entire process is highly precise; they don't read every single line of a file from start to finish.
AI agents cannot do this.
They have no editor, no Language Server Protocol (LSP), and their only means is "Read File."
As a result, the author of Cx analyzed data from 73 Claude Code sessions and found:
66% of reads were chained: reading A to find B, and reading B to find C. 37% were redundant reads, where the same file was read multiple times within a single session.
On average, each file read consumed about 1,200 tokens, with an average of 21 reads per session!
Just reading the code burned over 20,000 tokens per session before any actual work was done.
What is cx?
cx is a command-line tool written in Rust that performs semantic parsing based on tree-sitter. It provides agents with a "cost ladder":
cx overview src/fees.rs ~200 tokens What's in this file? cx definition --name calc ~200 tokens Show me this function cx symbols --kind fn ~70 tokens What functions exist in the whole project? cx references --name calc Very few Where is this symbol used? Compared to reading a medium-sized file directly, which costs 1,200 tokens, using cx overview costs only 200, and using cx definition to get the function body directly also costs just 200.
After adopting these tools, the agent first uses 'overview' to understand the structure, then uses 'definition' to precisely retrieve functions only when needed. In most cases, it no longer needs to read the full file.
Real-world testing shows 58% fewer Read calls and a 40-55% reduction in token usage.
Why not use LSP?
This is a reasonable question. Language Servers can also handle go-to-definition and find references, so why create a dedicated tool like cx?
Because LSP is designed for humans, not for agents.
LSP requires a continuously running background process, separate configuration for each language, often consumes 1-2GB of memory, and requires the project compilation index to complete before it can be used.
An agent might only need this once in a session; firing up such heavy machinery isn't worth it.
cx is stateless.
On its first run, it uses tree-sitter to parse all source files and builds a lightweight local index (.cx-index.db). Subsequently, it only incrementally updates changed files.
No background processes, no compilation dependencies, it works right out of the box.
How to install and integrate with Claude Code
Installation is simple:
curl -sL https://raw.githubusercontent.com/ind-igo/cx/master/install.sh | sh Or via Cargo:
cargo install cx-cli Then, provide an "instruction manual" for Claude Code:
cx skill > ~/.claude/CX.md Next, add a line to ~/.claude/CLAUDE.md:
@CX.md And you're done!
cx skill outputs a prompt telling Claude Code when to use cx overview, when to use cx definition, and under what circumstances a full file read is actually necessary.
After seeing this instruction, Claude Code will automatically prioritize cx commands over "Read File."
Install language support:
cx lang add rust typescript python cx will automatically detect which languages are used in the project. If the corresponding grammar isn't installed, it will prompt you.
How does it feel to use?
I tested it on a Rust project.
I asked Claude Code to help me refactor a module. Previously, it would read the entry file, then the dependency files, and only start writing code after reading several files.
Now, it first runs cx overview to see the overall structure. Once it finds the target function, it directly uses cx definition to get the function body. Basically, it starts working in just two steps.
The number of "Read File" calls in the conversation dropped significantly. Checking the token usage after the session finished confirmed a substantial decrease.
There are a few points to note: cx relies on tree-sitter for semantic parsing. Theoretically, it supports many languages, but you need to manually install the corresponding grammars.
The problem cx solves is very specific: providing AI agents with a code query interface that is cheaper than "reading the whole file." The tool itself isn't complex, integration is simple, but the results are tangible.
Project Address:
https://link.bytenote.net/msDCNa
The Next Code Paradigm Harness is Coming!
Implementing Active Message Push Based on WeChat OpenClaw Plugin