2026-11-26 15:39 UTC

Microsoft-backed TokenEconomizer reports 18–31% coding-agent cost reductions

state: significantheat: mediumuncertainty: mediumrelevance: highcoding-agent-costs token-optimization coding-agentsMicrosoft ResearchUC BerkeleyIon Stoica

What is this?

TokenEconomizer is an open-source Apache 2.0 plugin from researchers at Microsoft Research, Microsoft Security, and UC Berkeley, including Ion Stoica. It works with supported coding agents rather than modifying their models: it learns repository-specific practices from prior sessions, removes tools that appear unused, and can nudge an agent out of repeated failure loops. Microsoft’s project materials describe it as available for Claude Code, Codex, GitHub Copilot CLI, and Pi, with several other integrations marked experimental. A November 17 Microsoft Research blog is newer confirmation of the project first surfaced in the linked repository and arXiv paper. The supplied sources report benchmark results but provide no independent replication or real-world adoption evidence.

Why it matters

This is a practical example of optimizing the agent workflow around a model rather than changing the model itself. If the reported savings transfer to repeated development work, developers and organizations could run coding agents more cheaply without giving up their existing agent or login. That could improve access and make persistent agent use more economical. The measured gains are promising, but remain benchmark evidence, not proof of general production savings.

Current assessment

Microsoft Research’s November 17, 2026 blog provides newer first-party confirmation that TokenEconomizer is an open-source plugin; the repository and arXiv paper describe the mechanisms and experiments. It stores learning locally per machine and repository, counts its own model calls in reported costs, and offers reversible or configurable interventions. In the project’s reported SWE-Bench evaluation, 277 tasks across six repositories and five agent–model combinations yielded 18.4–30.9% lower mean cost; cost was lower in all 30 repository-by-combination cells, while Pass@1 increased in four of five combinations and fell in one. The project also reports savings on Web-Bench and two security-auditing benchmarks, including tasks in new repositories. These are authors’ reported results, not independent validation; benchmarks, tested agent versions, and repository/session patterns may not represent ongoing production work. Availability is uneven: several integrations are experimental or have documented limitations, and micro-skills are off by default. The useful implication is that cross-session memory and lightweight controls may reduce recurring context, tool-definition, and failure-loop costs without changing model weights. Track independent replication and evidence of sustained adoption before treating the savings as established broadly.

Measured heat

now 0 pts/hpeak 2 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 530h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

11-04 13:24 (minted)⭐ origin echo-reconstructedThe paper and accompanying project describe TokenEconomizer’s three cost-control mechanisms and report savings across coding-agent and bench
Aaron J. Li, Weijia Xu, Chandan Singh, Zixiao Chen, Jeevana Priya Inala, Charlotte Siska, Acar Tamersoy, Bin Yu, Ion Stoica, Michel Galley, and Jianfeng Gao on paper (echo) · attributed from hn.story.50365007 · published time unknown
—
11-04 13:05first on hacker news · published · lag ?TokenEconomizer: Cut coding-agent token costs 18-31%
mehdizare
—
11-04 13:05amplified on hacker news 👑hn.story.50365007
mehdizare
peak 2 · 1 comments · 59% of case engagement
11-17 06:53amplified on hacker newshn.story.50528293
matt_d
peak 2 · 0 comments · 41% of case engagement
11-04 13:21our radar first saw it · lag ?discovery anchor: hn.story.50365007—
pace: p40 vs 1845 stories at the 336h mark (now 530h old) — ahead of abmaze-protein-fitness-agent-benchmark (1.3x), behind agentplay-coding-agent-cost-dashboard (0.8x)

Evidence (3) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnTokenEconomizer: Cut coding-agent token costs 18-31%
Retrieved article excerpt

Open article · Retrieved 2026-11-04T13:23:36.567051+00:00

# TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents

Aaron J. Li1,
Weijia Xu2,
Chandan Singh2,
Zixiao Chen3,
Jeevana Priya Inala2,
Charlotte Siska3,
  
Acar Tamersoy3,
Bin Yu1,
Ion Stoica1,
Michel Galley2,
Jianfeng Gao2

1UC Berkeley   2Microsoft Research   3Microsoft Security

[arXiv](https://arxiv.org/abs/2610.22732)
[Project page](https://tokeneconomizer.github.io)
[X post](https://x.com/aaron_jli/status/2114797313613053952)
[Python 3.10+](https://camo.githubusercontent.com/6152833ccf63971ce9805effafc43aad79dd3fe9cc0db0fe5f006d1c02d96059/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f707974686f6e2d332e31302532422d3337373661622e737667)
[Apache 2.0 license](https://camo.githubusercontent.com/b29de0acdfd19013f1f02689b15c933e4a6c145be9efa718288f88ba3280b1c5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e737667)

Our measurement on SWE-Bench tasks: **18.4–30.9% lower mean cost** across five agent–model
combinations, cheaper in **all 30** repository × combination cells, and Pass@1 up in
**4 of 5**. [Results](https://github.com/microsoft/TokenEconomizer#results)

An animation that opens on a title card: TokenEconomizer, experience-driven black-box cost control for coding agents, with its three mechanisms (micro-skills, tool pruning, failure-loop intervention), the agents it works with (Claude Code, Codex, GitHub Copilot CLI, Pi) and the UC Berkeley and Microsoft logos. Then a schematic of six sessions in one repository, each a bar of what it cost: the work itself plus three kinds of waste, namely re-learning the repo, tools never used, and getting stuck in loops. Each of the first three sessions teaches TokenEconomizer one thing, in order: 1 micro-skills remember how the repo works (run tests with python -m pytest), 2 tool pruning skips tools never used here (Read and Edit kept, Notebook and Browser left out), and 3 failure-loop intervention spots loops and steps in (the same error three times meets a nudge to try another way). In the session after each lesson that waste shrinks, so the bars step down below a dashed line marking the cost without TokenEconomizer. It ends on results measured on SWE-Bench tasks: 18.4–30.9% lower mean cost across five agent–model combinations, cheaper than default in 30 of 30 repository × combination cells, and Pass@1 up in 4 of 5; per combination, cost 23.6% lower and Pass@1 +1.3 for Claude Code with Sonnet 5, 30.9% and −1.0 with Opus 4.8, 24.7% and +0.9 for Codex with GPT-5.6 Terra, 26.1% and +1.6 with GPT-5.6 Sol, and 18.4% and +2.6 for Copilot CLI with Sonnet 5.

TokenEconomizer makes coding agents cheaper to run in the repositories you work in often,
without changing the agent itself. It learns from the sessions an agent has already run in a
repository, and uses that experience to cut waste in the sessions that follow. It has three
mechanisms:

- **Micro-skills: remember how the repository works.** Sessions keep rediscovering the same
  facts: a build step that must run first, the spelling of a command that works here
  (`python -m pytest` where `pytest` is missing, `npx tsc` where `tsc` is), an environment
  variable a command needs, where generated files live. Micro-skills learns such facts, in any
  language, from two sources: failures that repeat across sessions, and a model that reviews the
  recent sessions every *k* sessions (*k* = 3) and proposes facts. A fact is stated at the start
  of each session once three sessions have confirmed it, and dropped when later sessions
  contradict it.
- **Tool pruning: stop loading tools that go unused.** Every loaded tool's definition is sent with
  every request. A tool that goes unused over *p* prompts spread across at least *m* sessions, or
  over *s* sessions of any length (*p* = 10, *m* = 2, *s* = 5), is left out of the next sessions
  through the agent's own settings. One command brings it back.
- **Failure-loop intervention (the loop guard): step in when a turn is stuck.** When a turn (the
  agent's work on one prompt) keeps hitting the same failures, a judge model checks whether it is
  stuck. If the judge is at least *c* sure (*c* = 0.7), the agent gets a redirect (a short note,
  added to its context, to try another approach), at most *r* times per turn (*r* = 1). If the
  turn is still stuck after that, TokenEconomizer tells you how to stop it; it never stops a turn
  itself.

TokenEconomizer is a plugin for **Claude Code**, **Codex**, the **GitHub Copilot CLI** and **Pi**,
with experimental support for **opencode**, **Cursor Agent** and **Hermes Agent**. Each italic
letter above is a setting, shown with its default ([Settings](https://github.com/microsoft/TokenEconomizer#settings)), and each mechanism can be turned on or
off. The plugin announces each action in one line, and if any part of it fails, your session
carries on as if it were not installed. Its model calls (the fact proposer, and the judge with the
redirect it writes) run through your own agent, on the same plan or login, and their cost is
included in its reports. What it learns stays on your machine, in `~/.tokeneconomizer`.

## Results

The paper ran five agent–model combinations on the same 277 SWE-Bench tasks from six repositories.
Each task ran as its own session, and each repository's tasks ran in order, starting with nothing
learned. Costs include every model call TokenEconomizer made. Within each repository and
combination, cost fell by 5–40%. The savings held on Web-Bench (16–21% lower) and on two
security-auditing benchmarks where every task is in a new repository (6–20% lower). The
[project page](https://tokeneconomizer.github.io) has interactive charts, per-repository numbers
and nine annotated runs, and [`experiments/`](https://github.com/microsoft/TokenEconomizer/blob/main/experiments/README.md) reruns the SWE-Bench and
Web-Bench experiments.

## How it works

[TokenEconomizer: the plugin keeps what it knows about a repository and applies micro-skills, tool pruning and failure-loop intervention to your unchanged coding agent; each finished session's log updates all three](https://github.com/microsoft/TokenEconomizer/blob/main/docs/assets/framework_overview.png)

Coding agents are built to finish tasks, not to keep them cheap. Every turn pays again for the
agent's instructions, every loaded tool, and the conversation so far. Developers use the same
agent on the same repository again and again, so much of that cost repeats: the same facts
rediscovered, the same unused tools sent, the same kinds of failing loops. TokenEconomizer leaves
the agent's model, weights and code alone and learns across a repository's sessions instead of
treating each one on its own, so whatever the plugin spends is paid back over the sessions that
follow. Four principles guide the mechanisms:

- **Work through what the agent already reads.** Facts enter the context at session start, and
  tools are removed through the agent's own settings, so nothing depends on the agent learning a
  new tool.
- **Count cost as it is billed.** Most tokens in a session are cached re-reads, so cost is
  computed with cache pricing, and it includes the plugin's own model calls.
- **Protect task success.** Facts form only from repeated evidence, tools are removed only after
  going unused, and the loop guard leaves alone a turn that is still making progress.
- **Keep every action reversible.** A fact that later sessions contradict is dropped, removed
  tools can be given back, and the loop guard only redirects and tells you: stopping a turn is
  your call.

## Quick start

You need one of these agents, signed in any way it supports, and Python 3.10 or newer on
`PATH`. The plugin needs no API key of its own and never handles credentials, so any plan or
login works.

### Install

Run these commands in the folder where you want to keep the clone. Claude Code, Codex, the
Copilot CLI and opencode run the plugin from the clone, so leave it in place. Then start the agent
in one of your repositories.

**Claude Code**

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

Start `claude`, trust the folder (**Yes, I trust this folder**), and run
`/tokeneconomizer:status`, allowing its script if asked. Once per machine, and again after Claude
Code updates, run `/tokeneconomizer:toolprune refresh-catalog`.

**Codex**

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

Start `codex`, choose **Trust and continue** for the folder, then at **Hooks need review**
choose **Trust all and continue**. The hooks take effect from your next Codex session, so quit
(`/exit`), start `codex` again, and check with `$tokeneconomizer:status`.

**Copilot CLI**

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

Start `copilot`, choose **Yes, and remember this folder for future sessions**, and run
`/tokeneconomizer:status`, choosing **Yes** to run its script. Once per machine, and again after
Copilot updates, run `/tokeneconomizer:toolprune refresh-catalog`.

**Pi**

```
pi install git:github.com/microsoft/TokenEconomizer
```

Start `pi` and run `/te status`.

**Cursor Agent** (experimental)

```
python scripts/build_plugin.py --out ~/.cursor/plugins/local/
```

Reload Cursor, confirm `tokeneconomizer` appears in Customize, then send a prompt in a repository.
Check its state from a terminal with `~/.tokeneconomizer/bin/te --host cursor status`. Cursor's
published hooks provide session, prompt, tool-result and completion events. Its transcript format
and per-session token usage are not a supported public interface, so the adapter records needed
hook events locally and reports session cost as unavailable. Cursor support is macOS and Linux
only: on Windows, Cursor runs hook commands through PowerShell, and this plugin's launcher is a
POSIX shell script.

**opencode** (experimental)

```
git clone https://github.com/microsoft/TokenEconomizer.git
mkdir -p ~/.config/opencode/plugins
ln -s "$PWD/TokenEconomizer/plugin/opencode/tokeneconomizer.ts" ~/.config/opencode/plugins/
```

Start `opencode` and send a prompt, then check in the repository with
`~/.tokeneconomizer/bin/te --host opencode status`. opencode has no plugin commands, so the
plugin's commands run from a terminal.

**Hermes Agent** (experimental; micro-skills and the loop guard, on the classic CLI and one-shot
runs)

```
git clone https://github.com/microsoft/TokenEconomizer.git
ln -s "$PWD/TokenEconomizer/plugin/hermes" ~/.hermes/plugins/tokeneconomizer
hermes plugins enable tokeneconomizer
hermes gateway restart
```

Link it rather than running `hermes plugins install`, which leaves the launchers behind when given
this directory and refuses the whole repository at its security scan. Send a prompt, then check in the repository with `~/.tokeneconomizer/bin/te --host hermes status`.

If the install worked, the status command prints a short status block. `refresh-catalog`
records every tool a session loads (without a model call), so that tool pruning can consider all
of them. Keep the marketplace path absolute, as above: the Copilot CLI reads a relative path such
as `./TokenEconomizer` as the name of a GitHub repository.

To update:

| Agent | Update |
| --- | --- |
| Claude Code, Copilot CLI, opencode | `git pull` in the clone |
| Hermes Agent | `git pull` in the clone, then `hermes gateway restart` |
| Codex | `git pull` in the clone, then the `codex plugin add` line again |
| Pi | `pi update --extensions` |

**[`plugin/README.md`](https://github.com/microsoft/TokenEconomizer/blob/main/plugin/README.md)** walks through each agent in more detail, including
uninstalling, using Copil
mehdizare21
🟧 echo.paper ⭐The paper and accompanying project describe TokenEconomizer’s three cost-control mechanisms and report savings across coding-agent and benchAaron J. Li, Weijia Xu, Chandan Singh, Zixiao Chen, Jeevana Priya Inala, Charlotte Siska, Acar Tamersoy, Bin Yu, Ion Stoica, Michel Galley, and Jianfeng Gao——
🟧 hnTokenEconomizer: Learning from Experience to Make AI Coding Agents Efficientmatt_d20

Interpretation history

Decision trace