Claude Code Agent Token Waste Fix
Disclosure: This post may contain affiliate links. If you purchase through these links, we may earn a small commission at no extra cost to you.
Claude Code agents burn through tokens fast. Developers report costs of $13 per active day and sessions that chew up 12,000 tokens to answer questions that should take 800.
The primary fix for Claude Code token waste is symbol-level code retrieval instead of file-granular reads, combined with aggressive context hygiene and prompt caching-changes that typically reduce token consumption by 70-90% per session.
This waste is mechanical: agents read entire 500-line files to extract single functions, re-bill that content on every turn, and revisit code they've already examined.
Most Claude token waste comes from five predictable patterns: cache misses, context bloat, and oversized model usage top the list.
The problem compounds in longer sessions. Every file the agent reads stays in the context window and gets billed again with each message.
If you know where your token usage actually goes-and which fixes deliver measurable results-you can optimize instead of guess.
Solutions range from simple habit changes like .claudeignore files and clearing context between tasks, to architectural shifts involving code graphs and retrieval systems.
I'll walk through proven techniques at each level: prompt design, caching strategies, tool configuration, and automated monitoring that shows exactly how many tokens you're saving.
Understanding Token Waste in Claude Code Agents
Claude Code agents consume tokens through three primary channels: file reads and context loading, command execution and output, and conversational exchanges.
The way tokens accumulate across sessions directly impacts both cost and performance.
How Tokens Are Consumed in AI Workflows
Every interaction with Claude Code costs tokens. When you ask Claude to fix a bug or implement a feature, it reads files to understand context.
Each file read counts toward token usage, even if the information isn't useful.
Command execution adds another layer. When Claude runs tests, checks logs, or executes build commands, the full output enters the context window.
A verbose test suite or lengthy git log can consume thousands of tokens in a single operation.
Re-reading files is the biggest source of waste-often 40-60% of Read tokens. Claude reads a file, makes changes, then reads it again to verify.
It repeats this process when working on related files, billing full token counts for each read.
Project exploration without boundaries compounds the problem. Without a .claudeignore file, Claude indexes build artifacts, lock files, and dependencies you never intended it to access.
The Impact of Context Window and Session Length
Context windows have finite capacity. As conversations extend, earlier exchanges drop out of Claude's working memory.
Sessions that run too long fill the context window and cause forgetting, but starting fresh means Claude re-learns your project from scratch.
Session structure directly affects token efficiency. One logical task per session-a single bug fix, feature, or refactor-optimizes both context retention and cost.
Trying multiple unrelated tasks in one conversation forces Claude to maintain competing contexts.
Long sessions increase the likelihood of redundant operations. Claude may re-explore code sections it examined earlier, spending tokens to rediscover information already in the session history.
Token Breakdown: Input vs Output vs Memory
Input tokens are everything Claude receives: prompts, file contents, command outputs, and maintained context.
These typically make up the largest portion of token usage in development workflows.
Output tokens cover Claude's responses, code generations, and explanations. You can reduce these through compact mode or by requesting concise responses when detailed reasoning isn't necessary.
Memory tokens include persistent context like CLAUDE.md files that load at session start.
Every token in these configuration files consumes resources every session. Bloated setup files with excessive history or redundant documentation waste tokens before real work begins.
The pattern: input tokens from file reads dominate, followed by conversational exchanges, then output generation.
Core Causes of Excessive Token Consumption
Claude Code's token consumption has increased significantly. Users report that token usage drains several times faster since March 2026.
The primary drivers: repetitive file operations, poor context management, and inefficient plugin configurations that inflate both input and output tokens.
Repeated File Reads and Command Outputs
Claude Code re-reads the same files multiple times during a session, consuming token volume with duplicate content.
Each file read counts toward input tokens. When the agent requests the same documentation or source code repeatedly, you're paying multiple times for identical information.
Command outputs are similar. When you run terminal commands through Claude Code, the full output gets included in the context window.
Long compilation logs, verbose test results, or directory listings with hundreds of files contribute to token waste.
The agent doesn't filter or truncate these outputs, so a single command can consume thousands of tokens even when only a few lines matter.
Recent updates have made token consumption disproportionately high. Tasks that previously used reasonable amounts now exhaust daily budgets rapidly.
This suggests the platform may have changed how it handles file reads and command results.
Irrelevant or Bloated Context Retention
The context window in Claude Code doesn't automatically prune irrelevant information as sessions progress.
The agent often carries forward entire conversation histories, including exploratory questions, false starts, and resolved issues that no longer matter.
This bloat compounds in longer sessions. What starts as a focused 5,000-token conversation can balloon to 50,000 tokens as the agent retains every intermediate step.
Documentation snippets, API responses, and error messages from hours ago remain in context even when you've moved to different tasks.
Plugin outputs and tool responses add more layers. When multiple plugins are active, each tool invocation and response stays in the context unless you explicitly clear it.
This creates a situation where token costs compound exponentially in long conversations, making extended sessions impractical.
Inefficient Tool Definitions and Plugins
Tool definitions consume tokens every time Claude Code considers which tools to use.
Poorly designed plugins with verbose descriptions, excessive parameters, or redundant capabilities force the agent to process more text with each decision.
Some plugins generate unnecessarily detailed outputs. Instead of concise, structured data, they produce lengthy explanations or include metadata that inflates token costs without adding value.
With multiple overlapping plugins enabled, the agent evaluates all of them repeatedly, even if most aren't relevant to the current task.
MCP (Model Context Protocol) overhead is particularly problematic. The protocol layer adds its own token consumption on top of plugin functionality.
Techniques exist to control MCP overhead specifically to address this issue.
Prompt Optimization and Stable Prefix Techniques
Reducing token waste in Claude Code starts with structuring prompts to maximize cache hits and minimize unnecessary context.
Strategic use of ignore files, consistent prefix ordering, and precise prompting cut costs by preventing cache invalidation and limiting what enters the context window.
Effective Use of .claudeignore
The .claudeignore file controls which files Claude Code can access during a session.
By excluding irrelevant directories like node_modules, .git, build, dist, and coverage, you prevent thousands of unnecessary tokens from entering the context window.
Add patterns for log files, temporary files, and large data files that don't inform coding decisions.
Each excluded file type reduces both the initial context load and the risk of accidental reads during tool use.
Common .claudeignore patterns:
node_modules/.git/*.logbuild/anddist/.envand.env.**.pycand__pycache__/
The file works like .gitignore but for Claude Code's file system access.
When properly configured, it can reduce context size by 40-60% in typical projects.
Maintaining Stable Prompt Prefixes
Prompt caching in Claude Code requires stable prefixes to achieve cache hits.
The cached portion includes system instructions, CLAUDE.md content, and MCP tool definitions.
Any change to these elements invalidates the entire cache.
Put volatile content after the cached prefix boundary. Model-specific instructions, temporary notes, and session-specific context should appear in user messages, not system instructions.
Switching between Claude models mid-session breaks the cache. Each model has different system prompts.
Staying on a single model tier throughout a session preserves cache hits and reduces token costs by up to 90% on cached content.
Cache-breaking actions to avoid:
- Editing CLAUDE.md during active sessions
- Adding or removing MCP servers mid-session
- Switching between Opus, Sonnet, and Haiku
- Modifying skill definitions between prompts
Specific Prompting to Minimize Context Load
Precise prompts prevent unnecessary file reads and reduce the scope of Claude's tool use.
Instead of "fix the login bug," specify "check authentication logic in src/auth/login.ts lines 45-67."
File-specific requests eliminate exploratory reads. When you reference exact paths and line numbers, Claude doesn't need to search the codebase or read multiple files to understand the task context.
Breaking large tasks into focused subtasks reduces peak token usage.
Rather than "refactor the entire payment module," request specific changes to individual functions across multiple prompts.
This keeps each interaction lean while maintaining progress.
Scoped prompts consistently outperform broad requests on cost efficiency.
Avoiding Volatile Content in Prompts
Dynamic elements in prompts invalidate caching and increase costs.
Timestamps, session IDs, random examples, and frequently changing metrics should stay out of system instructions and CLAUDE.md files.
Separate static guidelines from dynamic information.
Project standards, coding conventions, and architectural decisions belong in cached prefix content.
Current task details, debug output, and temporary constraints fit better in individual user messages.
Even small edits to prefix content force full cache rewrites. A single character change in CLAUDE.md can cost thousands of tokens on the next prompt.
Keep configuration files stable across sessions. You pay cache-write rates once and benefit from cache-read rates (90% cheaper) on every subsequent prompt until the cache expires.
Leveraging Prompt Caching and Session Management
Prompt caching automatically reuses previously processed content instead of recomputing it on every turn.
Strategic session management ensures you maintain high cache hit rates throughout long development workflows.
Understanding cache reads versus writes reveals where your token costs actually accumulate.
How Prompt Caching Reduces Token Waste
Prompt caching works by matching the prefix of each request against content Claude Code recently processed.
When you send a new message, the system re-sends the full context: system prompts, project files, and conversation history.
Without caching, every turn would reprocess this entire payload.
The cache stores content in layers that change at different frequencies.
System prompts and tool definitions rarely change between turns.
Project context from CLAUDE.md and memory updates only at session start.
Conversation messages change every turn but build on the cached foundation.
Cache-friendly actions append new content without disturbing what's already cached.
When you invoke skills, run commands, or let Claude read files, these operations add to the conversation end.
The existing prefix remains intact and cache hits continue.
Cache-breaking actions force complete reprocessing.
Switching models invalidates the entire cache because each model maintains separate cache entries.
Changing effort levels mid-session triggers the same penalty since effort is part of the cache key.
Boosting Cache Hit Rate Through Session Design
You maximize cache hits by keeping your session structure stable.
The most impactful practice: avoid model switches during active work.
When you toggle between Opus and Sonnet, the next request reads your entire conversation history with zero cache benefit.
Session stability practices:
- Start sessions with the correct model and effort level selected
- Keep MCP servers connected throughout the session rather than toggling them
- Avoid editing CLAUDE.md mid-session; changes only apply after restart anyway
- Use
/rewindinstead of/clearwhen you need to backtrack
The Claude Code team monitors cache hit rate the same way most teams monitor uptime.
When cache performance drops, you're paying full price for content you've already processed.
Long sessions naturally accumulate more cached content, making cache preservation increasingly valuable as conversations extend.
Tool loading strategy affects cache stability.
When tools defer through tool search, connecting or disconnecting MCP servers appends new content without breaking your prefix.
When tools load upfront, any server change invalidates everything.
Cache Reads vs Cache Writes: Billing Implications
Cache reads cost significantly less than cache writes. When Claude Code sends a request, any portion matching our cached prefix bills as a cache read at roughly 90% discount.
New content and anything after a cache break bills as a cache write at standard rates. A typical turn in a long session might process 50,000 cached tokens as reads and 500 new tokens as writes.
The cached portion costs a fraction of reprocessing. When we break the cache by switching models, those 50,000 tokens shift from discounted reads to full-price writes.
Token cost comparison:
| Scenario | Cache Reads | Cache Writes | Relative Cost |
|---|---|---|---|
| Normal turn | 50,000 | 500 | 1× baseline |
| After model switch | 0 | 50,500 | ~10× baseline |
| After compaction | 0 | 5,000 | ~2× baseline |
Compaction reduces conversation length but rebuilds the cache at that point. The summary generation itself reads from our existing cache, so we're not reprocessing during summarization.
The post-compaction turn writes a shorter history, making subsequent turns cheaper overall.
Optimizing Tool Use and MCP Server Connections
MCP servers consume tokens by loading tool schemas into every conversation, whether we use them or not. Some configurations cost over 6,500 tokens per turn.
We can reduce this overhead through strategic tool management, selective server activation, and disciplined plugin use.
Managing Tool Schemas and Definitions
Tool definitions represent one of the largest sources of hidden token consumption in Claude Code sessions. When we connect an MCP server, its entire schema loads into context automatically.
The Model Context Protocol exposes all available tools upfront. A Linear MCP server with 31 tools consumes approximately 3,000 tokens per conversation, even when idle.
A GitHub server adds another 2,000+ tokens. These costs accumulate across every message in our session.
We should audit which tools actually get used versus those that sit dormant. Removing unused tool schemas or switching to on-demand alternatives improves cache hit rate and reduces baseline token overhead for model routing decisions.
| Server Type | Tool Count | Idle Token Cost |
|---|---|---|
| Linear MCP | 31 tools | ~3,000 tokens |
| GitHub MCP | 20+ tools | ~2,000 tokens |
| Combined (3 servers) | 50+ tools | ~6,500 tokens |
Selective Activation of MCP Servers
We don't need every MCP server active for every project. Global configurations that make sense for our entire development environment often create unnecessary overhead for specific work sessions.
Project-scoped configurations solve this problem. We can create a project-local .mcp.json file that activates only the servers relevant to our current work.
A frontend project rarely needs database migration tools. A documentation update doesn't require deployment management capabilities.
Tools for optimizing MCP optimization help us analyze actual server usage patterns and generate minimal configurations. We should evaluate each server's relevance before including it in our project scope.
This selective approach can reduce per-session token consumption by 60-80% while maintaining full functionality for project-specific needs.
Plugin and Subagent Discipline
Plugins and subagents extend Claude Code capabilities but introduce their own token overhead. Each active plugin loads its command definitions and schemas into our working context.
We should enable plugins only when their functionality directly supports our current workflow. Development plugins make sense during coding sessions but waste tokens during documentation or planning work.
Subagents should launch on-demand rather than persist across unrelated tasks. Plugins typically expose commands we invoke explicitly, while MCP servers load tool schemas preemptively.
Both consume tokens, but plugins offer more granular control over when that consumption occurs. We should regularly review our active plugins and disable those not immediately necessary for our current project phase.
Strategies to Control Session and Output Size
Long sessions accumulate context that gets re-read on every message. Unconstrained output generates tokens whether you need them or not.
Session-level compression and output-level controls work together to keep token volume manageable.
Session Compaction Methods and Hooks
Session hooks and tiered documentation can optimize Claude Code context by 60% by intercepting context before it bloats. Hooks let us inject compression logic at specific points in the conversation lifecycle.
PreToolUse hooks rewrite commands before execution. A bash command that would dump thousands of tokens gets filtered to essentials before the output enters context.
PostToolUse hooks process results after execution but before Claude sees them, allowing us to summarize or truncate large responses. We can implement custom hooks that detect when context exceeds a threshold and automatically trigger compaction.
The hook checks message count or token estimates, then runs a compaction routine that preserves only the essential context needed for the current task. RTK (Rust Token Killer) provides a PreToolUse implementation specifically for bash output, compressing common development commands by 60-90% before they reach the conversation.
Using /compact, /clear, and Related Commands
/compact and /clear serve different purposes. /compact summarizes the conversation and restarts from that summary, preserving the thread while reducing context weight.
We use this when the session is long but we still need what happened. /clear wipes everything and starts fresh.
We use /clear when switching to a completely different task where prior context adds no value.
When to use each:
- Use
/compact: Debugging session hits 40 messages but we still need the error pattern - Use
/clear: Switching from database work to UI components - Use
/clear: Previous topic is irrelevant to the next task
On Claude Desktop and the web interface, we don't have a /compact equivalent. Our only option is starting a new chat, which functions like /clear.
This makes one topic per chat essential for avoiding invisible context waste on those platforms.
Tracking Token Volume Across Sessions
We can't optimize what we don't measure. Token tracking shows us which sessions burn budget and which patterns cause it.
Claude Code doesn't expose real-time token counts in the interface. We can use external tools.
Claude-hud monitors token usage during active sessions and displays running totals. We install it as an MCP server and it tracks both input and output tokens as the conversation progresses.
For historical analysis, we export conversation logs and parse them with token counting utilities. This reveals patterns like which file types cost the most when loaded, which MCP servers return the largest responses, and how session length correlates with total cost.
Key metrics to track:
- Average tokens per message over time
- Token cost by file type when using read_file
- MCP server output volume by server type
- Session length vs. total token consumption
We review these weekly to identify which optimization delivered real savings and which workflows still need adjustment.
Coding Agents: Output Shortening and Summarization
Claude generates wasteful output by default, opening with "Sure!" and closing with "I hope this helps!" Every repeated pleasantry costs output tokens across hundreds of messages.
We control this in our instruction file (CLAUDE.md or project-level config). Direct instructions that specify output format eliminate filler.
- No greetings or sign-offs
- Code blocks only, no explanations unless asked
- Use plain ASCII, no Unicode decorators
- Respond with just the answer
For tasks that need structured output, we specify exact formats. "Return as JSON with these three fields" produces predictable, parseable responses without extra commentary.
We also set output token budgets explicitly when the task allows it. If we need a yes/no answer, we can constrain the response to under 50 tokens.
For code generation where we know the scope, setting a 500-token cap prevents Claude from over-explaining. The /effort command in Claude Code controls extended thinking output tokens.
/effort low limits reasoning tokens for simple tasks that don't require deep analysis. This prevents the default budget from running into tens of thousands of tokens on straightforward requests.
Automated Tools and Monitoring for Token Efficiency
Several plugins and dashboards now exist to track token consumption patterns and automate optimization decisions. These tools provide real-time breakdowns of where tokens are being spent and can route requests to more efficient models based on task complexity.
Token Optimizer, RTK, and Related Plugins
The claude-token-efficient repository includes two browser-based diagnostic tools: Token Checkup and Cache Health Checker.
Token Checkup is a 5-question tool that analyzes consumption patterns and suggests optimizations. Cache Health Checker examines /cost output to verify if prompt caching is functioning properly.
We can implement CLAUDE.md files that enforce output constraints automatically. Benchmarked configurations show cost reductions of 17.4% when using the v8 config across three coding challenges.
The M-drona23-v8 profile uses only 7 lines across 2 files and restricts tool budgets to 20 calls per session. Alternative approaches include the Antigravity Protocol and Ultimate Protocol Simulator, which use structured planning and JSON-only compiler modes to reduce context window usage.
Superpowers plugin showed 9% cheaper runs and 14% fewer tokens across 12 automated sessions.
Real-Time Token Audits and Cost Reports
We need visibility into token breakdowns before optimization is possible. The /cost command in Claude Code provides session-level data, but third-party tools offer more granular analysis.
MCP response analyzers help identify when Model Context Protocol calls consume excessive tokens.
These custom skills parse large responses and flag inefficient data transfers that accumulate over long sessions. Dashboard tools track token volume across multiple projects.
For automation pipelines processing 1,000 prompts daily, we can expect to save approximately 96,000 tokens per day according to scaling calculations, translating to $8.64 monthly on Sonnet pricing.
Optimizing with Model Routing and Skills
Model routing directs simple queries to Haiku while reserving Sonnet and Opus for complex tasks. Tested routing strategies combined with MCP caching reduced token costs by 20-43% across different workflows.
Skills enable context-aware task handling without rebuilding instructions. We can create reusable skills for common patterns like code review or debugging that include optimization rules.
The /effort command lets us specify task complexity upfront, helping the model allocate appropriate context and avoid over-engineering. Path-scoped rules apply different optimization levels to specific directories.
Verified benchmarks show that combining path scoping with model routing achieves 77-91% token reduction on repetitive tasks.
Advanced Approaches: RAG, Context-Mode, and AI Agent Architectures
Strategic implementation of RAG systems, context management techniques, and multi-agent patterns can reduce token consumption by 70-90% while maintaining or improving output quality.
These approaches address the core problem that multi-agent systems use about 15× more tokens than chats.
Retrieval-Augmented Generation (RAG) Integration
We implement RAG to compress large codebases into relevant context chunks instead of feeding entire files to agents. Modern RAG architectures have evolved beyond basic vector search to include hybrid search with reranking.
This combines semantic similarity with keyword matching for better precision. The key to token reduction lies in compression ratios.
Instead of loading 50,000 tokens of documentation, we retrieve only the 2,000 most relevant tokens. This requires proper chunking strategies.
We typically use 500-1000 token chunks with 100-200 token overlap to maintain context continuity. For coding agents specifically, we apply multimodal RAG-driven approaches that index code structure, function signatures, and dependency graphs separately.
This enables more precise retrieval when agents need to understand relationships between modules.
Implementation priorities:
- Use hybrid search (vector + keyword) for 30-40% better retrieval accuracy
- Implement reranking to filter retrieved chunks before feeding to the LLM
- Cache frequently accessed embeddings to reduce preprocessing overhead
- Set strict retrieval limits (top 3-5 chunks) to prevent context bloat
Context-Mode and Memory Management
We manage agent memory through two approaches: persistent memory via RAG and ephemeral memory via context windows. RAG versus context engineering is a tradeoff between storage costs and token costs.
Context-mode optimization is about what stays in the active window. I remove redundant information, compress previous turns into summaries, and keep only decision-critical context.
Instead of full API responses from 10 tool calls, I extract and store only the actionable data.
Memory compression techniques I use:
- Sliding window summarization: Compress conversations older than 5-10 turns into brief summaries.
- Selective retention: Keep only error messages, user corrections, and key decisions.
- State extraction: Replace verbose outputs with structured state objects-JSON, not prose.
I also use prompt caching. By making system instructions and tool definitions static across calls, I cache up to 80% of prompt tokens.
This is effective with coding agents that use consistent tool sets across multiple interactions.
The context window is working memory, not long-term storage. I offload historical context to RAG and retrieve it only when it's relevant.
Design Patterns with Coding and AI Agents
I structure coding agents using orchestrator-worker patterns. A lead agent coordinates specialized subagents.
This multi-agent architecture prevents token waste. Each subagent gets narrow, well-defined responsibilities with separate context windows.
Critical design patterns:
- Task decomposition: Break large coding tasks into 3-5 independent subtasks. Subagents handle these in parallel.
- Bounded tool calls: Limit each subagent to 3-10 tool calls. This prevents runaway exploration.
- Explicit output contracts: Define exact output formats. Subagents return only required information.
For agents.md configurations, specify when agents should spawn subagents versus handle tasks directly. Simple refactoring or single-file edits stay with the lead agent. This avoids the 4× token overhead.
Complex tasks like codebase-wide migrations justify the 15× token cost. Parallel execution pays off here.
Effort scaling rules go directly into prompts. A function rename uses 1 agent with 3-5 calls.
A feature implementation spanning 5-10 files uses 2-4 subagents with 10-15 calls each. Major refactors use specialized subagents for analysis, modification, and testing.
Token-efficient cowork patterns:
- Agents share compressed findings (bullet points), not full logs.
- Use structured formats-tables, lists-for inter-agent communication.
- Implement early termination when subagents find enough information.
- Cache common code patterns and library signatures to avoid repeated analysis.
Related reading
- Zapier Vs Make Vs N8n 2026
- HDMI vs Displayport vs VGA vs DVI – What are They and What are Their Differences?

Tech enthusiast and founder of Technize. Passionate about making technology accessible and helping people make smarter buying decisions.