Developer tools#Coding agent

TokenEconomizer: per-repo lessons that cut coding-agent costs

TokenEconomizer, a Microsoft plugin, learns per-repo facts, prunes idle tools and breaks failure loops in coding agents; Microsoft reports 18.4–30.9% cost cuts.

Project facts

GitHub Ecosystem
Repositorygithub.com/microsoft/TokenEconomizer
License
Apache-2.0
Language
Python
Stars
7,062
Data checked
2026-11-17

Snapshot figures reflect the check date and may change over time.

Anyone who runs a coding agent in the same repository for a week has seen the bill: every session rediscovers the test command, every request carries tool descriptions nobody calls, and a turn stuck on the same error keeps paying for it. TokenEconomizer is an Apache-2.0 plugin from Microsoft Research and UC Berkeley that leaves the model and the agent code untouched and learns three policies for each repository from finished session logs. The repo was created on October 13, 2026 and had 7,062 stars on November 17, 2026.

How TokenEconomizer sits beside an unchanged coding agent: micro-skills inject repository facts at session start, tool pruning drops idle tools from the next session, and the loop guard adds a redirect when failures repeat

Core features

  • Micro-skills remember the repository. The plugin learns one-line facts such as “run tests with python -m pytest here” from failures that recur across sessions, plus candidates proposed by a model that reviews recent sessions every three sessions. A fact is injected at session start only after three sessions confirm it, and is dropped when later evidence contradicts it. It is off by default because the proposer costs model calls.
  • Tool pruning stops shipping idle tools. A tool that goes unused over 10 prompts spread across at least two sessions, or over five sessions of any length, is removed from later sessions through the agent’s own settings: single tools in Claude Code, capability packages in Codex, whole MCP servers in the Copilot CLI. toolprune restore brings them back, and a restored tool is never removed again.
  • Failure-loop intervention calls a model only when a turn looks stuck. The guard first learns how long a normal turn runs in this repository, then rule checks flag repeated failures, dense errors or a run far past that length. Only then does a judge model look, and at 0.7 confidence or higher the agent gets one redirect per turn suggesting another approach; if it stays stuck, the plugin tells you to press Esc rather than ending the session itself.
  • Black-box integration. It works through the instruction prefix, the loaded tool set and the live event stream the agent already exposes, never through weights or agent-loop code. Its own model calls run on your existing login or plan, and their cost is counted in its reports.
  • What it learns stays local. Facts and tool evidence live in ~/.tokeneconomizer. The plugin needs no API key of its own and never handles credentials.

Benchmarks

Microsoft’s headline result covers 277 SWE-Bench tasks from six repositories across five agent–model combinations: mean cost fell 18.4–30.9%, all 30 repository-by-combination cells got cheaper, and Pass@1 rose in four of the five. Every figure includes the plugin’s own model calls.

Test (Microsoft’s own runs)Result
SWE-Bench, 277 tasks, 6 repos × 5 combinationsmean cost −18.4% to −30.9%; cheaper in 30/30 cells; Pass@1 up in 4/5
Web-Benchcost −16.0% to −21.2%
Security-auditing benchmarks, a new repo per taskcost −6.4% to −19.6%
Ablation on Claude Codetool pruning 13.2–17.7%, micro-skills 11.8–14.3%, loop guard 5.4–7.1%

The paper’s profiling explains where the money goes. Across 60 Claude Code tasks, once a repository had five or more tasks behind it, 30% of tool calls repeated an action from an earlier task; each turn carried 23 tool descriptions, 16 of which were never called; and the 17% of tasks that failed consumed 32% of the spend. One combination, Claude Code with Opus 4.8, lost 1.0 point of Pass@1, the only one of the five that did.

The fixed-strategy comparison is the argument for learning per repository. On the same tasks, RTK, which compresses command output, was more expensive in 12 of 30 cells (range −8.9% to +4.5%); Aider’s RepoMap was more expensive in 15 (range −6.1% to +6.5%). RTK, Serena and RepoMap all saved on Django and cost more on SymPy.

Typical use cases

  • A developer who maintains a handful of repositories for months. The same test command, build order and unused tools come back every session, which is exactly the experience micro-skills and tool pruning can bank.
  • Teams paying per token or hitting weekly caps. Run te status in a couple of repositories and compare the reported cost against a week without the plugin before turning on micro-skills, which is off by default.
  • Anyone evaluating token-saving plugins. The te status, te savings and te toolprune commands report what was removed or injected and what sessions cost, including the plugin’s own calls, so the claim is checkable rather than a dashboard number.

Quick start

You need Python 3.10 or newer on PATH and one supported agent already signed in; the plugin needs no API key of its own. For Claude Code, from the README:

git clone https://github.com/microsoft/TokenEconomizer.git
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizer

Start claude, trust the folder, and run /tokeneconomizer:status to see what it learned here; run /tokeneconomizer:toolprune refresh-catalog once per machine and again after each Claude Code update. Codex and the Copilot CLI swap in codex plugin and copilot plugin; Pi is a single pi install git:github.com/microsoft/TokenEconomizer, followed by /te status.

Supported versions are pinned: Claude Code 2.1.300–2.1.310, Codex 0.153.1–0.164.0, Copilot CLI 1.0.83–1.0.102, Pi 1.2.0–1.3.0, with nothing guaranteed outside those ranges. Cursor, Grok Build, opencode, Hermes Agent, the Antigravity CLI and Factory Droid are experimental, and the README names each gap: Grok and Hermes get no tool pruning, Cursor cannot report session cost, and Antigravity only learns facts that need no model call.

Summary

TokenEconomizer fits people who run Claude Code, Codex or the Copilot CLI in the same repositories every day and will let it watch a few sessions first. Its angle differs from Headroom, which compresses tool output before it reaches the model: this plugin changes what the next session starts with, not what the current request contains. It also differs from billion-context, which folds conversation history; TokenEconomizer distills repository-level lessons into a few facts and a tool list. Apache-2.0, written in Python, five weeks old, and still moving fast.

Three things to know before installing. The savings are Microsoft’s own measurements, and the first few tasks in a repository can cost more because the plugin has no history yet. Micro-skills is off by default, and turning it on adds proposer calls to your bill. Independent testing lands well below the headline: CyberQ ran 288 Claude Code sessions and measured 6.2% per round and 10.8% at steady state with Sonnet 5.5 on default settings, or 13.0% and 22.4% with everything on after fixing the auxiliary model. With the default haiku alias, those auxiliary calls were billed at Sonnet rates and the setup cost 2.9% more than no plugin at all until the full model ID was set. That test also ran Claude Code 2.1.314, outside the validated range. Narrow version windows and a long list of experimental hosts make this a project worth watching, not a set-and-forget cost switch.