Hidden Costs of AI Coding Agents Arise from 'Lack of Experience'
Even if developers use AI coding agents daily in the same repository, the agent starts from scratch in each session. It rediscover familiar facts, loads tools that will not be used, and repeats failed approaches. The joint research team from Microsoft Research and UC Berkeley profiled 60 tasks from SWE-Bench sequentially by repository using Claude Code. As a result, three distinct waste patterns emerged.
| Waste Type | Key Figures | Details |
|---|---|---|
| Rediscovery of the Same Fact | 30% Repeated Tool Calls | After accumulating over 5 tasks, previous actions are repeated within the same repository. Matches with other repository histories are only 7% |
| Loading Unused Tools | 16 out of 23 Uncalled | Full tool descriptions are provided every turn. Most tools, except for core ones, remain unused |
| Failure Loop Stagnation | 17% of Failures Account for 32% of Costs | Excessive turns spent on attempts to fix the same error |
The research team pointed out that "since developers return to the same repository, the agent has the opportunity to learn from previous work," and noted that fixed cost reduction strategies cannot resolve repository-specific variances.
TokenEconomizer: Experience Learning Through a Black Box Approach
TokenEconomizer operates as a plugin that does not modify the agent or underlying model. It reads session logs and updates repository knowledge, then activates three mechanisms using only the interfaces already provided by the agent.
- Micro-skills: Accumulates repository-specific knowledge in one-line memos. When patterns are confirmed across multiple sessions, they are added to the starting context and automatically discarded when contradictory evidence appears.
- Tool Pruning: Removes unnecessary tools based on usage history. Core tools such as command execution and file editing are always retained and can be restored immediately if needed.
- Failure-loop Intervention: A judge model determines whether the agent is stagnating. If stagnating, alternative approaches are suggested; if persistent, the developer is notified before continuing work.
"The controller is designed to modify decisions when new evidence arrives. The reported savings also include the costs of calling the TokenEconomizer model itself." — from the original text
Validation with 277 Real Tasks: Cost Reduction Across All Repositories and Combinations
Evaluated with 6 repositories from SWE-Bench, 5 agent-model combinations, and 277 bug-fixing tasks. TokenEconomizer reduced costs by an average of 18.4% to 30.9% across all 30 repository-combination pairs, while maintaining overall task success rates. Methods to reduce inference effort yielded similar savings but resulted in significant performance degradation.
| SWE-Bench | 18.4-30.9% |
| Web-Bench | 16.0-21.2% |
| Security Audit | 6.4-19.6% |
As experience accumulates, the extent of savings expands. Initial tasks may incur higher learning costs, but from the 6th task onward, cumulative costs fell below the default. Each of the three mechanisms contributes independently, achieving maximum effectiveness when combined. In sequential web development (Web-Bench), savings of 16.0% to 21.2% were confirmed, while in security audits where each task involved a new repository, savings of 6.4% to 19.6% were also observed.
Implications: Agents Learning 'Cost Knowledge' Beyond 'Task Knowledge'
TokenEconomizer enables agents to learn not only 'what they know' but also 'how to use it efficiently' through experience. Distributed as an open-source plugin, it can be immediately applied to existing workflows, requiring no separate API keys and reducing security concerns by storing local learning data. However, further validation is needed regarding the criteria for selecting judge models, tuning micro-skill thresholds, and scalability in large monorepos.