ByteCosts
tokeneconomizer-coding-agent-cost-control.mdx

AI Coding Agents

TokenEconomizer Review: Experience-Driven Cost Control for Coding Agents

TokenEconomizer is a Microsoft Research plugin for coding agents including Claude Code, Codex, Copilot CLI, and Pi. It learns repository facts across sessions, prunes tools that went unused during a configured observation window on supported hosts, and can redirect turns that appear stuck. The authors report 18.4% to 30.9% lower mean cost across five agent-model pairs on 277 SWE-Bench tasks, with Pass@1 up in four of five.

At a glance

QuestionAnswer
What is it?A research plugin that learns repository facts, prunes unused tools on supported hosts, and can redirect stuck turns.
What cost does it target?Repeated discovery, input from unused tool definitions, and turns spent repeating failures.
Where does it act?Through the coding agent’s own hooks and settings.
How do you try it?Install from a local clone for Claude Code, Codex, or Copilot CLI. Pi has a Git install route.
Can you restore pruned tools?The tool-pruning restore action puts them back in the agent’s settings before uninstall.
What license is stated?MIT.
What is its maturity signal?8,255 stars and 62 open issues as of November 30, 2026.
When is it a good fit?You revisit the same repositories often or load many tools the agent rarely calls.

What TokenEconomizer is and which cost layer it targets

Compression tools shrink what a call contains; TokenEconomizer shrinks what a session wastes. The README names three waste sources: re-learning the same repository facts every session, sending tool definitions that never get called, and turns that churn through identical failures. It is “black-box” in the paper’s sense: the agent’s model, weights, and code are untouched, and the plugin acts only through the agent’s own hooks and settings.

The project is Python, MIT licensed, authored by UC Berkeley, Microsoft Research, and Microsoft Security, with a paper on arXiv (2610.22732). It was created October 13, 2026, released v0.1.0 on October 26, and as of November 30, 2026 has 8,255 stars, 588 forks, and 62 open issues, an unusually steep adoption curve and an equally busy tracker for a six-week-old project.

How it works: three mechanisms

Micro-skills (off by default). Sessions keep rediscovering the same facts: python -m pytest works where pytest does not, a build step must run first, an env var is required. Micro-skills learns such facts from repeated failures and from a model that reviews recent sessions every k=3 sessions and proposes candidates. A fact is injected at session start only after three sessions confirm it, and dropped when later sessions contradict it. Because the proposer costs model calls, it ships off; microskills=envfacts learns only from repeated failures with no model calls.

Tool pruning (on by default). Loaded tool definitions can add fresh input, cache writes, and cache reads. A tool unused over p=10 prompts spanning at least m=2 sessions, or s=5 sessions of any length, gets left out of subsequent sessions through the agent’s own settings; one command (toolprune restore) brings it back. What it can prune depends on the host: single tools in .claude/settings.local.json on Claude Code, capability packages in .codex/config.toml on Codex, whole MCP servers for Copilot CLI, and nothing on Pi, Cursor Agent, Grok Build, opencode, Hermes, Antigravity, or Droid where no per-tool setting exists. By default, the plugin waits for 60 idle minutes before writing its deny list, with a fallback a day after the list forms. It adds its own entries, preserves existing deny rules, and adds settings files it creates to .git/info/exclude.

Failure-loop intervention, the loop guard (on by default). The guard first learns a baseline: e=5 turns in this repo that ended well. Then a turn showing loop signs (repeating failures, piling errors) goes to a judge model; at confidence c≥0.7 the agent gets a redirect, a short note added to context suggesting another approach, at most r=1 per turn. A separate backstop redirects without the judge when a turn runs past b=2.5 times its usual length while churning the same edits and failures. If still stuck, it prints a line telling you how to stop it and does nothing else: stopping is your call.

The plugin’s own model calls (fact proposer, judge, redirect writer) run through your agent on your plan or login, and their cost is included in its reports. Everything it learns stays in ~/.tokeneconomizer on your machine.

Install and first run

Requirements: a supported agent signed in however you use it, and Python 3.10+ on PATH. The plugin runs from a clone you keep:

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

# Codex
git clone https://github.com/microsoft/TokenEconomizer.git
codex plugin marketplace add "$PWD/TokenEconomizer"
codex plugin add tokeneconomizer@tokeneconomizer

# Copilot CLI
git clone https://github.com/microsoft/TokenEconomizer.git
copilot plugin marketplace add "$PWD/TokenEconomizer"
copilot plugin install tokeneconomizer@tokeneconomizer

# Pi
pi install git:github.com/microsoft/TokenEconomizer

Then start the agent in a repository and run its status command (/tokeneconomizer:status, $tokeneconomizer:status, or /te status). On Claude Code and Copilot CLI, run the toolprune refresh-catalog command once per machine and after agent updates so pruning can see every tool a session loads. Supported version ranges are explicit (Claude Code 2.1.300-2.1.329, Codex 0.153.1-0.171.0, Copilot CLI 1.0.83-1.0.114, Pi 1.2.0-1.5.2, plus a table of experimental hosts).

To remove it, uninstall the plugin through the agent and delete the clone and ~/.tokeneconomizer; toolprune restore first if you want pruned tools back in settings.

What it saves: claims versus evidence

The paper ran five agent-model combinations on 277 SWE-Bench tasks from six repositories, each repo’s tasks in order starting from nothing learned. Reported: 18.4-30.9% lower mean cost across the five combinations, cheaper in all 30 repository-by-combination cells, Pass@1 up in four of five. The authors also report 16% to 21% lower cost on Web-Bench. Costs include every model call the plugin itself made, counted under cache pricing, which is the accounting most cost tools skip.

The authors report 6% to 20% lower costs on two benchmarks where each task starts in a new repository. Those results describe the tested workloads. Measure pruning, side-call spend, and cost per accepted task on your own mix of new and recurring repository work.

Issue #335 and issue #338 report missed npm, pnpm, and Windows verification forms. Issue #353 reports that the guard can judge PHPUnit or CTest without its summary. The snapshot also lists reports of VS Code chats misidentified as Claude Code (#317) and missed commands wrapped in bash -lc (#343). The closed list is more instructive: #87 reported Claude Code side calls keeping every MCP server attached so one Haiku call cost ~570k effective tokens, a reminder that the plugin’s own calls are real spend it now accounts for. Most concerning is open #260: “repository-planted code runs in the plugin process; tmp writes follow symlinks”, a security surface to weigh before installing on repos you do not trust.

Prompt-cache and extra-turn risk

The design is explicitly cache-aware. Facts enter at session start, and the pruning delay is intended to limit cache rewrites. Check measured cache usage when the tool list changes. The loop guard can add a redirect mid-turn, and a wrong learned fact or a premature redirect could steer the agent into extra turns. The guardrails (three confirmations per fact, contradiction drops facts, one redirect per turn, judge confidence threshold) exist to bound exactly that. On Claude Code, note that plugin lines show only in the detailed transcript (Ctrl+O), so check /tokeneconomizer:toolprune rather than assuming silence means inaction.

A cost example

Take tool pruning alone. Assume a session loads 12 tool schemas at ~400 tokens each (4,800 tokens/request), 150 requests a day in one repo, on claude-sonnet-5-5 (input $2/M, cache read $0.10/M, rates).

  • Pruning 6 unused tools removes 2,400 tokens/request: 360,000 tokens/day removed.
  • If all removed tokens would have billed as fresh input, 360,000 × $2 per million = $0.72 per day. If 90% would have been cache reads, 360,000 × (0.10 × $2 + 0.90 × $0.10) per million = about $0.10 per day. Both are estimates before cache writes.

At $2 per million fresh input tokens, avoiding a 50,000-token turn saves an estimated 50,000 × $2 per million = $0.10 before judge or redirect costs. Compare that with the daily schema savings above using the cache behavior you observe. Count any extra turns if a needed tool goes missing.

Who should use it, who should skip it

Use it if:

  • You run Claude Code, Codex, Copilot CLI, or Pi repeatedly in the same repositories; the mechanism needs session history to pay back.
  • Your sessions load many tools/MCP servers the agent rarely calls; schema overhead is a known input-cost line (MCP tool definition token cost).
  • You want the safety properties: reversible actions, no credentials handled, learned state kept local in ~/.tokeneconomizer.

Skip it if:

  • You work mostly one-shot in fresh repos; there is nothing to learn from.
  • You cannot accept a research plugin running hook code in your agent process, especially on untrusted repos given open issue #260.
  • You are on an experimental host (opencode, Cursor Agent, Grok Build, Hermes, Antigravity, Droid) where only a subset of mechanisms works; the README’s per-host limits are precise, read them first.
  • You need a released product: one release (v0.1.0) and 62 open issues is early-stage software, however impressive the star count.

How to trial it safely

  1. Start in a repository you trust and leave micro-skills off initially. Include loop-guard judge and redirect calls in the trial cost, and check whether the interventions lower cost per accepted task.
  2. Optionally turn on history_import on Claude Code right after install so it can learn from existing session logs with no model calls.
  3. Run a week, then read /tokeneconomizer:status for learned facts, pruned tools, and session costs; verify pruned tools were actually unused before keeping the list.
  4. Compare billed cost against the same work pattern without the plugin using the method in how to measure coding agent token savings or the agent cost simulator.
  5. Only then consider microskills=on (paid proposer) or envfacts (free variant), and watch whether injected facts ever steer the agent wrong.

Worked pruning and restore trial in Claude Code. Pick a trusted repository where you can run both a common task and a less frequent task that needs a specific tool. Record the current deny rules and run both tasks before enabling pruning. Leave micro-skills off and turn the loop guard off for this pass so you can measure pruning by itself. Start in proposal mode and gather evidence across normal sessions. Inspect the proposed changes before applying them.

/tokeneconomizer:config set loopguard=off
/tokeneconomizer:config set toolprune=propose
/tokeneconomizer:toolprune

If the proposed list includes a tool the less frequent task needs, preserve access or restore the tool before depending on it. For a controlled trial, apply the proposal, start a new session, and verify the resulting settings and available tools. Repeat both tasks with the same model and record provider-reported input, cache reads, and cache writes. Check the task results against your original acceptance criteria. A task that passes after extra searches or a manual handoff can cost more even when the catalog shrinks.

/tokeneconomizer:toolprune apply
/tokeneconomizer:toolprune
/tokeneconomizer:toolprune restore

The restore command removes the plugin’s deny entries and leaves your existing rules in place. Start another session and confirm that the restored tool is available for the less frequent task. The README says restored tools are exempt from future pruning. Record the result before enabling the loop guard for a separate trial that includes judge and redirect costs. Keep the settings diff with the usage totals so you can connect any change in cache writes or completion rate to the tools actually removed. If the first new session is more expensive, compare later sessions as well before drawing a conclusion. The cache write on the first request and the reads on later requests can carry different rates even when the tool list stays the same.

Alternatives and next reads

TokenEconomizer can change which tools the agent sees and how it responds to stalled work. For tool-output compression, see sqz or Tamp. See how providers price prompt caching for the rates that apply when tool definitions change. For the broader bill context, see the real cost of AI coding assistants and input tokens vs output tokens.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

TokenEconomizer Review: Experience-Driven Cost Control for Coding Agents. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/tokeneconomizer-coding-agent-cost-control/

Sources