
TokenEconomizer
A plugin that makes coding agents cheaper in the repos you use most
Description
The expensive part of running a coding agent often isn't the code it writes. It's every new session relearning the same repository: how tests run, which command actually works on this machine, what has to be built first. Yesterday's questions get asked again today, and every turn is billed.
TokenEconomizer, open-sourced by Microsoft Research and UC Berkeley, doesn't swap the model or modify the agent. It learns from the sessions you've already finished in a repository and uses that to trim waste from the ones that follow.
It distills repository facts from failures that recur across sessions, such as using
Tool pruning: stop loading tools nobody uses
Every loaded tool's definition rides along with every request. A tool left unused for 5 sessions, or for 10 prompts spread over at least 2 sessions, is left out of the next session through the agent's own settings. One command brings it back.
Failure-loop intervention: nudge a stuck turn
When a turn keeps hitting the same failure, a judge model checks whether it's stuck. At 70% confidence or more, the agent gets a short note to try another approach, at most once per turn. If it's still stuck, you're told how to stop it; the plugin never stops a turn itself.
It officially supports Claude Code, Codex, the GitHub Copilot CLI and Pi, with experimental support for opencode, Cursor Agent and others. It needs Python 3.10+ and no extra API key: its model calls go through your agent's existing plan or login, and everything it learns stays on your machine in
For Claude Code, clone the repo, then run
TokenEconomizer, open-sourced by Microsoft Research and UC Berkeley, doesn't swap the model or modify the agent. It learns from the sessions you've already finished in a repository and uses that to trim waste from the ones that follow.
Three ways it saves
Micro-skills: remember how the repo worksIt distills repository facts from failures that recur across sessions, such as using
python -m pytest where pytest is missing. A fact is added to each session's opening context only after three sessions confirm it, and dropped when later sessions contradict it.Tool pruning: stop loading tools nobody uses
Every loaded tool's definition rides along with every request. A tool left unused for 5 sessions, or for 10 prompts spread over at least 2 sessions, is left out of the next session through the agent's own settings. One command brings it back.
Failure-loop intervention: nudge a stuck turn
When a turn keeps hitting the same failure, a judge model checks whether it's stuck. At 70% confidence or more, the agent gets a short note to try another approach, at most once per turn. If it's still stuck, you're told how to stop it; the plugin never stops a turn itself.
Results and where it fits
The paper ran five agent–model combinations on 277 SWE-Bench tasks across 6 repositories. Mean cost fell 18.4% to 30.9%, and all 30 repository × combination cells came out cheaper, with the plugin's own model calls counted. On security-audit benchmarks where every task is in a new repository, savings were only 6% to 20%, so it pays off most when you work in the same repo day after day.It officially supports Claude Code, Codex, the GitHub Copilot CLI and Pi, with experimental support for opencode, Cursor Agent and others. It needs Python 3.10+ and no extra API key: its model calls go through your agent's existing plan or login, and everything it learns stays on your machine in
~/.tokeneconomizer.For Claude Code, clone the repo, then run
claude plugin marketplace add /path/to/TokenEconomizer and claude plugin install tokeneconomizer@tokeneconomizer. Keep the clone in place, since the plugin runs from it. Licensed under Apache-2.0.
