TokenEconomizer Saves 18.4% to 30.9% of Token Costs for Coding Agents
Microsoft's open-source plugin TokenEconomizer extracts repository experience from completed coding sessions, using micro-experiences, tool pruning, and failure intervention to reduce repetitive work. Tests show that across 277 fix tasks in six repositories, it reduces costs by 18.4%–30.9%, while task success rates remain stable overall.

- Repeated repository discovery, unused tools, and failure loops are the main sources of waste
- Session logs are distilled into repository knowledge, tool selection, and failure intervention
- Average cost reduced by 18.4%–30.9% across 277 real fix tasks
- Cumulative cost falls below the default approach by the 6th task in each repository
This is the official research blog post from the Microsoft research team announcing its own open-source plugin, including experimental setup, cost results, and open-source positioning; the conclusions are self-reported by the project team and have not yet been independently replicated by third parties.
You open a familiar code repository again and ask an AI coding agent to fix a bug: it re-explores the test commands from scratch, loads a pile of rarely used tools, and continues trying along the same failed path as last time, and the token bill grows accordingly. TokenEconomizer, open-sourced by Microsoft and UC Berkeley and other teams, aims to let agents remember experience already learned within the same repository; officially, across 277 real fix tasks, it measured an average cost reduction of 18.4%–30.9%, while task success rates remained stable overall.
Where do agents spend tokens on repetition every day?
Programmers return to the same repository every day, but AI coding agents (model agents that can read and write code and call tools to complete development tasks) often start from scratch. The Microsoft research team recorded the tool calls and costs of Claude Code handling 60 tasks on SWE-Bench (a benchmark that tests coding agents on real open-source project defects).
The first source of waste occurs within a repository. After the same repository accumulated at least 5 completed tasks, 30% of tool calls repeated actions from earlier tasks, such as re-exploring how to run tests. Only 7% of calls matched historical actions from another repository, indicating that most of this repetition is not due to generic operations, but because the agent did not remember experience already learned in the repository at hand.
The second source of waste comes from tool descriptions carried in every round but never used. Claude Code received 23 tool descriptions per round (information explaining a tool's purpose and how to call it), of which 16 were never called. The more tools a developer prepares for a repository, the heavier the descriptions the agent carries on every request; uncalled tools still occupy context, making the model repeatedly read options it does not need.
The third source of waste is hidden in failed tasks. Failed tasks account for 17% of all tasks but contribute 32% of spending, nearly twice their share of tasks. When the agent encounters the same error, it repeatedly tries different approaches, and the tokens consumed (the basic unit billed for text processed by the model) keep accumulating; failure not only slows down the task but also makes the bill heavier.
How can one old session help the next one take fewer detours?
TokenEconomizer reads ended session logs and carries repository experience confirmed across multiple attempts into subsequent tasks. Coding agents no longer have to start from scratch every time.
Repository experience is carried by micro-experiences (one-line notes that store repository-specific knowledge). The plugin first looks for recurring patterns across different sessions; a one-off discovery in a single task does not count. Only after confirmation across at least multiple sessions is a note written into the starting context of subsequent sessions.
What is written in can also be removed. If evidence contradicting a note appears in a subsequent session, the plugin revokes that experience and removes it from the starting context.
Tool pruning (removing infrequently used tools based on repository history) is responsible for reducing the tool descriptions the agent must receive every time but may not use. The plugin removes tools unlikely to be used based on the current repository's history, while retaining the two core tools of running commands and editing files. If a subsequent task does need them, removed tools can still be restored.
What if the agent repeatedly hits the same error? The plugin enables failure loop intervention (identifying repeated failures and prompting a change of approach). A judge model first determines whether the agent is truly stuck, or whether it is still making progress despite consecutive failures. Only after confirming that it is stuck does the agent receive a brief prompt suggesting a different approach.

Without changing models, how much can be saved?
Without changing the coding agent or reducing the model's reasoning effort, TokenEconomizer lowered average cost by 18.4%–30.9% across 277 real fix tasks. What is saved is the token cost actually consumed in the tests.
These results come from an evaluation published by Microsoft Research. The tests used SWE-Bench (a benchmark for fixing real software defects), covering 6 code repositories and 277 fix tasks, and tested 5 different coding agent and model combinations. The 6 repositories and 5 combinations crossed to form 30 repository combinations, and TokenEconomizer was the most cost-saving approach in all 30 combinations.
Microsoft Research also states that the statistics include the cost of the plugin's own model calls. These figures come from the project team's evaluation and have not yet been replicated by third parties.
| Approach | Performance across 277 real fix tasks |
|---|---|
| TokenEconomizer | Most cost-saving in all 30 repository combinations, average cost reduced by 18.4%–30.9% |
| Reducing model reasoning effort | Can save comparable or more cost, but task performance drops noticeably |
| Default approach | No added repository experience learning, and no change to model reasoning effort |
Reducing reasoning effort does save money, and can even save more, at the cost of noticeably lower task performance; TokenEconomizer's savings do not come from weakening the model, but from applying experience already validated in the same repository to subsequent tasks—provided that this experience actually holds in subsequent tasks.
The cost reduction did not come at the expense of task performance. Among the 5 agent–model combinations, 4 saw an increase in Pass@1 (the proportion of tasks solved on the first attempt). "Performance" is measured by task success rate and cannot be directly equated with all code quality or long-term maintenance outcomes.

By which task does the saving appear?
TokenEconomizer does not start saving money from the very first task. It pays a learning cost upfront, but by the 6th task, the cumulative cost across all tested repositories had fallen below the default approach.
When each repository begins testing, TokenEconomizer has no historical sessions to learn from. The first task requires exploring the repository on its own, recording experience, and judging which information is worth keeping for reuse in subsequent tasks. This stage may cost more than the default approach, because the plugin is building repository knowledge and its records are not yet sufficient to support cost control.
As tasks continue, repository patterns, tool usage, and failure paths confirmed in earlier sessions are applied to the next task; the cost of an individual early task may still be high, but as tasks in the same repository accumulate, the difference changes as available experience grows.
By the 6th task, the cumulative cost across all tested repositories was below the default approach, and the learning investment had been covered by savings from subsequent tasks. To judge whether it is worth adopting, one should not look only at the first task; the cumulative bill after continuous use in the same repository is more worth watching: the 6th task is the point in this test at which the default cost is crossed, but it does not mean every repository will break even earlier.
It saves in other scenarios too—the key is whether historical sessions can connect
Both tests showed reductions: continuous web development fell 16.0%–21.2%, and security auditing fell 6.4%–19.6%. The gap points to the same premise—whether tasks can accumulate historical sessions within the same repository.
Web development tasks are closer to everyday use. The test used Web-Bench (a benchmark for evaluating web development tasks), with tasks performed consecutively, and cost reduced by 16.0%–21.2%. The method does not depend on a particular kind of code repository or a particular agent: as long as subsequent sessions remain in the same repository, the plugin can reuse the repository experience already formed and take fewer repeated detours.
The reduction for security auditing was 6.4%–19.6%. The difference lies in task arrangement—each task switches to a new repository. Without historical sessions accumulated within the same repository, TokenEconomizer has nothing to reuse across tasks, so the reduction is naturally lower than in continuous web development.
Returning to the opening scene: a coding agent repeatedly working on the same code repository, starting from scratch every time. What it saves is not switching to a cheaper or weaker model, but the exploration already paid for in the same repository. For teams that do not keep agent session logs locally, how should the privacy boundary for code and logs be drawn for this approach of trading history for savings?
Source: Microsoft Research blog "TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient"; the figures are the project team's self-reported results on 6 repositories, 277 SWE-Bench fix tasks, and 5 agent and model combinations, including the plugin's own model call costs, and have not yet been independently replicated by third parties.
Glossary · Plain-language notes in this article
Full articles on deep dives, research interpretations, and tool tutorials, plus all podcasts, are in the members' area.