You open the same familiar repository again and ask an AI coding agent to fix a bug, only for it to relearn how to run the tests, load a pile of rarely used tools, and continue down the same failed path as before, driving up your token bill. TokenEconomizer, open-sourced by teams from Microsoft, UC Berkeley, and elsewhere, aims to help agents remember what they have already learned in the same repository. In official testing across 277 real bug-fixing tasks, average costs fell by 18.4%—30.9%, while overall task success rates remained stable.

It is like giving someone who enters the same repair workshop every day a loose-leaf notebook: notes on which machine must be powered down first, which tool turns out to be unnecessary, and which repair method did not work last time. It does not repair the machine for them; it simply prevents them from repeating dead ends whose answers are already known before the next job begins.

Where do agents waste tokens every day?

Programmers return to the same repository every day, yet AI coding agents—model-based agents that can read and write code and invoke tools to complete development tasks—often start from scratch. A Microsoft research team recorded the tool calls and spending involved in Claude Code completing 60 tasks on SWE-Bench(a benchmark that tests coding agents on defects in real open-source projects).

The first source of waste occurs inside the repository. Once a repository has accumulated at least 5 completed tasks, 30% of tool calls repeat actions from earlier tasks, such as figuring out again how to run the tests. Only 7% of calls match actions from the history of a different repository, indicating that most of this repetition does not arise from generic operations. Rather, it reflects the agent's failure to remember what it has already learned about the repository at hand.

The second source of waste comes from tool descriptions carried in every round but never used. Claude Code receives 23 tool descriptions in each round—information explaining what each tool does and how to invoke it—but 16 are never called. The more tools developers prepare for a repository, the heavier the descriptions each request may become for the agent. Unused tools still consume context, forcing the model to read options it will never use.

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 the workload. When an agent encounters the same error, it keeps trying different variations, steadily consuming tokens(the basic unit used to measure and charge for processing text). Failure does more than slow down a task; it makes the bill heavier.

How can an old session prevent the next one from repeating mistakes?

TokenEconomizer reads completed session logs and carries repository knowledge confirmed across multiple attempts into subsequent tasks. Coding agents no longer have to start from scratch every time.

From an old session to the next session
Read session logs
→
Identify repository-specific patterns
→
Update starting knowledge and tool list
→
Intervene in repeated failures

Repository knowledge is carried by micro-experiences(one-line notes that preserve repository-specific knowledge). The plugin first looks for patterns that recur across different sessions; an isolated discovery from a single task does not count. A note is added to the starting context of subsequent sessions only after multiple sessions have confirmed it.

Written knowledge may also be removed. If a later session produces evidence that contradicts a note, the plugin revokes that experience and removes it from the starting context.

Tool pruning(removing infrequently used tools based on repository history) reduces the tool descriptions the agent must receive each time even when it may never use them. The plugin removes tools that are unlikely to be used based on the current repository's history while retaining the two core tools for running commands and editing files. If a later task genuinely needs a removed tool, it can still be restored.

What happens when an agent keeps running into the same error? The plugin activates failure-loop intervention(detecting repeated failures and prompting the agent to change approaches). A judge model first determines whether the agent is genuinely stuck or still making progress despite consecutive failures. Only after confirming that it is stuck does the agent receive a brief prompt suggesting a different approach.

Microsoft Research Blog (RSS) official image 1
Official illustration 1 · Source: Microsoft Research Blog (RSS) · Data definitions follow the original article

How much can be saved without changing the model?

Without replacing the coding agent or reducing the model's reasoning intensity, TokenEconomizer cut average costs by 18.4%—30.9% across 277 real bug-fixing tasks. The savings came from token costs actually incurred during testing.

These results come from an evaluation published by Microsoft Research. The test used SWE-Bench(a benchmark for real-world software bug fixes), covering 6 code repositories and 277 bug-fixing tasks, and tested 5 different combinations of coding agents and models. The cross-product of the 6 repositories and 5 combinations produced 30 repository combinations, and TokenEconomizer delivered the greatest savings in all 30.

Microsoft Research also stated 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 independently reproduced by a third party.

Approach Performance across 277 real bug-fixing tasks
TokenEconomizer Delivered the greatest savings across all 30 repository combinations, reducing average costs by 18.4%—30.9%
Lower model reasoning intensity Could save comparable or greater costs, but caused a marked decline in task performance
Default approach No repository knowledge learning and no changes to model reasoning intensity

Lowering reasoning intensity does save money, potentially even more, but at the cost of a marked decline in task performance. TokenEconomizer's savings do not come from weakening the model; they come from applying previously validated experience from the same repository to later tasks—provided that experience remains valid in those tasks.

Lower costs did not come at the expense of task performance. Of the 5 agent-model combinations, 4 saw an increase in Pass@1(the proportion of tasks solved on the first attempt). “Performance” here is measured by task success rate and cannot be equated directly with every aspect of code quality or long-term maintainability.

Microsoft Research Blog (RSS) official image 2
Official illustration 2 · Source: Microsoft Research Blog (RSS) · Data definitions follow the original article

How many tasks before the savings appear?

TokenEconomizer does not begin saving money with the very first task. It first pays the cost of learning, but by the 6th task, cumulative costs across all test repositories have fallen below those of the default approach.

When testing begins for each repository, TokenEconomizer has no historical sessions to learn from. The first task must explore the repository on its own, record experience, and determine which information is worth preserving for reuse in later tasks. This phase may cost more than the default approach because the plugin is building repository knowledge, and the records are not yet sufficient to control costs.

As tasks progress, repository patterns, tool usage, and failure paths confirmed in earlier sessions are used in the next task. The cost of an individual early task may still be high, but as tasks accumulate within the same repository, the difference changes as more experience becomes available.

By the 6th task, cumulative costs across all test repositories are below those of the default approach, and the learning investment has been offset by savings on subsequent tasks. Deciding whether it is worth integrating cannot depend on the first task alone; the cumulative bill after continuous use within the same repository deserves more attention: the 6th task is the point at which this test crossed below the default cost, but that does not mean every repository will break even earlier.

Savings in other scenarios depend on connecting historical sessions

Both tests produced savings: continuous web development costs fell by 16.0%—21.2%, while security auditing costs fell by 6.4%—19.6%. The difference points to the same prerequisite: 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 costs fell by 16.0%—21.2%. The method does not depend on a particular type of repository or agent: as long as subsequent sessions remain in the same repository, the plugin can reuse the repository knowledge it has already built and avoid repeated exploration.

Security auditing saw savings of 6.4%—19.6%. The difference lies in how the tasks were arranged: every task used a new repository. Without historical sessions accumulated within the same repository, TokenEconomizer had nothing to reuse across tasks, so its savings were naturally lower than in continuous web development.

Return to the opening scenario: a coding agent repeatedly works on the same repository and starts from scratch every time. What it saves is not the cost of switching to a cheaper or weaker model, but the cost of exploration already paid for within the same repository. For teams that do not keep agent session logs locally, where should the privacy boundary lie between code and logs in an approach that trades history for savings?

Source: Microsoft Research blog post “TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient”; the figures are self-reported by the project team across 6 repositories, 277 SWE-Bench bug-fixing tasks, and 5 agent-model combinations, include the plugin's own model-call costs, and have not yet been independently reproduced by a third party.