TokenEconomizer: How Microsoft's Free Plugin Cuts Claude Code and Codex Costs
TokenEconomizer is an open-source, Apache 2.0 plugin from Microsoft Research, Microsoft Security, and UC Berkeley. It learns from past sessions in a repository, then prunes tools that go unused, states confirmed repo facts at session start, and redirects turns stuck in failure loops. The authors report 18.4 to 30.9 percent lower mean cost on SWE-Bench.
What it is
TokenEconomizer is published at github.com/microsoft/TokenEconomizer under the Apache 2.0 license, with a paper, arXiv 2610.22732, submitted October 15, 2026. The authors are from UC Berkeley, Microsoft Research, and Microsoft Security. The README calls it experience-driven black-box cost control for coding agents: it does not modify the agent, it watches what the agent does in a repository across sessions and adjusts what the next session carries.
It supports Claude Code, Codex, GitHub Copilot CLI, and Pi, with Cursor Agent, opencode, and Hermes Agent marked experimental. On Claude Code it installs as a plugin from its own marketplace. It needs no API key of its own; its model calls run through your agent on your existing plan or login. What it learns stays on your machine in ~/.tokeneconomizer.
The paper's premise is the useful part. Agents are usually benchmarked on isolated tasks, but developers use them continuously on the same project. Run a sequence of tasks in one repository and a class of recurring, environment-specific waste shows up that per-task tricks do not address.
How it cuts cost
The seed question asks whether the saving comes from context, caching, or routing. The answer is context and wasted turns. The README describes no model routing, and it computes cost with cache pricing rather than adding a cache of its own.
Tool pruning. Every loaded tool definition is resent on every turn. A tool unused for 10 prompts across 2 sessions, or across 5 sessions of any length, is left out of the next sessions through the agent's own settings, such as .claude/settings.local.json on Claude Code. A restore command brings tools back. It is on by default. The README notes that changing tools can force a conversation's history to be written to the prompt cache again, which is why the timing of a prune matters.
Micro-skills. Agents rediscover the same repository facts every session, for example that python -m pytest works where plain pytest is missing. Once three sessions confirm a fact, it is stated at session start; a later contradiction drops it. It is off by default because its proposer adds model calls.
Loop guard. A judge model checks a turn that keeps hitting the same failures. At 0.7 confidence or higher, the agent gets one redirect per turn. If it is still stuck, the user is told how to stop it. The guard never ends a turn itself.
None of this is new as an idea. Pruning unused tools is the manual advice in MCP tool search, and stating known facts is what a good instruction file does. The contribution is doing both automatically, from evidence, with thresholds.
What the authors measured
On 277 SWE-Bench tasks from six repositories, across five agent and model combinations, the README reports mean cost 18.4 to 30.9 percent lower, including every model call the plugin made. It was cheaper in all 30 repository and combination cells, and Pass@1 rose in four of five combinations.
Per combination, the README lists Claude Code with Sonnet 5 at 23.6 percent lower cost and Pass@1 up 1.3 points; Claude Code with Opus 4.8 at 30.9 percent lower and down 1.0 point; Codex with GPT-5.6 Terra at 24.7 percent lower and up 0.9; Codex with GPT-5.6 Sol at 26.1 percent lower and up 1.6; and Copilot CLI with Sonnet 5 at 18.4 percent lower and up 2.6.
The README adds other benchmarks: Web-Bench costs fell 16 to 21 percent, and two security-auditing benchmarks fell 6 to 20 percent. These are the authors' measurements on their harness. Treat them as a strong prior, not a guarantee, and measure on your own repository using the method in how to benchmark token savings honestly.
Where it will not help
New repositories. It learns from history. The security benchmarks, where each task sits in a fresh repository, showed the smallest savings. A consultancy jumping between client repos gets less than a team living in one monorepo.
The strongest model. The largest saving, Claude Code with Opus 4.8, came with the only drop in success. That is plausible: a strong model may use tools in ways the usage threshold misreads, or recover from loops the guard interrupts. If you pay for the top model for its success rate, check that trade on your own tasks.
Rare tools that matter. Pruning by usage cannot tell an idle tool from an occasionally critical one. A deploy or database tool used once a week may be pruned. Restore is one command, but someone has to notice.
Agent version gaps. The README notes Codex versions before 0.141.0 do not run plugin hooks, and that in headless runs a flagged turn may run until it ends.
Where it fits with other savings
TokenEconomizer trims the fixed overhead of each turn: tool definitions, rediscovered facts, and failure loops. That stacks with prompt caching in Claude Code, which discounts the repeated prefix, and with retrieval, which removes repeated reading of reference material and past answers. On repeated or reference-heavy work, RDK reports 80 to 90 percent token reduction by retrieving instead of regenerating. The three attack different waste, so measure each separately. The broader playbook is in how to run coding agents cheaper.
The practical path: install it on one repository with steady agent use, leave defaults on, note which tools it prunes in the first week, and compare cost per accepted change before and after.
Frequently asked questions
- Is TokenEconomizer really from Microsoft?
- Yes, in part. The repository sits under the microsoft organization on GitHub, and the README lists authors from UC Berkeley, Microsoft Research, and Microsoft Security. It is a research release with an accompanying arXiv paper, 2610.22732, licensed under Apache 2.0, rather than a supported Microsoft product.
- Does TokenEconomizer use prompt caching or model routing?
- No to both, as mechanisms. It cuts cost by pruning unused tool definitions, stating learned repository facts at session start, and redirecting turns stuck in failure loops. The README computes cost with cache pricing and warns that tool changes can force cached history to be written again, but it adds no cache and routes no models.
- Will TokenEconomizer make Claude Code worse?
- In the authors' tests, success rose in four of five agent and model combinations. The exception was Claude Code with Opus 4.8, which saved 30.9 percent but lost 1.0 point of Pass@1. Watch for pruned tools you occasionally need, and compare accepted changes per dollar on your own repository.
- Does it send data anywhere?
- Per the README, what it learns stays on your machine in ~/.tokeneconomizer, it needs no API key of its own, and it never handles credentials. Its model calls, such as the loop guard's judge, run through your own agent on your existing plan, and their cost is included in its reports.