AI coding agents often work in the same codebase across successive sessions, yet they may repeatedly rediscover the same information, load tools they do not use, or revisit unsuccessful approaches. Each interaction consumes tokens and adds to the cost of using the model.
TokenEconomizer, an open-source plugin from UC Berkeley, Microsoft Research and Microsoft Security, uses experience from earlier sessions to make later tasks more efficient. It works alongside existing coding agents without modifying the agent or its underlying model.
Where waste occurs
The researchers first examined Claude Code on 60 tasks from SWE-Bench, a benchmark of real bug fixes in open-source Python projects. They ran the tasks for each repository sequentially.
They identified three recurring sources of expense. Once a repository had at least five completed tasks, 30% of tool calls repeated an action performed in an earlier task in that repository. Only 7% matched an action in another repository’s history. The agent received descriptions of 23 tools on every turn but never called 16 of them. Meanwhile, 17% of tasks failed, accounting for 32% of spending.
The researchers also tested three popular open-source plugins that each used a fixed cost-saving strategy. Each reduced costs in some repositories but not others, suggesting that effective cost control needs to adapt to the project.
Three ways to learn from past work
After each session, TokenEconomizer processes its log and updates what it knows about the repository. It uses three mechanisms that operate through the agent’s existing interfaces:
- Micro-skills: it proposes one-line, repository-specific notes based on recurring patterns. Notes enter the agent’s initial context only after several sessions confirm them, and are retired if later evidence contradicts them.
- Tool pruning: it removes tools that repository history suggests the agent is unlikely to use. Core tools for running commands and editing files remain available, and removed tools can be restored when needed.
- Failure-loop intervention: a separate judge model decides whether an agent encountering repeated failures is genuinely stuck or still making progress. If stuck, the agent receives a short note suggesting another approach. In the open-source plugin, if the agent remains stuck, TokenEconomizer alerts the developer rather than stopping the work itself.
The controller revises its decisions as new evidence arrives. The reported savings also include the cost of TokenEconomizer’s own model calls.
Results across different tasks
The researchers evaluated the system on 277 SWE-Bench tasks from six repositories, using five agent–model combinations. TokenEconomizer started without prior session history in each repository.
Average cost per task fell by 18.4–30.9% across the combinations. Task success remained broadly stable, and the Pass@1 metric rose in four of the five combinations. According to the paper, the system achieved savings without performance loss in all 30 repository and agent–model pairings. By comparison, reducing the model’s reasoning effort produced similar or greater savings but substantially degraded performance.
Early tasks can cost more while the system learns. In the Claude Code evaluation, however, cumulative costs fell below the default in every repository by the sixth task. Each mechanism produced savings on its own, while combining all three yielded a larger reduction.
The approach also worked on sequential web-development tasks, with costs 16.0–21.2% lower on Web-Bench. For security auditing, where every task took place in a new repository, costs fell by 6.4–19.6%.
The plugin requires no API key of its own and keeps what it learns on the developer’s machine. The researchers say the approach offers a way for coding agents to learn from past work not only to solve tasks, but also to use computing resources more efficiently.



