The paper

TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents, by Aaron J. Li, Weijia Xu, Chandan Singh, Zixiao Chen, Jeevana Priya Inala, Charlotte Siska, Acar Tamersoy, Bin Yu, Ion Stoica, Michel Galley and Jianfeng Gao. The paper lists UC Berkeley, Microsoft Research and Microsoft Security as affiliations, and notes the first author's work was done during an internship at Microsoft Research. Version 1 was posted to arXiv on 15 October 2026. Read it at arXiv 2610.22732. The code is public on GitHub under an Apache-2.0 licence.

The finding in plain English

Most tests of coding agents treat each task as a one-off. Real use looks different: you point Claude Code or Codex at the same repository day after day, and it relearns the same things each time, on your bill. The authors measured that waste and then built an outside controller that removes it.

Across Claude Code, Codex and GitHub Copilot CLI, the controller cut average token cost by 18.4-30.9% with comparable task success on a stream of SWE-Bench bug fixes. On sequential web-development and security-audit tasks, the savings were smaller, at 6.4-21.2%. The reported costs include the controller's own model calls, so they are net figures.

Success did not drop in a meaningful way. On SWE-Bench, Pass@1 improved in four of the five agent-model setups and fell by 1.0 percentage point in the fifth (Claude Code with Opus 4.8).

Where the waste comes from

Before building anything, the team looked at where tokens were going. Three patterns stood out in the paper's analysis:

  • Tools nobody calls. The agent was shown 23 tool schemas on every turn, yet no repository invoked more than 7. Every unused schema is text the model reads, and you pay for, on every single turn.

  • Rediscovering the same facts. Actions that recurred in at least half of a repository's tasks made up 12-28% of the bytes going through tool calls. That is the agent working out, again, which test command runs or where the source lives.

  • Failure loops. Ten failed runs were 17% of the tasks but 32% of the total spend, and across 60 analysed tasks, 51% of spend came after a trajectory first started repeating itself.

How they did it

TokenEconomizer treats each agent as a black box. It does not retrain the model or change the agent's own loop. It works only through what any user can touch: the prompt, the tool settings and the stream of events the agent emits. It has three levers.

1. Micro-skills. After each finished task, the controller condenses the run into a digest, and a model drafts short "micro-skills": single operational facts about one repository, such as which test runner works, where the sources live, or which setup step is unnecessary. Later tasks either confirm or contradict each skill. Confirmed skills are injected; contradicted ones are retired.

2. Tool pruning. Tools that go unused for a set number of consecutive tasks are removed from the agent's tool list. A model judge can also drop clearly irrelevant tools, and a periodic re-audit restores the full catalogue so nothing stays hidden for ever.

3. Failure-loop interruption. The controller sets a turn budget based on past successful runs. When a run exceeds it, a model judge decides whether the agent is actually stuck. The first "stuck" verdict sends a short redirect; a repeat verdict ends the run.

The experiments used Claude Code (Sonnet 5 and Opus 4.8), Codex (GPT-5.6 Terra and Sol) and Copilot CLI (Sonnet 5). Tasks were 277 SWE-Bench fixes across six Python repositories including Django, scikit-learn and Matplotlib, 102 Web-Bench tasks across five projects, and 100 tasks each from the CredData and ReposVul security datasets.

Which lever mattered most

The ablation on Claude Code is the most useful table in the paper for a solo builder. On Sonnet 5, micro-skills alone cut cost by 11.8%, tool pruning by 13.2% and the loop guard by 7.1%, for 23.6% combined. On Opus 4.8 the figures were 14.3%, 17.7% and 5.4%, for 30.9% combined. Tool pruning was the biggest single lever in both, and success stayed within 3 points of the default for every variant.

Why it matters

Builders pay for agents per token, across weeks of work on the same codebase. A saving that holds over a stream of tasks is worth more than a clever trick on one benchmark. In the paper, every one of the six SWE-Bench repositories ended up cheaper, with cumulative savings of 16.9-32.0%.

The levers are also ordinary. None needs model access, fine-tuning or a new agent. Two of them, a tighter tool list and a short file of repo facts, are things you can set up by hand this afternoon. That matches what we saw in coding agents fixing more bugs when you paste whole files: what you put in the context, and what you leave out, changes both cost and quality.

Caveats

  • There is a warm-up period. In the paper, every SWE-Bench repository except xarray initially cost more under TokenEconomizer, and all became cheaper by the sixth task. The gains depend on doing repeated work in the same repository.

  • The task streams were not real sessions. The authors say their SWE-Bench streams "consist of related but independent fixes rather than actual user sessions." Your mixed, messy day may behave differently.

  • Every lever can misfire. The paper lists the failure modes itself: a stale skill, a wrongly pruned tool, or a productive run mistaken for a loop. Stale notes are a known risk; see why saved lessons can make agents repeat mistakes.

  • Security savings were thin. ReposVul costs fell only 6.4-9.3%.

  • The released plugin differs from the paper's set-up. The GitHub README says micro-skills are off by default because they add model calls, and the loop judge only sends a redirect; it never stops a turn itself. Your results will not match the paper's numbers out of the box.

How builders and ordinary people can use it today

Option A: install the plugin

The microsoft/TokenEconomizer repository ships plugins for Claude Code, Codex, Copilot CLI and Pi, each tested against a specific version range. It needs Python 3.10 or newer and uses your agent's existing sign-in, so there is no extra API key. For Claude Code, Codex and Copilot CLI, install it from a local clone via the agent's plugin marketplace command (Pi installs straight from GitHub), then run the status command to confirm it is active.

Option B: copy the three levers by hand

This checklist works with any coding agent, plugin or not.

  1. Measure first. Pick one repository you use often. Note the token count or cost of your next five tasks so you have a baseline.

  2. Audit your tools. List every MCP server and tool your agent loads. Disable any you have not used in that repo in the past week. The paper's numbers suggest this is the biggest single win.

  3. Write a short repo notes file. Put the operational facts your agent keeps rediscovering into the repo's agent instructions file (CLAUDE.md, AGENTS.md or similar): the exact test command, where the source lives, which setup steps to skip. Keep each line to one fact.

  4. Review those notes monthly. Delete any line that is no longer true. A wrong note costs more than a missing one.

  5. Set a loop rule. Add an instruction such as "If the same command or fix fails twice, stop and summarise what you tried before continuing." Then actually stop runs that go round in circles rather than letting them burn tokens.

  6. Break big jobs into smaller tasks. Shorter runs are less likely to spiral and easier to judge when they do.

  7. Measure again after five tasks. Compare against your baseline. Keep what saved money; roll back anything that hurt results.

An illustrative example, not from the paper: if you spend about $200 a month on one agent in one repo, a 20% cut would save about $40 a month. Your own figure depends on how repetitive your work is.

For more on harnesses that improve themselves task by task, see our breakdown of Harness 2.

Sources

Comments

Avatar

or to participate