CODING AGENTS / AGENTS
How to Stop Your Coding Agent From Burning $50 in Tokens on a Single Bug
Techniques for AST indexing, language server protocol integration, and context boundaries that reduce AI token costs by up to 70%.
We have all experienced it: you ask your coding agent to fix a simple button color or update an API route, and five minutes later you notice it read 45 files, dumped entire node_modules packages into context, and burned $15 in token costs.
This happens because LLM agents default to brute-force directory traversal. Here is how to configure context boundaries, AST symbols, and Language Server Protocol (LSP) tools so your agent targets exact lines of code.
The Three Root Causes of Token Waste
- Unbounded Grepping: The agent searches for common variable names and reads 200 matches across build artifacts.
- Full File Dumps: Reading 1,200 lines of code just to inspect a 5-line type definition.
- Repeated Context Accumulation: Retaining multi-megabyte tool outputs across 20 turns of conversation.
The Solution: AST & LSP-Driven Codebase Exploration
Using tools like ctags, ripgrep with strict ignore patterns, or dedicated LSP servers, the agent can query symbol definitions directly:
# Instead of reading page.tsx completely, inspect symbols:
npx ast-grep --pattern 'export function $FUNC($$$) { $$$ }' src/app/page.tsxConfiguring Strict Ignore Patterns
Create a .claudeignore or .geminiignore file in your project root containing build caches, lockfiles, and media:
.next/
node_modules/
dist/
package-lock.json
*.svg
*.png
*.webpBy restricting agent access to source files only, you immediately eliminate up to 70% of unnecessary token consumption.
NEXT IN THE SERIES