@yibie: Recommends this hardcore real-world test. An engineer tracked his coding agent session for a week and found that only 0.67% of tokens were spent on actual tasks—the remaining 99% all went to moving tool directories, skill descriptions, and system prompts. Work-to-overhead ratio 1:1…
Summary
An engineer tracked his coding agent's token usage over a week, finding that only 0.67% of tokens were spent on actual tasks, with 99% consumed by tool directories, skill descriptions, and system prompts. He provides optimization strategies, including shell output filtering which saved 46.9% of tokens.
View Cached Full Text
Cached at: 07/15/26, 01:55 PM
Recommend this hard-hitting real-world test. An engineer spent a week tracking his own coding agent sessions, only to find that the actual task consumed just 0.67% of the tokens—the remaining 99% was all spent hauling tool directories, skill descriptions, and system prompts. Work-to-overhead ratio: 1:150. Most painful stat: Shell output filtering saved 46.9% of tokens, while compressing history saved only 4.2%. He offers a full optimization methodology—starting with reading the usage block.
Your Agent Spends 99% of Its Tokens Carrying the Toolbox, Not Doing the Work
There’s a comfortable assumption in agentic coding: tokens scale with work. Big task, big bill. Small fix, small bill.
It’s wrong.
I tracked a full session that fixed a GitHub issue: read the issue → edit 98 lines of server.mjs → run tests → commit → open PR. Output was about 10,304 tokens. Total processed context was about 1.55 million tokens. Work-to-overhead ratio: roughly 1:150.
The Four Most Expensive Items on the Bill
-
Tool name dumps—the single biggest chunk. I connected 9 MCP servers, exposing about 260 tools. When two servers attached mid-session, the harness injected their full tool catalogues—one server alone listed about 180 tool names. It’s one-time, but it’s huge, and it never leaves conversation history.
-
Skills catalogue—a per-turn fixed tax. Dozens of skills, each with multi-sentence descriptions, loaded every turn. No spike—it just raises the floor.
-
System prompt, safety policies, tool schemas. Fixed cost per turn. Before the agent does anything, the per-turn baseline could already exceed 100K tokens.
-
The actual task. A few KB. Trivial compared to the catalogues.
The dominant driver of context growth is what you’ve connected, not what you’re doing.
How to Fix It—Ranked by Effectiveness
-
Read the usage block (free). The API response on the final turn carries three numbers: output_tokens, input_tokens, cache_read_input_tokens. Cache reads = your cumulative history—every git status, every npm test output, every old/new string pair from edits. In my session: ~10.3K output, ~9.9K fresh input, ~1.535M cache reads. That one number tells the whole story.
-
Use /context mid-session to take a look. It shows what’s currently occupying the context window. That’s how you catch the per-turn fixed cost.
-
Filter shell output—biggest single lever. Add a thin filtering layer before shell commands, saving 2.7 million tokens (46.9%) across about 6,800 commands. This is the highest-leverage per-token intervention—because tool output re-enters context on every subsequent turn.
-
Disconnect MCP servers you aren’t using for this session. Biggest single win, zero engineering. The fattest tool dump came from a server I never called during the entire session. Connect per task, not permanently.
-
Constrain output style. Hook to force terse agent responses on routine turns. Baseline estimate: ~65% output-token savings on affected turns.
-
Compress stale history—but be precise. 31% of messages were file-read outputs (too risky to compress), 51% too short to bother. Only stale reads—file contents from 10+ turns ago—are worth targeted compression.
-
Respect the cache. A 95.1% hit rate is what made a 713 million token week affordable. Anything that disrupts prompt prefix stability—reordering tools, editing prompts mid-session, unstable tool catalogues—resets this curve.
Five Lessons
- The ratio is the core metric. Not total tokens—the ratio of task tokens to environment tokens.
- Every connected tool is a fixed charge. Connect on demand, don’t mount permanently.
- One-shot costs and per-turn costs need different treatment.
- Measure first, then optimize—intuition is usually third-best. I would have bet history compression was the biggest win (actual 4.2%), and CLI output filtering last (actual 46.9%).
- Output tokens are small but expensive; cache tokens are huge but cheap. Optimize both, but know which lever you’re pulling.
Original: https://praveenvijayan.substack.com/p/your-agent-spends-99-of-its-tokens…
#TokenOptimization #AgentEngineering #MCP
Similar Articles
@freeman1266: Slash AI coding costs by 80% monthly with optimization strategies and model routing. Inefficient context management and blind use of expensive models can cause bills to skyrocket. By implementing prompt caching, trimming context files, and fixing auto-loops in tool calls, developers can significantly reduce ineffective token consumption.…
This article introduces practical techniques to cut AI coding costs by 80%, including prompt caching, context trimming, multi-model routing (using Kimi 2.6 for daily coding tasks and advanced models for core architecture), and more.
I measured where my AI coding agents waste tokens, 42% was avoidable. Built a tool to catch it (Claude Code / Cursor / Codex)
The author measured token waste in AI coding agents and found 42% avoidable, then built a tool to catch it. The tool works with Claude Code, Cursor, and Codex.
@AstroHanRay: We ran an actual A/B benchmark test for active tool pruning, comparing 121 Terminal Bench tasks: - Performance: no regression (even slight improvement +2.48pp) - Token consumption: reduced by 41.7…
A/B testing for agent active tool pruning shows: across 121 Terminal Bench tasks, performance slightly improves (+2.48 percentage points), token consumption reduces by 41.7%, and cost decreases by 31.6%.
@jasonzhou1993: I gave my coding agent a map across 3 of my repos: - Reduce ~50% token - a grep hook so every grep call has much richer…
Jason Zhou shares a technique to give coding agents a map across repos, reducing token usage by ~50% and enabling richer grep and call chain tracing. He also releases a Claude Code plugin marketplace called AI Builder Club Skills for setting up codebase harness and compounding agent loops.
@wsl8297: When running complex tasks with AI agents, the most painful thing is often not that the model isn't strong enough, but that as the conversation gets longer, the context starts to overflow. You have to keep filling in background details, re-explaining the process, plus the redundant logs from tool calls — tokens just gush out like a broken pipe. Recently, I saw TencentDB Agent Memory open-sourced by Tencent...
Tencent has open-sourced TencentDB Agent Memory, which solves the AI agent long-context overflow problem through hierarchical memory management (symbolic short-term memory + hierarchical long-term memory). Benchmarks show token consumption reduced by up to 61% and task success rate improved by over 50%.