Overview
TokenEconomizer is an open cost controller from Microsoft Research, UC Berkeley and Microsoft Security. It treats coding agents as a black box, learns from the sessions an agent has already run in a repository, and uses that experience to cut waste in the sessions that follow. It changes no model weights and no agent code, working only through prompts, tool settings and the event stream.
The waste comes from three places, all measured in the paper. On a repository used repeatedly, once five tasks precede the current one about 30 percent of tool calls repeat an earlier action. Every request ships more than twenty tool definitions, and most are never called. Failure loops account for 10 of 60 analysed runs but 32 percent of total spend. Each waste pattern maps to a mechanism.
Micro-skills record repository facts one line at a time, such as running python -m pytest when pytest is missing, injected only after three sessions confirm them and retired when later sessions contradict them. Tool pruning drops tools that go unused across sessions and restores them with one command. The loop guard redirects once when a turn looks stuck, then tells you how to stop. State lives in ~/.tokeneconomizer on your machine, and the controller's own model calls are included in its cost reports.
Key Features
- Micro-skills for repository facts: Distils one-line operational facts from repeated failures and periodic session reviews, injecting them at session start after three confirmations.
- Tool pruning: Removes tools that stay unused across sessions from the tool list, cutting thousands of definition tokens per turn, restorable with one command.
- Failure-loop guard: When a turn exceeds its budget, a judge model decides whether the agent is stuck, injects one redirect and then explains how to stop.
- Black-box integration: Works through prompts, tool settings and events without touching weights or agent code, and a failing component leaves the session as if it were never installed.
- Learn per repository: Experience is stored per repository on the local machine, so projects do not bleed into each other and long-running work compounds the savings.
- Its own cost is counted: Model calls for proposing facts and judging loops run through your agent login and appear in the reports, so the numbers are net.
Use Cases
- Daily work in one monorepo with Claude Code or Codex, where the agent keeps rediscovering the same quirks.
- Teams codify repository conventions into facts about test commands, environment variables and generated file locations.
- Long sessions that tend to wander get a redirect before they burn budget.
- Repositories with many tools but few used ones stop paying for unused definitions every turn.
- Cost reviews compare bills with and without the plugin, per repository.
- Security auditing tasks keep the per-run spend bounded.
Pros
- Mean per-task cost falls 18.4 to 30.9 percent across five agent and model combinations on SWE-Bench.
- All 30 repository and combination cells got cheaper, not just a single repository.
- Pass@1 improved in four of five settings, so the savings did not come at the cost of success.
- Each mechanism has its own switch, so you can enable one at a time.
- No model or agent code changes, since installation is a plugin.
- State stays on the local machine, so repository knowledge never leaves.
Pricing
Open source under Apache 2.0 as a standard-library Python package with plugins per agent, requiring Python 3.10 or newer and needing neither a GPU nor its own API key. Supported agents are Claude Code, Codex, the GitHub Copilot CLI and Pi, with opencode support still experimental. Learned state lives in ~/.tokeneconomizer. Tool pruning and the loop guard are on by default while micro-skills is off, and an envfacts mode learns only from repeated failures without model calls. Status is available through /tokeneconomizer:status.
Summary
Half of a coding agent's bill is spent on repetition: the same repository, the same conventions, relearned by every new session. TokenEconomizer's judgement is that this belongs to the repository rather than the model, so experience is stored locally, injected on demand, and unused tool definitions are removed from each request. The 30 percent it saves is not squeezed out of a context window but comes from not repeating the same mistakes.
Version History
- TokenEconomizer listed: cost control for coding agents (2026-10-31): Form at listing: an open cost controller from Microsoft Research, UC Berkeley and Microsoft Security under Apache 2.0. Three mechanisms learn repository facts through micro-skills, prune tools that stay unused and guard against failure loops. Supports Claude Code, Codex, the GitHub Copilot CLI and Pi, with experimental opencode support. Across 277 SWE-Bench tasks and five agent and model combinations, mean per-task cost drops 18.4 to 30.9 percent, all 30 repository and combination cells get cheaper and Pass@1 improves in four of five. State is stored locally in ~/.tokeneconomizer and its own model calls are counted in the reports.