SuperAPIAI Directory

TokenEconomizer

github.com · AI coding

TokenEconomizer is a coding agent cost-control plugin jointly developed by Microsoft Research and other institutions. It reduces the operating costs of coding agents in commonly used repositories through an experience-driven, black-box approach. It does not modify the agent itself; instead, it learns from sessions the agent has already run, using three mechanisms—micro-skills (remembering repository operation facts), tool pruning (disabling unused tools), and failure-loop intervention (loop guard)—to reduce waste. Measurements on SWE-Bench tasks show an average cost reduction of 18.4–30.9% across five agent-model combinations, with all 30 repository×combination units being cheaper and Pass@1 improving in 4 of the 5 combinations. The plugin supports Claude Code, Codex, GitHub Copilot CLI, and Pi, and provides experimental support for opencode, Cursor Agent, Grok Build, Hermes Agent, Antigravity CLI, and Factory Droid. Learned content is stored locally in the ~/.tokeneconomizer directory, and model calls are made through the user's own agent, requiring no additional API keys.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

TokenEconomizer is a cost-control plugin for coding agents, jointly developed by UC Berkeley, Microsoft Research, and the Microsoft Security team. Its core idea is that coding agents are designed to complete tasks, not to keep costs low; every conversation turn repeatedly pays for agent instructions, loaded tools, and conversation history. Developers repeatedly use the same agent in the same repository, so a large amount of cost recurs—the same facts are rediscovered, the same unused tools are repeatedly sent, and the same types of failure loops repeatedly occur. TokenEconomizer does not change the agent's model, weights, or code; instead, it learns across repository sessions so that the plugin's own overhead pays off in subsequent sessions.

Main capabilities include three mechanisms:

  1. Micro-skills: remembering how a repository works. The same facts are repeatedly discovered during sessions, such as build steps that must be run first, command spellings that work here (e.g., using python -m pytest when pytest is missing, or npx tsc when tsc is missing), environment variables required by commands, and the locations of generated files. Micro-skills learn these facts from two sources: failures that recur across sessions, and a model that reviews recent sessions every k sessions (k=3) and proposes facts. A fact is declared at the start of every session after being confirmed in three sessions, and is discarded when a later session contradicts it.

  2. Tool pruning: stopping the loading of unused tools. The definition of every loaded tool is sent with every request. A tool that is unused across p prompts (p=10, m=2) in at least m sessions, or unused across s sessions (s=5) of any length, is excluded from subsequent sessions through the agent's own settings. A single command restores it.

  3. Failure-loop intervention (loop guard): intervening when a conversation turn (the agent's work on one prompt) keeps encountering the same failure. A judgment model checks whether it is stuck; if confidence is at least c (c=0.7), the agent receives a redirect (a short prompt added to its context suggesting trying another approach), at most r times per turn (r=1). If it is still stuck afterward, TokenEconomizer explains how to stop, but never stops the turn itself.

Usage: one of the supported agents must be logged in, and Python 3.10 or newer must be in PATH. The plugin does not need its own API key and never handles credentials. Run the installation command in the folder where you want to keep the clone, thenThen start the agent in a repository. The specific startup and status-check commands differ across agents; for example, in Claude Code run /tokeneconomizer:status, in Codex check $tokeneconomizer:status, in Copilot CLI run /tokeneconomizer:status, and in Pi run /te status. Tool pruning and loop guard are enabled by default; microskills are disabled by default because their proposer adds model calls, and the degree of savings depends on the repository and the work content. Each mechanism has an independent switch (microskills, toolprune, loopguard) that can be set to on or off.

When to use: when developers repeatedly use coding agents in the same repository, TokenEconomizer can help reduce repeated costs. The paper tested five agent-model combinations on 277 SWE-Bench tasks (from six repositories), with each task run as an independent session, tasks within each repository run in sequence, starting from zero learning. Costs include all model calls made by TokenEconomizer. Within each repository and combination, costs dropped by 5–40%. The savings also hold on Web-Bench (16–21% reduction) and on two security audit benchmarks (each task in a new repository, 6–20% reduction).

Limitations: the level of support differs across agents. Claude Code, Codex, GitHub Copilot CLI, and Pi are primarily supported; opencode, Cursor Agent, Grok Build, Hermes Agent, Antigravity CLI, and Factory Droid are experimentally supported, and some features (such as tool pruning, paid proposers, and loop guard) may be unavailable. Cursor support is limited to macOS and Linux, and session cost reporting is unavailable. Antigravity CLI only supports LLM-free facts for microskills and makes no model calls. Hermes Agent only supports the classic CLI and one-shot runs. Factory Droid does not support tool pruning. Grok Build does not support tool pruning, and learned facts arrive at the session's first tool call. The tested version range for each agent is limited, and newer versions have not yet been tested. Learned content is saved locally in the ~/.tokeneconomizer directory.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools