Writing
November 18, 2026 · 3 min read

TokenEconomizer: coding agents that get cheaper the longer they work in a repo

Microsoft Research and UC Berkeley released TokenEconomizer, an open-source plugin that learns from past coding-agent sessions in a repository to cut token costs by 18.4–30.9% on SWE-Bench without changing the agent or model. Here is what it does, what the numbers say, and where I would be careful.

ai-coding-agentsagentic-aitoken-efficiencyllm-costopen-source

Microsoft Research, with UC Berkeley and Microsoft Security, has released TokenEconomizer, an open-source plugin that learns from a coding agent's past sessions in a repository and uses that history to cut token spend in later sessions. It does not touch the agent or the model, working only through interfaces the agent already exposes. That design choice is the most interesting part of the release.

The problem it targets

Most cost work on coding agents treats each task on its own, but developers return to the same repository daily while the agent starts from zero. The team profiled Claude Code on 60 SWE-Bench tasks run in sequence per repository and found three recurring kinds of waste:

  • Rediscovery. Once a repository had at least five completed tasks, 30% of tool calls repeated an action from an earlier task in that same repository. Only 7% matched another repository's history. The redundancy is local to the repo.
  • Unused tools. The agent was sent 23 tool descriptions on every turn, and 16 of them were never called.
  • Failure loops. The 17% of tasks that failed accounted for 32% of total spend.

They also tested three popular open-source cost-saving plugins, each built around one fixed strategy. Each helped in some repositories and not in others. Their conclusion is that cost control has to adapt to the repository.

How it works

After each session, TokenEconomizer reads the session log, updates what it knows about the repository, and acts through three mechanisms:

TokenEconomizer architecture: an unchanged coding agent writes a session log; the TokenEconomizer controller reads it and updates micro-skills, tool pruning, and failure-loop intervention, which feed back into the agent's next session

  1. Micro-skills. These are one-line, repository-specific notes, such as how to run the tests. A note enters the agent's starting context only after several sessions have confirmed the pattern, and it is retired when later evidence contradicts it.
  2. Tool pruning. Tools the history says are unlikely to be used get dropped. Core tools for running commands and editing files always stay, and pruned tools can be restored.
  3. Failure-loop intervention. A judge model decides whether an agent that keeps hitting the same failure is actually stuck or still making progress. If it is stuck, the agent gets a short note suggesting a different approach. If that doesn't work, the open-source plugin alerts the developer instead of killing the run.

All three mechanisms have a way back. That matters, because a learned optimizer that can't undo its decisions eventually locks in a bad one.

The numbers

The announcement reports the following results:

  • On 277 SWE-Bench tasks across six repositories and five agent-model combinations, starting with no history, mean cost per task fell 18.4–30.9%. Pass@1 rose in four of the five combinations.
  • Costs fell in all 30 repository and agent-model pairs. The authors say the savings count the plugin's own model calls.
  • Early tasks can cost more while it learns. With Claude Code, cumulative cost dropped below the default in every repository by the sixth task.
  • Lowering the model's reasoning effort saved a similar or larger amount, but with substantial performance loss.
  • Costs were 16.0–21.2% lower on sequential web development (Web-Bench), and 6.4–19.6% lower on security auditing, where every task is in a new repository.

My take

This is a research plugin, not a product, and I would treat the numbers as directional. SWE-Bench tasks are well-scoped bug fixes. Real repositories have messier sessions, longer histories, and code that drifts, which is exactly where stale micro-skills could cause harm. The retirement logic is the piece I'd stress-test first.

The direction is right, though. Repetition, unused tool schemas, and stuck loops can all be measured from session logs you already have. TokenEconomizer packages that into a controller that sits outside the agent, needs no API key of its own, and keeps what it learns on the developer's machine. For teams running agents on the same codebases every day, it is a sensible pattern to copy even if you never install the plugin.

The practical takeaway: before you lower reasoning effort to save money, look at your session logs for repetition, unused tools, and failure loops. In this work, that is where the savings came from, with task success broadly stable.

References
  1. 01TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient (Microsoft Research Blog)
  2. 02TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents (paper)