Back home

TokenEconomizer

x+github+web 0.72
Visit source

Intro

TokenEconomizer is an open-source plugin from Microsoft that makes coding agents cheaper to run in repositories you work in repeatedly — without changing the agent or the model. It is described in the paper "TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents" (arXiv 2610.22732) and works with Claude Code, OpenAI Codex, GitHub Copilot CLI and Pi, with experimental opencode support.

The insight: real developers run agents over sequences of tasks in the same repo, and agents keep paying to rediscover the same environment facts, loading tools they never use, and spinning in failure loops. TokenEconomizer learns from past sessions and removes that recurring waste.

Explain

Three mechanisms

  1. Micro-skills – remembers how the repo works (e.g. python -m pytest instead of missing pytest, a build step that must run first, a required env var). Facts are learned from repeated failures and from a periodic model review of recent sessions, injected once three sessions confirm them, and dropped if contradicted.
  2. Tool pruning – tools unused over many prompts/sessions are left out of future sessions via the agent's own settings (every loaded tool definition costs tokens on every request). One command restores them.
  3. Failure-loop guard – when a turn keeps hitting the same failures, a judge model checks if it's stuck (≥0.7 confidence) and injects one redirect note; it never kills a turn itself.

Results (from the paper)

  • 18.4–30.9% lower mean cost on 277 SWE-Bench tasks across five agent–model combos; cheaper in all 30 repo × combo cells, Pass@1 up in 4 of 5.
  • 16–21% savings on Web-Bench and 6–20% on security-auditing benchmarks.
  • All learned data stays local in ~/.tokeneconomizer; its own model calls are included in the reported cost.

Usage

How to install

git clone https://github.com/microsoft/TokenEconomizer.git
# Claude Code
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizer
# Codex
codex plugin marketplace add "$PWD/TokenEconomizer"
codex plugin add tokeneconomizer@tokeneconomizer
# Pi
pi install git:github.com/microsoft/TokenEconomizer
  1. Keep the clone in place (agents run the plugin from it).
  2. Start your agent in a repo and run /tokeneconomizer:status; in Claude Code also run /tokeneconomizer:toolprune refresh-catalog once.
  3. Savings grow as more sessions run in the same repository. See the project page for interactive charts.