AI coding agents can waste time and tokens relearning the same lessons. TokenEconomizer is an open-source plugin that builds on past sessions to cut costs while maintaining task success. It’s a path toward coding agents that learn not only how to solve tasks, but also how to spend computation more effectively. The post TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient appeared first on Microsoft Research .
AI coding assistants are getting good at tackling bug fixes and feature work with minimal human input, but their autonomy comes with a meter running in the background. Every turn typically ships a bundle of text to the model—instructions, tool documentation, and the growing transcript of the session. Most token-saving tactics treat each task as a one-off. In practice, developers (and agents) return to the same codebases repeatedly, creating an obvious opportunity: reuse what was learned last time instead of re-deriving it from scratch.
That is the premise of “TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents,” a new paper describing an open-source plugin built by researchers from UC Berkeley, Microsoft Research, and Microsoft Security. The system is designed to reduce token spend while leaving both the agent and its underlying model untouched—meaning it can be layered on top of existing coding-agent workflows rather than requiring a new agent architecture.
The team began by profiling Claude Code on 60 sequential tasks from SWE-Bench, a benchmark built from real bug-fix issues in open-source Python projects. Running tasks in order within each repository revealed repeated inefficiencies: agents would re-learn routine repo-specific procedures such as how to run tests; they would load or describe tools that rarely got used; and they could burn many turns circling the same failure mode. The researchers also evaluated three widely used open-source plugins that apply fixed cost-cutting rules. Those tools reduced spending in some repositories but not in others, pointing to a central conclusion: cost control needs to adapt to the idiosyncrasies of each repository rather than rely on a single universal strategy.
TokenEconomizer operationalizes that adaptive approach by converting completed sessions into guidance for later ones. After each run, it reads the session log and updates its repository-specific understanding, then influences the next session through three mechanisms—using only standard interfaces already available to agents.
First, it creates micro-skills: short, one-line notes that capture recurring, repository-specific patterns. Importantly, these notes are only added to the agent’s initial context after repeated confirmation across multiple sessions, and they can be retired if later evidence contradicts them. Second, it performs tool pruning, removing tools that history suggests are unlikely to be useful in that particular codebase while retaining essential tools for editing files and running commands; pruned tools can be reinstated when needed. Third, it adds failure-loop intervention: when an agent appears to be repeating the same unsuccessful behavior, a judge model assesses whether it is genuinely stuck or still making progress. If stuck, the agent receives a brief suggestion to change course. In the open-source implementation, if the agent remains stuck, TokenEconomizer escalates by alerting the developer rather than terminating the attempt on its own.
To measure real-world impact, the researchers evaluated TokenEconomizer on 277 SWE-Bench tasks across six repositories, spanning five agent-and-model configurations. For each repository, the system started with no prior history. Even after accounting for the plugin’s own model calls, TokenEconomizer reduced average costs by 18.4% to 30.9%. Across all 30 repository–configuration pairs, it delivered the largest savings without reducing task performance. The authors contrast this with a common alternative—simply lowering the model’s reasoning effort—which sometimes saved as much or more but caused “substantial” performance drops.
The benefits also increased with experience. While early tasks could be more expensive as the system learned, cumulative costs beat the default baseline in every repository by the sixth task. Each of the three mechanisms produced savings individually, with the combined system saving the most.
Beyond SWE-Bench, the approach carried over to sequential web development: costs were 16.0% to 21.2% lower on Web-Bench. And in security auditing—where each task arrives in a fresh repository and prior experience is less reusable—TokenEconomizer still cut costs by 6.4% to 19.6%.
Why it matters
As coding agents move from demos to daily development work, token costs can become a significant operational expense. TokenEconomizer suggests a practical path to reducing that bill without switching models or rebuilding agent stacks—by letting agents “remember” how a repository works. The key question to watch next is how well this experience-based optimization generalizes across languages, toolchains, and fast-changing codebases where yesterday’s micro-skills may quickly go stale.
