Researchers from Microsoft Research and UC Berkeley have released TokenEconomizer, an open-source plugin designed to control the costs of programming agents. It learns from past sessions on the same code repository to reduce waste in subsequent sessions. According to the published results, it lowers the average cost of SWE-Bench tasks by 18.4% to 30.9% across 5 agent-model configurations.
Programming agents autonomously execute development tasks, sending a continuous stream of text to the language model, broken down into tokens (the billed text units). Each agent turn re-bills the system prompt, the schemas of each loaded tool, and the complete history. TokenEconomizer sits outside the agent, treating it as a black box: it modifies neither the model weights nor the agent code. It works with Claude Code, Codex, GitHub Copilot CLI, and Pi, on a machine with Python 3.10 or newer, without a GPU or its own API key.
Where the Money Goes
To understand the losses, the researchers analyzed 60 SWE-Bench tasks, spread across 6 repositories, executed with Claude Code and Opus 4.8. They identified three recurring sources of waste. The first is repeated discovery: once 5 previous tasks were completed, 30% of tool calls repeated an action already performed. The second concerns unused tools: 23 tool schemas are loaded each turn, of which 16 are never called, and 3 cover 98% of calls. The third involves failure loops: 10 failed runs accounted for 17% of tasks, but 32% of total spending.
The researchers also tested three existing open-source strategies, RTK, Serena, and Aider’s RepoMap. None were less costly in all cases: all three reduced costs on Django, but increased them on SymPy.
Three Mechanisms
TokenEconomizer maintains, for each repository, a state built from traces of completed tasks, and sets three policies before each task. The first, micro-skills, involves summarizing observations into one-line facts, such as the test command to use. A fact only enters the prompt after 3 confirmations on tasks not modifying the same files, and a contradiction counts as 5, allowing erroneous facts to be quickly removed.
The second policy, tool pruning, always keeps the shell, read, write, and edit tools. Others are hidden after 3 consecutive tasks without use, or when an LLM judge deems them irrelevant. The full catalog returns every 5 tasks for re-evaluation. On Django with Claude Code, the first call of task 2 went from 43,351 to 16,295 prompt tokens.
The third is intervention on failure loops. The controller defines a turn budget equal to 1.25 times the 90th percentile of successful run lengths. Simple rules flag repeated failures, then an LLM judge decides if the agent is stuck, with a confidence of at least 0.7. A stuck agent receives a single redirection, then is stopped if the loop repeats.
Variable Results
On SWE-Bench, the plugin reduced cost in all 30 tested repository-configuration cells, whereas RTK and RepoMap increased it in 12 and 15 cases respectively. The best result is a 30.9% reduction with Claude Code and Opus 4.8, which rises to 33.2% when combined with RTK. The Pass@1 rate, which measures success on the first try, improved in 4 out of 5 configurations, but declined by 1.0 point with Opus 4.8. Savings are most evident over time: most repositories were more expensive initially, but all were cheaper by the sixth task.
The plugin is released under the Apache 2.0 license. The learned data stays local, in the ~/.tokeneconomizer folder, and it installs on Claude Code from the project’s GitHub repository. Tool pruning and loop guarding are enabled by default, while micro-skills are disabled, as their proposer adds model calls.





