TokenEconomizer: How Repository Experience Reduces Token Costs for AI Coding Agents by 20% to 30%
Researchers from Microsoft Research, UC Berkeley, and the Microsoft Security team found that coding agents perform approximately 30% redundant tool calls within the same repository, with 16 out of 23 tool descriptions never used, and 17% of failed tasks consuming 32% of the budget. They open-sourced the TokenEconomizer plugin, which leverages three mechanisms—micro-skills, tool pruning, and failure-loop intervention—to convert repository history into cost savings for subsequent sessions. On 277 SWE-Bench tasks, it reduced token costs by an average of 18.4%–30.9% without modifying the agent or the underlying model.
Developers use AI coding agents in the same codebases day after day, yet each session starts from scratch: rediscovering how to run tests, loading tools that are never called, and spinning in circles on the same error. Microsoft Research, UC Berkeley, and the Microsoft Security team profiled Claude Code across 60 real bug-fixing tasks on SWE-Bench to quantify the scale of this waste. They identified three recurring patterns: once a repository had accumulated at least five completed tasks, 30% of tool calls repeated actions from earlier tasks in that repository; in every turn, the agent received 23 tool descriptions, 16 of which were never invoked; and 17% of failed tasks consumed 32% of the total budget.
The core idea behind TokenEconomizer is to turn completed sessions into guidance for subsequent ones, without modifying the agent or the underlying model. It operates through three mechanisms. Micro-skills identify recurring patterns across multiple sessions and generate one-line notes added to the agent’s starting context; these are only added after several sessions confirm the pattern and are retired if later evidence contradicts them. Tool pruning removes tools that the repository history suggests the agent is unlikely to use, while always retaining core tools for running commands and editing files; removed tools can be restored if needed. Failure-loop intervention detects whether an agent is repeatedly hitting the same error, using a judge model to determine if it is truly stuck; if so, the agent receives a short note suggesting a change of direction.