TokenEconomizer Cuts Coding Agent Costs 18–31% Without Touching the Model

Published • news
Coding AgentsOpen Weights

Coding agents are expensive not because their models are slow, but because every turn re-bills the system prompt, the full tool catalog, and the entire conversation history. A joint team from Microsoft Research and UC Berkeley has released TokenEconomizer, an open-source plugin that attacks that billing structure directly — not by changing the underlying model or agent code, but by learning repository-specific waste patterns across sessions and suppressing them before they accumulate. Microsoft reports cost reductions of 18.4% to 30.9% on SWE-Bench across five agent–model combinations, with no cost increase in any of the 30 repository-by-combination cells tested.

This is the same infrastructure-layer approach — extracting performance from the stack rather than from model weights — that has characterised much of the real engineering progress in production AI deployments over the past year.

Three Mechanisms, One Shared Principle

TokenEconomizer installs as a plugin for Claude Code, Codex, GitHub Copilot CLI, and Pi, with experimental support for opencode. It requires Python 3.10 or newer and no API key of its own. All learned state is stored locally in ~/.tokeneconomizer. Each mechanism is independently switchable.

Micro-skills captures repository-specific facts — the correct test invocation, required environment variables, locations of generated files — from two sources: failures that repeat across sessions, and an LLM proposer that reviews session traces every three sessions and generates candidate facts. A fact enters the prompt only after three sessions have confirmed it on tasks with non-overlapping edited files, and its need rate must remain at or above 0.4. One contradiction is weighted as five confirmations, so incorrect facts are retired quickly. Micro-skills is off by default because the proposer adds model calls.

Tool pruning removes tool schemas the repository never actually uses. Microsoft's profiling of 60 SWE-Bench tasks across six repositories using Claude Code with Opus 4.8 found that 16 of the 23 tool schemas loaded per turn were never called, while three tools accounted for 98% of all calls. After pruning on Django with Claude Code, the first-request prompt token count fell from 43,351 to 16,295. A full catalog re-audit runs every five tasks. Shell, read, write, and edit tools are always kept.

Failure-loop intervention computes a per-repository turn budget equal to 1.25 times the 90th-percentile length of successful runs. Cheap rule checks detect repeated failures or dense error output. An LLM judge then determines whether the agent is stuck, requiring at least 0.7 confidence before acting. A stuck agent receives one redirect injected into its context; the plugin does not stop a turn autonomously — it instructs the operator to do so. Microsoft's profiling found that failed runs were 17% of tasks but consumed 32% of total spend.

SWE-Bench Results

The paper evaluated 277 SWE-Bench tasks from six repositories, with three seeds per setting. All cost figures include every model call the controller itself made.

Agent–Model Setting Cost Change vs. Default Pass@1 (Default) Pass@1 (TokenEconomizer)
Claude Code + Sonnet 5 −23.6% 74.7 76.0
Claude Code + Opus 4.8 −30.9% 74.0 73.0
Codex + GPT-5.6 Terra −24.7% 73.8 74.7
Codex + GPT-5.6 Sol −26.1% 80.1 81.7
Copilot CLI + Sonnet 5 −18.4% 75.0 77.6

Source: arXiv 2610.22732, Table 1. Microsoft-reported figures. Three seeds per setting.

Pass@1 improved in four of five settings; the sole decline was 1.0 point on Claude Code with Opus 4.8 — the same setting that achieved the highest cost reduction. Within individual repositories, per-cell cost reductions ranged from 5% to 40%. Savings also transferred to Web-Bench (Microsoft reports 16.0%–21.2% lower cost) and CredData (16.5%–19.6%). On ReposVul security audits, where every task runs in a new repository, savings were only 6.4%–9.3%, which the authors attribute to shorter runs leaving fewer repeated patterns to remove.

On Claude Code, tool pruning alone accounted for 13.2%–17.7% of cost reduction; micro-skills added 11.8%–14.3%; the loop guard contributed 5.4%–7.1%.

MarkTechPost notes that RTK raised cost in 12 of 30 repository-setting cells and Aider's RepoMap raised it in 15, while TokenEconomizer raised cost in none.

Availability and Supported Versions

The plugin is released under the Apache 2.0 license at github.com/microsoft/TokenEconomizer, where it had accumulated 1.9k stars and 115 forks at publication time. Supported agent version ranges are specific: 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, and opencode 1.19.5 and 2.2.0 (experimental). Codex before 0.141.0 does not run plugin hooks at all. Updates are applied via git pull in the clone directory.

AI Mastery Analysis

TokenEconomizer's most important architectural property is that it is strictly black-box: it communicates with the agent only through channels the agent already exposes — the prompt, tool settings, and the event stream — and requires no model fine-tuning, no agent modification, and no access to model weights. This makes it portable across model generations as long as the plugin interface is supported, a meaningful deployment advantage given how rapidly underlying models are swapped in production. The tradeoff is that the loop guard cannot autonomously stop a runaway session; it can only redirect once and then alert the operator. Teams running unattended pipelines need to instrument session termination themselves.

The cold-start behavior deserves scrutiny. Microsoft reports that most repositories cost more at the start of the experiment — savings compound only as session history grows — and all six repositories reached net-cheaper status by the sixth task. For low-volume repositories visited infrequently, the per-repository learning state may never mature enough to generate meaningful savings. The ReposVul result (6.4%–9.3%) is an early signal of this: when every task is in a fresh repository, none of the cross-session mechanisms has evidence to act on.

The micro-skills mechanism's default-off status is also worth noting. Because the LLM proposer runs on the same agent plan, enabling it adds cost per cycle — the paper includes those calls in its reported savings, meaning the net figures already reflect this overhead. As context pricing makes long-context strategies increasingly expensive, session-scoped memory that compresses rather than extends context will attract more engineering attention. An 18.4%–30.9% cost reduction on a production workload, delivered through a three-command install with no model changes required, is a concrete data point that infrastructure-layer optimisation is closing in on model-selection decisions as the primary lever for AI deployment economics.

Sources

Frequently asked questions

How much does TokenEconomizer reduce coding agent costs?

Microsoft reports 18.4% to 30.9% lower mean cost across five agent–model combinations on 277 SWE-Bench tasks. Cost fell in all 30 repository-by-combination cells tested, with per-cell reductions ranging from 5% to 40%.

Which coding agents does TokenEconomizer support?

The plugin supports Claude Code (versions 2.1.300–2.1.310), Codex (0.153.1–0.164.0), GitHub Copilot CLI (1.0.83–1.0.102), and Pi (1.2.0–1.3.0), with experimental support for opencode (1.19.5 and 2.2.0). Codex before version 0.141.0 does not run plugin hooks at all.

Does TokenEconomizer require a GPU or its own API key?

No. It requires Python 3.10 or newer and one of the supported agents already signed in. The plugin needs no API key of its own; its model calls run through the agent on the same plan or login.

What is the biggest single source of savings from TokenEconomizer?

Tool pruning is the largest lever, accounting for 13.2%–17.7% of cost reduction on Claude Code alone. Microsoft's profiling of 60 SWE-Bench tasks found that 16 of 23 tool schemas loaded per turn were never called, while three tools accounted for 98% of all calls.

Does TokenEconomizer hurt task success rates?

Pass@1 improved in four of five settings tested. The only decline was 1.0 point on Claude Code with Opus 4.8—the same setting that achieved the highest cost reduction of 30.9%.

Related Reading