Tools

TokenEconomizer plugin cuts AI coding agent costs 18-31% by learning from past sessions

Microsoft Research and UC Berkeley's open-source plugin learns from earlier sessions in a repository and cut bug-fixing costs across five agent-model setups.

Published Updated

Grayscale glass piggy bank filled with metal gears and one red gear
AI-generated image

TL;DR

  • On 277 SWE-Bench tasks, TokenEconomizer lowered average cost per task by 18.4% to 30.9% across five agent-model combinations [1].
  • It works without changing the agent or its model, using one-line repository notes, tool pruning and a check for stuck failure loops [1].
  • The plugin is open source, needs no API key of its own and keeps what it learns on the developer's machine [1].

Microsoft Research described TokenEconomizer on 16 November 2026, an open-source plugin from UC Berkeley, Microsoft Research and Microsoft Security [1]. It reads the logs of an AI coding agent’s finished sessions in a repository and uses them to cut wasted tokens in later sessions [1]. It does this without modifying the agent or the model behind it [1].

Why it matters

In each session, a coding agent sends instructions, tool descriptions and session history to its model, and all of that consumes tokens [1]. Developers return to the same codebases day after day, yet agents often start from scratch each time [1]. Most cost-cutting work looks at single tasks, while TokenEconomizer looks at what an agent can learn across tasks in the same repository [1].

Where the waste comes from

The team first profiled Claude Code on 60 SWE-Bench tasks, running each repository’s tasks in order [1]. Once a repository had at least five finished tasks, 30% of tool calls repeated an action from an earlier task in that repository [1]. The agent received 23 tool descriptions on every turn, but 16 were never called [1]. The 17% of tasks that failed accounted for 32% of spending [1]. Three popular open-source cost-saving plugins each helped in some repositories but not others [1].

How it works

TokenEconomizer uses three mechanisms [1]. Micro-skills are one-line notes about the repository, added to the agent’s starting context only after several sessions confirm the pattern, and removed if later evidence contradicts them [1]. Tool pruning drops tools that the repository’s history suggests will not be used, but always keeps the core tools for running commands and editing files [1]. Failure-loop intervention uses a judge model to decide whether the agent is stuck; if it is, the agent gets a short note suggesting a different approach, and if it stays stuck the plugin alerts the developer instead of stopping the work [1].

Results

On 277 SWE-Bench tasks from six repositories, using five agent and model combinations, average cost per task fell by 18.4% to 30.9% [1]. The reported savings include the cost of TokenEconomizer’s own model calls [1]. Pass@1 rose in four of the five combinations [1]. Lowering the model’s reasoning effort saved similar or larger amounts but hurt performance substantially [1]. Costs were 16.0% to 21.2% lower on Web-Bench and 6.4% to 19.6% lower on security auditing tasks, where each task is in a new repository [1].

Limits

Early tasks in a repository can cost more while the plugin learns; with Claude Code, cumulative costs dropped below the default in every repository by the sixth task [1]. The main results come from SWE-Bench, a benchmark of real bug fixes in open-source Python projects, and each repository started with no session history [1].

Sources

Written and checked by AI from the sources below

  1. TokenEconomizer: Learning from Experience to Make AI Coding Agents More EfficientMicrosoft Research ·

Fact-checked by gpt-6.1-sol on · Editorial policy