TokenEconomizer
Experience-driven black-box cost control: a plugin that learns from your repository's past sessions to make coding agents like Claude Code, Codex and Copilot CLI cheaper without changing the agent.
- Source repo
- microsoft/TokenEconomizer
- Stars
- ★ 8k
- Last updated
- 3d ago
- FARS reviewed
- Nov 01, 2026
- License
- MIT
- Primary language
- Python
- FA score
- 64/100 · Some gaps
At a glance
- How it runs
- Works with
- Portable with changesCodex · Claude Code
- Cost
- Free software; you pay for model usage
- Setup effort
- Low · running in minutes
- You'll need
- Typical use
- Individual developers running Claude Code or Codex daily on the same repositories who want measurably lower bills
- Not a fit if
- Users expecting identical full features across all coding agents: mechanism coverage differs per host
- Teams running unsupported or untested versions of Codex, Copilot CLI, etc.
- Users relying on tool pruning with hosts like Pi or Factory Droid that lack persistent tool settings
- Maintenance
- Commits in the last 30 dayslast commit 2026-11-20+131.9 ★/day over 7 days
- Source review
- 64/100 · Some gaps
What does this agent do, and when should you use it?
TokenEconomizer is an open-source (MIT) plugin from Microsoft Research, Microsoft Security and UC Berkeley that makes coding agents cheaper to run in repositories you work in often, without touching the agent's model, weights or code. It has three mechanisms: micro-skills distills repository facts (like a working command such as python -m pytest) from finished sessions and injects them at session start; tool pruning drops tools that go unused across sessions through the agent's own settings files; and failure-loop intervention (the loop guard) has a judge model redirect turns that are stuck. It ships as a plugin for Claude Code, Codex, the GitHub Copilot CLI and Pi, with experimental support for opencode, Cursor Agent, Grok Build and others. In the paper's measurements across 277 SWE-Bench tasks, mean cost fell 18.4–30.9% across five agent–model combinations, cost was lower in all 30 repository × combination cells, and Pass@1 rose in 4 of 5. What it learns stays on your machine in ~/.tokeneconomizer, and its own model calls run through your logged-in agent with no separate API key.
The plugin uses each agent's hooks to read session logs (tokeneconomizer/trace normalizes every host's log into one shape) and updates all three mechanisms after each finished session. Micro-skills learns facts from failures that repeat across sessions and from a fact proposer that reviews recent sessions every k=3 sessions; a fact is injected at session start once three sessions confirm it and dropped when contradicted. Tool pruning counts tools unused over p=10 prompts spanning at least m=2 sessions, or s=5 sessions, and after q=60 idle minutes writes a deny list through the agent's own settings (Claude Code's .claude/settings.local.json, Codex's .codex/config.toml, Copilot CLI's MCP servers); toolprune restore gives tools back. The loop guard learns a per-repository envelope of usual turn length, sends turns showing repeated failures to a judge model (confidence c=0.7), and injects a redirect at most r=1 times per turn; if still stuck it tells you how to stop the turn and never stops one itself. You inspect and tune everything with status, microskills, toolprune, config commands (/tokeneconomizer:... in Claude Code, $tokeneconomizer:... in Codex, /te in Pi), and cost is computed with cache pricing including the plugin's own calls.
- Individual developers running Claude Code or Codex daily on the same repositories who want measurably lower bills
- Teams whose sessions keep rediscovering the same build steps, commands and environment variables and want that knowledge retained across sessions
- Copilot CLI users with many loaded MCP servers or tools but only a few actually used, so unused tool definitions stop riding on every request
- Automated repair pipelines where agents burn tokens in repeating failure loops and the loop guard can redirect in time
- Researchers who want to evaluate in read-only modes (toolprune=propose, microskills=envfacts) or rerun the paper's benchmarks via experiments/
Key setup facts
Pulled from the install and usage notes below. The project README has the current values.
- Config files
~/.tokeneconomizer/bin/te- Runtime
- Python 3.10+
How do you install or deploy this agent?
You need one of the supported agents, signed in any way it supports, and Python 3.10+ on PATH. The plugin needs no API key of its own.
Claude Code:
git clone https://github.com/microsoft/TokenEconomizer.git
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizerCodex:
git clone https://github.com/microsoft/TokenEconomizer.git
codex plugin marketplace add "$PWD/TokenEconomizer"
codex plugin add tokeneconomizer@tokeneconomizerCopilot CLI:
git clone https://github.com/microsoft/TokenEconomizer.git
copilot plugin marketplace add "$PWD/TokenEconomizer"
copilot plugin install tokeneconomizer@tokeneconomizerPi:
pi install git:github.com/microsoft/TokenEconomizerAfter installing, run once per machine (and again after Claude Code / Copilot CLI updates):
/tokeneconomizer:toolprune refresh-catalogExperimental hosts (opencode, Cursor Agent, Grok Build, Hermes Agent, Antigravity CLI, Factory Droid) have separate install steps documented in the repo README and plugin/README.md.
How do you use this agent?
After installing, just work as usual. To see or change behavior, use the commands (same names everywhere, different typing): /tokeneconomizer:status or /tokeneconomizer:config set microskills=on in Claude Code / Copilot CLI, $tokeneconomizer:status in Codex, /te status in Pi, or from a terminal for opencode / Cursor / Grok / Hermes / Antigravity:
~/.tokeneconomizer/bin/te --host <host> statusCommands from a terminal are free; inside an agent they cost one model turn. Key commands: status (what it learned and session costs), microskills (injected and forming facts), toolprune (removed tools and evidence), toolprune restore (give tools back), config (view or change settings). Defaults: tool pruning and loop guard on, micro-skills off. Per-session switches include TE_DISABLE=1 claude and TE_LOOPGUARD=off codex.
Safety boundaries, hardening & integrations
Operational blast radius, source-verified safety controls, and first-run hardening steps before connecting this agent to real workspaces.
Declared capability surface (blast radius)
Can run terminal commands; pair with approval gates or container/OS sandboxing.
Modifies local files; work on a clean Git branch or dedicated worktree.
Makes outbound requests; verify telemetry settings and model data routing on private repos.
What are this agent's strengths and limitations?
- Black-box by design: works through context the agent already reads and the agent's own settings, so the agent never needs to learn a new tool
- Paper-backed evidence: on 277 SWE-Bench tasks mean cost fell 18.4–30.9% across five combinations, cheaper in all 30 repository × combination cells, Pass@1 up in 4 of 5
- Every action is reversible and protected: facts need three confirming sessions and are dropped when contradicted, removed tools are restorable, the loop guard only redirects
- Local-only learning in ~/.tokeneconomizer; its model calls ride your existing login, need no new API key, and are included in its cost reports
- Feature coverage differs per host: tool pruning works only on Claude Code, Codex and Copilot CLI, and is unavailable on Pi, Grok Build, Factory Droid and several others
- Experimental hosts (Cursor, Grok, Antigravity, Hermes, Droid) rely on undocumented hook contracts, cover narrow version ranges, and have documented limits
- Savings depend on reusing the same repository: one-off tasks or fresh repos benefit little, and micro-skills is off by default because its proposer adds model calls
- The loop guard never stops a stuck turn itself; in headless runs an unattended flagged turn runs until it ends
How does this agent compare with similar options?
Key facts side by side with the most closely related agents.
| Agent | Source review | Form / cost | Stars | Updated | Language | Full support on |
|---|---|---|---|---|---|---|
| TokenEconomizer This agent | 64 · Some gaps | Agent plugin / skillFree + model costs | ★ 8k | 3d ago | Python | Codex · Claude Code |
| RTK Command Output Optimizer | 72 · Some gaps | CLIFree | ★ 88k | today | Rust | Codex · Claude Code |
| Cheap Agent | 57 · Major gaps | CLIFree + model costs | ★ 342 | today | TypeScript | Codex · Claude Code |
| Chisle | 77 · Good | CLIFree + model costs | ★ 1.3k | today | JavaScript | Codex · Claude Code |
How does FollowAgents rate this agent?
Why each dimension lost points
README states the plugin holds no API key and never handles credentials, routing model calls through the user's own agent login; tool pruning only appends its own entries, never touches user deny rules, keeps created settings files out of git via .git/info/exclude, and is reversible via toolprune restore with restored tools not removed again; the loop guard only redirects and tells the user to stop, never stopping a turn itself. These are documentation-level claims not executed in this static review, so trust criteria score 2 rather than 3.
pyproject.toml declares dependencies=[] with a stdlib-only package, pytest only for tests, and optional extras that are empty or explicitly labeled; README gives supported version ranges per agent and notes older-version behavior, and states that on failure the session carries on as if the plugin were not installed. Concrete failure-message formats and error-handling code are not shown in the evidence, so 2.
README covers Claude Code, Codex, Copilot CLI, Pi and experimental opencode, documenting per-agent tool-pruning capability differences, command syntax differences, where notices appear and how to stop turns in headless runs, plus TE_DISABLE-style env vars for per-session toggles; trigger thresholds (k/p/m/s/c/r/b) all have defaults and explanations. opencode support is labeled experimental and untested in the 2.x TUI, which is disclosed boundary rather than a defect.
README is well structured with install, update, supported versions, command table, settings table, repository layout, citation and license; LICENSE is full Apache-2.0; SECURITY.md gives a vulnerability reporting path; package.json and pyproject.toml both at 0.1.0. Deduction: no CHANGELOG or version history, and version is only 0.1.0, so versioning_changelog scores 1.
README reports 18.4–30.9% lower cost on SWE-Bench, cheaper in 30/30 cells, Pass@1 up in 4/5 combinations, with cost including the plugin's own model calls and cache pricing; status/microskills/toolprune/config commands let users inspect learned facts and costs. These are author-reported measurements not reproduced here, so 2.
README maps each mechanism to concrete thresholds, defaults and written file paths, and links docs/PLUGIN.md, docs/ARCHITECTURE.md, experiments/README.md and the arXiv paper, making claims traceable; cross-source corroboration is limited to in-repo docs and a paper link with no independent third-party verification, so cross_source_corroboration scores 1. For fact_inference_separation, README distinguishes measured results from design principles and flags opencode as experimental and partly untested, giving basic separation of fact and inference.
- This is a static source review with no installation or execution; the cost and Pass@1 figures in README are author-reported and not independently reproduced.
- The plugin edits local agent settings files (e.g. .claude/settings.local.json, .codex/config.toml, .github/copilot/settings.local.json); confirm these are not tracked by the repository or already carrying custom rules before installing.
- opencode support is labeled experimental, tested only on 1.19.5 and 2.2.0 and not in the 2.x terminal UI; use with caution in production.
- Micro-skills is off by default; enabling it adds model calls and cost, so weigh it against the repository and workload.
- The repository is at version 0.1.0 with no CHANGELOG, so upgrade paths and breaking-change records are incomplete.
FAQ
How are the plugin's own model calls billed?
Does my data leave my machine?
Could it break my tasks?
Which agents and versions are supported?
Can I try it before committing to its behavior?
Is TokenEconomizer free?
Is TokenEconomizer open source?
Is TokenEconomizer safe to use?
Is TokenEconomizer still maintained?
Who makes TokenEconomizer?
Thanks — we use this to improve the page.
Subscribe to the FollowAgents RSS feed, or save this agent to your browser shortlist to compare on your next visit.