AI
TokenEconomizer learns from past debugging sessions to cut AI coding agent costs by up to 31%
An open-source plugin that tracks what AI agents have already learned in a codebase helps them solve future tasks with 18–31% fewer tokens, without altering the underlying model.
1/6
Microsoft Research Blog
AI coding agents tackle bug fixes and feature development with minimal human intervention, but each turn they take consumes tokens—a costly resource. When developers work in the same codebase over multiple sessions, today's agents typically begin each task from zero, forcing them to rediscover repository-specific patterns, load tools they never use, and retry approaches that have already failed.
TokenEconomizer, a new open-source plugin from UC Berkeley, Microsoft Research, and Microsoft Security, addresses this inefficiency by distilling lessons from completed debugging sessions into guidance for the next one. The system optimizes costs without modifying the agent itself or its underlying model, making it compatible with any existing AI coding tool.
Three sources of wasted tokens#
Researchers profiled Claude Code across 60 real-world bug-fixing tasks to understand where tokens go to waste:
- Redundant rediscovery: After a repository accumulated five or more finished tasks, 30% of subsequent tool calls simply repeated actions the agent had already performed in that same repository.
- Unused tools in context: The agent received descriptions of 23 tools on each turn, yet only 7 were ever called during a session.
- Stuck in failure loops: Just 17% of failed tasks consumed a third of total spending, as agents repeatedly attempted and abandoned the same unsuccessful paths.
Three popular open-source cost-reduction plugins each worked in some repositories but not others, suggesting that one-size-fits-all strategies fail to adapt to repository-specific needs.
How the system learns and saves#
TokenEconomizer operates through three complementary mechanisms, all built on interfaces the underlying agent already exposes:
Micro-skills are concise, single-line notes capturing patterns unique to each repository. The system identifies recurring actions across sessions and proposes notes only after several sessions confirm the pattern. If later evidence contradicts them, notes are retired.
Tool pruning removes tools the agent is unlikely to use based on historical behavior, while preserving essential commands for running tests and editing code. Removed tools can be restored if circumstances change.
Failure-loop intervention detects when an agent keeps hitting the same error. A judge model assesses whether the agent is making genuine progress or stuck. If truly stuck, the system suggests an alternative approach. In the open-source version, if the agent remains blocked after the hint, TokenEconomizer alerts the developer rather than halting work.

