TokenEconomizer cuts AI coding agent costs by learning from past sessions
Microsoft Research and UC Berkeley introduce an open-source plugin that reduces token usage for AI coding agents by leveraging repository history without modifying the underlying model.
Researchers from Microsoft Research, Microsoft Security, and UC Berkeley have released TokenEconomizer, an open-source plugin designed to lower the operational costs of AI coding agents. Published on November 16, 2026, the tool addresses the inefficiency of agents that restart every session from scratch, ignoring valuable context from previous interactions within the same codebase.
What happened
AI coding agents are becoming standard tools for fixing bugs and building features, but their reliance on large language models makes them expensive to run. Each interaction consumes tokens as the agent sends instructions, tool descriptions, and history to the model. While developers often work in the same repositories day after day, most agents fail to retain knowledge across sessions, leading to repeated mistakes and redundant computations.
To quantify this waste, the research team profiled Claude Code on 60 tasks from SWE-Bench, a benchmark for real bug fixes in open-source Python projects. They identified three primary sources of inefficiency: rediscovering facts already known from earlier tasks, paying for unused tool descriptions, and getting stuck in failure loops. For instance, after five completed tasks in a repository, 30% of tool calls were repeats of actions from earlier sessions. Additionally, agents received 23 tool descriptions per turn but only used seven, while failed tasks accounted for nearly a third of total spending despite representing only 17% of the workload.
Existing cost-saving plugins often apply fixed strategies that do not adapt to specific repository needs. TokenEconomizer takes a different approach by treating each completed session as a learning opportunity. It operates as a black-box controller that sits alongside the agent, analyzing logs to update its understanding of the repository without requiring changes to the agent itself or its underlying model.
How it works
TokenEconomizer functions through three adaptive mechanisms that refine the agent’s behavior over time. First, it generates micro-skills, which are one-line notes capturing repository-specific patterns. These notes are added to the agent’s context only after multiple sessions confirm their validity, and they are retired if subsequent evidence contradicts them. This ensures the agent retains useful shortcuts without accumulating outdated or incorrect information.
Second, the tool performs dynamic tool pruning. It removes descriptions for tools that historical data suggests are unlikely to be used in the current repository, while always preserving core capabilities for running commands and editing files. If a pruned tool becomes necessary later, it can be restored. Third, a failure-loop intervention mechanism monitors the agent for repetitive errors. A judge model determines if the agent is truly stuck, and if so, provides a short note suggesting a different approach. If the agent remains stuck, the plugin alerts the developer rather than halting the process.
Key details
- TokenEconomizer reduced costs by 18.4–30.9% across 277 SWE-Bench tasks using five different AI agent and model combinations.
- The plugin achieved savings in every repository tested, with cumulative costs falling below default levels by the sixth task.
- Task success rates remained broadly stable, and in four out of five agent-model combinations, the pass rate actually improved.
- Savings also applied to other domains, reducing costs by 16.0–21.2% on Web-Bench for web development and 6.4–19.6% for security auditing tasks.
- The tool runs locally on the developer’s machine, requires no API key, and does not modify the underlying AI model.
- Early sessions may cost more as the system learns, but efficiency gains accumulate rapidly as experience grows.
Why it matters
For engineering teams adopting AI agents, token costs can quickly escalate, especially when agents operate autonomously on complex codebases. TokenEconomizer demonstrates that significant savings are possible without sacrificing performance or requiring deep integration with proprietary models. By adapting to the specific habits and structure of a repository, it avoids the pitfalls of one-size-fits-all optimization strategies that often degrade agent capability.
This approach shifts the paradigm from viewing each agent session as an isolated event to treating them as part of a continuous learning process. It allows developers to maintain high success rates while reducing the financial overhead of automated coding assistance. As agents become more prevalent, tools that enable them to learn from experience will be critical for sustainable adoption in production environments.
What you can do
- Install the open-source TokenEconomizer plugin to test cost reductions in your existing AI coding workflows.
- Monitor the first few sessions closely, as the system requires initial tasks to build its repository-specific knowledge base.
- Review the generated micro-skills periodically to ensure the learned patterns align with your project’s evolving standards.
- Combine TokenEconomizer with other best practices, such as clear prompt engineering, to maximize overall efficiency.
- Evaluate the tool on diverse tasks, including bug fixes and feature development, to understand its impact across different types of work.
- Contribute to the open-source project by sharing feedback on how the failure-loop intervention handles edge cases in your codebase.



