Graft just cut my Claude Code grep token usage by 42%
Graft fixes this by implementing hooks that optimize how the agent interacts with the file system. Instead of a raw grep that might return dozens of irrelevant lines, Graft filters the noise before the tokens even hit the LLM.
If you want to set this up to optimize your AI workflow, here is the basic logic for integrating hooks into your environment. While Graft handles this automatically, the manual logic for a custom implementation looks something like this:
# Example of a filtered grep hook to reduce token noise
grep -r "search_term" . | awk -F: '{print $1 " line " $2}' | head -n 20By limiting the output to just the filename and line number rather than the full line of code, the LLM can decide which specific file it actually needs to read. This turns a "shotgun approach" into a surgical strike.
How this changes the developer experience
When I started using these hooks, the most immediate difference wasn't just the token count, but the accuracy of the agent. When an LLM is flooded with 50 "near-matches" from a grep command, it sometimes gets distracted by irrelevant code patterns in the noise. By stripping that down to a clean list of locations, the agent stays focused on the actual logic.
For anyone building a custom LLM agent or trying to refine their prompt engineering for codebase navigation, here are a few practical tips to reduce token waste:
- Limit context windows: Don't let the agent read a 2,000-line file if it only needs one method. Use tools that allow line-range reading.
- Pre-index your symbols: If you can provide a
ctagsorLSPstyle index, the agent doesn't have to grep at all; it can just jump to the definition. - Filter by extension: Force your search hooks to ignore
.log,.json, or.lockfiles to avoid massive blocks of useless text.
For a real-world deployment, you can integrate these kinds of optimizations into your
.claudecode config or your shell aliases to ensure the agent is always using the most efficient path to the data. It's a simple tweak, but seeing a 40%+ drop in token usage makes it a mandatory part of a professional AI coding setup.