microsoft/TokenEconomizer
TokenEconomizer
Experience-Driven Black-Box Cost Control for Coding Agents
GitHub metrics
- Stars
- 8K
- +1.3K this week
- Forks
- 564
- 30-day growth
- —
- Open issues
- 20
| Day | GitHub stars |
|---|---|
| 2026-11-09 | 5490 |
| 2026-11-16 | 6656 |
| 2026-11-23 | 7981 |
What it does
TokenEconomizer cuts the bill for AI coding agents when you keep using them on the same codebase. It plugs into an existing agent, studies each finished session, and applies what it picked up to later ones, while the agent's model and code stay untouched.
The plugin has three parts. The first records small facts about a project (say, that tests need python -m pytest because bare pytest is missing) and hands them to the agent when a session opens, once three sessions agree on a fact. The second spots tools a project never calls and switches them off in the agent's config, so their definitions stop riding along with each request. The third looks for a turn that keeps failing the same way. A judge model rates it, and if it looks stuck the agent receives a nudge to change course. Ending the turn stays with you.
Four agents have full support: Claude Code, Codex, GitHub Copilot CLI and Pi. Five more are experimental, among them Cursor Agent and opencode. The authors' paper tested five agent and model pairings on 277 SWE-Bench tasks and reports mean cost down 18.4 to 30.9%, with Pass@1 higher for four pairings. The only release so far, 0.1.0, is dated October 26, 2026.
Why it matters
Each turn an agent takes resends its system instructions, the definitions of all loaded tools and the chat history, and people tend to point one agent at one codebase over and over. That makes a lot of spending repetitive. TokenEconomizer goes after the repetition and leaves the model alone: it adds facts to the opening context and edits tool settings, both things the agent reads anyway. The extra model calls it makes go through your agent's own login and show up in its cost reports.
Main features
- Records per-project facts and passes them to the agent at session start
- Turns off tools a project never uses, through the agent's settings
- Judge model flags stuck turns; one corrective note per turn by default
- Separate on/off switch for each part, per project or machine-wide
- Status command reports learned facts, actions taken and session spend
- Keeps everything it learns locally under ~/.tokeneconomizer
- Can read older Claude Code session logs, with no model call, when enabled
- Pruned tools come back with one restore command and stay back
Who it's for
- Anyone who opens Claude Code, Codex, Copilot CLI or Pi in the same few codebases day after day
- Users who want lower agent spend while keeping the agent they already use
- Researchers in agent efficiency, since the repo ships the code to rerun the paper's benchmarks
Strengths
- Extra model calls bill to the plan or login your agent already uses, and the reports include them.
- A failure inside the plugin leaves your session running as though it were absent.
- Changes can be reversed: facts drop out when later sessions disagree, pruned tools can return, and only you end a turn.
- Pure standard-library Python, with tests that run offline.
Limitations
- Each agent is supported only within a tight version window (Claude Code 2.1.300 to 2.1.310, for instance), and releases past that window are untested.
- Pi and all five experimental agents get no tool pruning; on the Antigravity CLI only the model-free facts work.
- Cursor Agent and the Antigravity CLI run on macOS and Linux only, and Cursor sessions show no cost figure.
- Micro-skills ships switched off since it costs extra model calls, and the README says its payoff varies by project.
Getting started
Requirements: Python 3.10+ on PATH plus a supported agent you are already signed in to; no separate API key.
Always follow the official instructions in the README on GitHub. This overview is our summary, not a copy.
Sources
- microsoft/TokenEconomizerRepositoryPrimarygithub.com
- github.com/microsoft/TokenEconomizer/releases/tag/v0.1.0RepositoryPrimary