我们首先对 SWE-Bench(一个针对开源 Python 项目中真实 bug 修复的基准测试)上的 60 个任务中的 Claude Code 进行了分析,按顺序运行每个代码库的任务。出现了三种 recurring 的浪费现象:
我们还测试了三个流行的开源插件,它们各自围绕固定的节省成本策略构建。每个插件在某些代码库中降低了成本,但在其他代码库中则没有效果。这些发现共同表明,有效的成本控制必须适应特定的代码库,而不是在所有地方应用同一种策略。
我们在来自六个代码库的 277 个 SWE-Bench 任务上评估了 TokenEconomizer,使用了五种不同的 AI 编码代理和模型组合。对于每个代码库,TokenEconomizer 开始时没有任何先前的会话历史记录。
如图 3 所示,TokenEconomizer 将平均成本降低了 18.4%–30.9%,并在所有 30 个“代码库-组合”配对中实现了最大程度的节省,且没有性能损失。相比之下,降低模型的推理努力虽然节省了相似或更多的费用,但导致了显著的性能下降。
随着经验的积累,节省幅度也会增加。早期任务可能会因为 TokenEconomizer 的学习过程而成本更高,但到第六个任务时,每个代码库的累计成本都低于默认值,如图 4 所示。每种机制都能单独带来节省,而结合使用所有三种机制则能实现最大的降幅。
节省效果也延续到了顺序式 Web 开发中,Web-Bench 上的成本降低了 16.0%–21.2%。在安全审计方面(每个任务都在一个新的代码库中),成本降低了 6.4%–19.6%。
TokenEconomizer 开辟了一条路径,使编码代理不仅能学习如何解决任务,还能学习如何更有效地分配计算资源。其轻量级的控制器展示了经验如何在无需更改底层代理或模型的情况下提高效率。
该开源插件使开发人员和研究者能够轻松利用这些方向。它设计为与现有的 AI 编码代理并行运行,无需修改其底层模型,不需要自己的 API 密钥,并且将其所学内容保留在开发者的机器上。我们邀请社区将其作为起点,探索随着经验积累而变得更具资源的代理,使其工作方式以及所掌握的知识都能不断适应进化。
查看原文

At a glance
- Developers use AI coding agents in the same codebases day after day, yet agents often start each session from scratch: rediscovering familiar facts, loading unused tools, and repeating unsuccessful approaches.
- TokenEconomizer is an open-source plugin that learns from an agent’s past sessions in a repository to reduce waste in future sessions, without modifying the agent or its underlying model.
- Across 277 real bug-fixing tasks, TokenEconomizer reduced costs by 18.4–30.9% across multiple AI coding agents. Costs fell in every repository tested, while task success rates remained broadly stable.
AI coding agents are increasingly helping developers fix bugs and build features largely on their own, but every interaction with their models consumes tokens. In each session, an agent sends instructions, tool descriptions, and session history to its model. Most efforts to reduce this cost focus on individual tasks. Yet developers return to the same repositories, giving agents an opportunity to learn from previous work. Without that learning, an agent may repeatedly rediscover how to run tests, load tools it never uses, or spend dozens of turns revisiting the same error.
In our paper, TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents, we ask a simple question: can experience in a repository help an agent solve future tasks more efficiently? TokenEconomizer, an open-source plugin from UC Berkeley, Microsoft Research, and Microsoft Security, turns completed sessions into guidance for subsequent ones. It reduces waste without changing the agent or its underlying model, so developers can use it alongside the coding agents they already rely on.

Figure 1. Each finished session teaches TokenEconomizer something about the repository, so later sessions cost less tokens.
Where the tokens go
We first profiled Claude Code on 60 tasks from SWE-Bench, a benchmark of real bug fixes in open-source Python projects, running each repository’s tasks in sequence. Three kinds of waste recurred:
- Rediscovering the same facts. After a repository had accumulated at least five completed tasks, 30% of tool calls repeated an action from an earlier task in that repository. Only 7% matched an action in another repository’s history.
- Paying for unused tools. The agent received 23 tool descriptions on every turn, but 16 were never called.
- Getting stuck on failures. The 17% of tasks that failed accounted for 32% of the spending.
We also tested three popular open-source plugins, each built around a fixed cost-saving strategy. Each lowered costs in some repositories but not others. Together, these findings suggest that effective cost control must adapt to the repository, rather than apply the same strategy everywhere.
Microsoft Research StorY

OptiMind: When the system meets the floor
A three‑month pilot in a Midwestern bottling plant shows what happens when AI moves beyond chat and into decision-making, where constraints shift, stakes are real, and answers must hold.
How TokenEconomizer works
After each session, TokenEconomizer reads the session’s log and updates what it knows about the repository. It then acts through three mechanisms, using only interfaces the agent already provides, as illustrated in Figure 2.
Micro-skills capture repository-specific knowledge in one-line notes. TokenEconomizer identifies recurring patterns across sessions and proposes corresponding notes. They are added to the agent’s starting context only after several sessions have confirmed the pattern, and retires the note if later evidence contradicts it.
Tool pruning removes tools that repository history suggests the agent is unlikely to use, while always retaining core tools for running commands and editing files. Removed tools can be restored if needed.
Failure-loop intervention watches for an agent that keeps hitting the same failure. A judge model decides whether the agent is truly stuck or still making progress. If it is stuck, the agent gets a short note suggesting a different approach. In the open-source plugin, if the agent is still stuck after the note, TokenEconomizer alerts the developer rather than stopping the work itself.

Figure 2. TokenEconomizer works alongside an unchanged coding agent. Micro-skills add learned facts, tool pruning trims the loaded tools, and failure-loop intervention redirects stuck work. Each finished session updates all three.
The controller is designed to revise its decisions as new evidence arrives. Reported savings also account for the cost of TokenEconomizer’s own model calls.
Saving costs in every repository
We evaluated TokenEconomizer on 277 SWE-Bench tasks from six repositories, using five different AI coding agent and model combinations. For each repository, TokenEconomizer started with no prior session history.
TokenEconomizer lowered the average cost by 18.4–30.9%, as shown in Figure 3, and saved the most in all 30 repository-combination pairs without performance loss. By contrast, lowering the model’s reasoning effort saved similar or larger amounts but led to substantial performance degradation.

Figure 3. On SWE-Bench, TokenEconomizer lowered mean cost per task by 18.4–30.9% across five agent–model combinations (left), while Pass@1 rose in four of them (right).
Savings grow as experience accumulates. Early tasks can cost more while TokenEconomizer learns, but cumulative costs fell below the default in every repository by the sixth task, shown inFigure 4. Each mechanism contributes savings on its own, and combining all three delivers the largest reduction.

Figure 4. Cumulative cost change relative to default over each repository’s tasks, using Claude Code. Starting with no history, every repository becomes cheaper by the sixth task.
The savings also carried over to sequential web development, with costs 16.0–21.2% lower on Web-Bench. On security auditing, where every task is in a new repository, costs were 6.4–19.6% lower.
Looking ahead
TokenEconomizer opens a path toward coding agents that learn not only how to solve tasks, but also how to spend computation more effectively. Its lightweight controller shows how experience can improve efficiency without changing the underlying agent or model.
The open-source plugin makes these directions accessible to developers and researchers. It is designed to run alongside existing AI coding agents without modifying their underlying models, requires no API key of its own, and keeps what it learns on the developer’s machine. We invite the community to use it as a starting point for exploring agents that become more resourceful with experience, adapting how they work, as well as what they know.