Search tools, AI agents, MCP servers
Submit a tool

Search iThub

Search tools, categories and collections. Type at least two characters.

Explore all tools
↑ ↓ to explore resultsEnter to open · Esc to close

TokenEconomizer

Microsoft plugin that lowers coding-agent cost by learning from past sessions in a repository

AI Coding Assistants & Agent ToolingOpen sourcev0.1.0

TokenEconomizer at a glance

Pricing
Open source
License
Open source
Version
v0.1.0October 26, 2026
Language
Python
Tool type
Plugin
Data location
Runs locally; learned state stays in ~/.tokeneconomizer on the user machine. Its model calls go through the user's own agent CLI and provider, or on-device on macOS 27 if enabled.
Works with
claude code, codex, github copilot cli, pi
Maker
microsoft
Founded
2026

What is TokenEconomizer?

TokenEconomizer is an open-source plugin from Microsoft that aims to lower the running cost of coding agents in repositories where they are used repeatedly, without modifying the agent's model, weights or code. It reads the logs of sessions an agent has already finished in a repository and uses them to change what later sessions in that repository start with and how stuck turns are handled. The project describes itself as experience-driven, black-box cost control: the agent is treated as an unchanged component, and every change goes through context the agent already reads or settings it already honors.

The work comes from researchers at UC Berkeley, Microsoft Research and Microsoft Security and accompanies the paper TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents (arXiv 2610.22732). The project page carries interactive charts, per-repository numbers and annotated runs. According to the README, the paper ran five agent and model combinations on the same 277 SWE-Bench tasks from six repositories and measured 18.4 to 30.9 percent lower mean cost, lower cost in all 30 repository and combination cells, and higher Pass@1 in four of the five combinations. The README also reports 16 to 21 percent lower cost on Web-Bench and 6 to 20 percent on two security-auditing benchmarks; these figures are the project's own measurements.

The plugin combines three mechanisms. Micro-skills learns short facts about a repository (for example that python -m pytest works where pytest does not) and states them at session start. Tool pruning leaves tools that go unused out of later sessions through the agent's own settings files. Failure-loop intervention, called the loop guard, asks a judge model whether a turn that keeps hitting the same failures is stuck and, if so, adds one redirect to the agent's context. Tool pruning and the loop guard are on by default; micro-skills is off by default because its fact proposer adds model calls.

Full support covers Claude Code, Codex, the GitHub Copilot CLI and Pi. opencode, Cursor Agent, Grok Build, Hermes Agent, the Antigravity CLI and Factory Droid have experimental support with a reduced feature set on most of them. Installation is from a clone of the repository through each agent's plugin marketplace command, or with pi install on Pi; there are no packaged binaries. The plugin needs Python 3.10 or newer, no API key of its own, and runs its model calls through the user's own agent CLI and plan. What it learns is stored locally in ~/.tokeneconomizer.

The current release is TokenEconomizer 0.1.0, published on October 26, 2026 as the first release. The Python package is standard-library only and is split into modules for micro-skills, tool pruning, the loop guard, session-log readers per agent and the plugin runtime, as described in ARCHITECTURE.md. The repository also contains the experiment harness behind the paper's results, which is not part of the installed plugin. The code is released under the Apache License 2.0. Similar listings on iThub include CodeBurn, a local tracker of AI coding token usage, and AutoMode, a Claude Code plugin that routes prompts between models.

Key capabilities

  • Micro-skills for repository facts Micro-skills collects facts that sessions keep rediscovering: a build step that must run first, a command spelling that works in this repository, an environment variable a command needs, or where generated files live. Facts come from failures that repeat across sessions and, when enabled, from a model that reviews the recent sessions every k sessions (3 by default). A fact is injected at session start once three sessions confirm it and is retired when later sessions contradict it. The feature is off by default.
  • LLM-free fact mode With microskills=envfacts, the plugin learns facts only from repeated environment failures, such as a tool or test command that fails as typed and works spelled another way. This mode makes no model calls. It is also the only micro-skills mode available on the Antigravity CLI and on Factory Droid while side calls are off.
  • Tool pruning Every loaded tool's definition is sent with every request. A tool that stays unused over 10 prompts spread across at least 2 sessions, or over 5 sessions of any length, is left out of the next sessions. Claude Code's NotebookEdit and Codex's image_media package require three times as much evidence. The deny list is written only after the repository's sessions have been idle for 60 minutes, so a resumed conversation does not lose its prompt cache.
  • Per-agent pruning targets What tool pruning can leave out depends on the agent: single tools on Claude Code (written to .claude/settings.local.json), capability packages on Codex (.codex/config.toml) and whole MCP servers on the Copilot CLI (.github/copilot/settings.local.json). Pi loads only four tools, so nothing is pruned there, and the experimental hosts have no tool pruning yet. A settings file the plugin creates is added to .git/info/exclude, and deny rules written by the user are not touched.
  • Reversible pruning and proposal mode toolprune restore removes only the plugin's own entries, and tools given back are not removed again. With toolprune=propose the deny list is only proposed and nothing changes until toolprune apply runs. If a file cannot be edited safely, for example a committed .codex/config.toml or invalid JSON, the list stays a proposal and the session start says why.
  • Failure-loop intervention (loop guard) The loop guard first waits until 5 turns in the repository have ended well, to learn how long a usual turn runs. A turn that later shows repeated failures or piling errors goes to a judge model; with a "stuck" verdict at confidence 0.7 or higher, the agent receives one redirect per turn by default. A turn that runs past 2.5 times its usual length while churning the same edits through the same failures is redirected without the judge. The plugin never stops a turn itself; it prints a one-line notice explaining how to interrupt it.
  • Cost accounting with cache pricing The status command shows each session's tokens, priced after it ends, together with the plugin's own overhead from the judge and the fact proposer. Cost is computed with cache pricing, because most tokens in a session are cached re-reads. Per-session records are kept in a ledger.jsonl file under ~/.tokeneconomizer/repos/.
  • Model calls through the user's own agent The plugin has no API key of its own. Its judge, redirect writer and fact proposer run through the agent's CLI (claude -p, codex exec, copilot -p with every tool removed, or pi -p), so they use the same subscription or login as the sessions. According to the plugin documentation, no call is sent file contents or user prompts; the judge reads a digest of the turn's last 24 actions with commands cut to 90 characters.
  • On-device judge on macOS On macOS 27 with Apple Intelligence on, local_model=fm runs the loop guard's judge on the Foundation Models CLI at /usr/bin/fm, with no login, key or network. The ledger charges these calls 0 tokens. If the on-device model is unavailable or cannot answer, the call falls back to the agent's CLI. The setting is off by default and does nothing on other systems.
  • Commands on every agent The same command set is available on every host: status, microskills, toolprune, toolprune restore, config, repos, doctor and others. Claude Code and the Copilot CLI use /tokeneconomizer:<command>, Codex uses $tokeneconomizer:<command> and Pi uses /te <command>. Inside an agent a command costs one model turn; from a terminal, through ~/.tokeneconomizer/bin/te, it costs nothing.
  • Settings per repository or global Each mechanism has its own switch (microskills, toolprune, loopguard) and numeric settings such as toolprune_evidence, loopguard.judge_confidence and loopguard_nudges. config set changes a repository, and --global applies to every repository. A single session can be changed with environment variables: TE_DISABLE=1 turns the plugin off, and TE_LOOPGUARD=off disables one mechanism.
  • Import of earlier Claude Code sessions On Claude Code, the plugin can learn from a repository's earlier sessions read from Claude Code's own logs, oldest first and without a model call. The feature is off by default and reads a repository's history only before the plugin has learned from any session there. A deny list that rests on imported sessions waits for toolprune apply.
  • Installation on Claude Code, Codex and Copilot CLI These three agents install from a local clone: git clone, then the agent's plugin marketplace add command with the absolute clone path, then plugin install (or codex plugin add). The installed plugin runs from the clone, so it must stay in place, and updates are a git pull. Claude Code and the Copilot CLI also need a one-time toolprune refresh-catalog per machine and after agent updates.
  • Installation on Pi Pi installs the plugin with pi install git:github.com/microsoft/TokenEconomizer and updates it with pi update --extensions. Pi 0.99.x loads the extension by path instead. Status is checked with /te status.
  • Supported agent versions The README lists Claude Code 2.1.300 to 2.1.310, Codex 0.153.1 to 0.164.0, Copilot CLI 1.0.83 to 1.0.102 and Pi 1.2.0 to 1.3.0, tested on the oldest and newest version in each range. Older versions are not supported, and Codex before 0.141.0 does not run plugin hooks at all. Newer versions have not been tested.
  • Experimental hosts Opencode (1.19.5 and 2.2.0), Cursor Agent (macOS and Linux only), Grok Build (1.0.70), Hermes Agent (0.22.5), the Antigravity CLI (agy 1.5.1 and 1.5.2) and Factory Droid (0.233.0 on macOS) have experimental adapters. Most offer micro-skills and the loop guard without tool pruning, and the Antigravity CLI supports only LLM-free facts. Limits per host are listed in the plugin README and in DROID.md.
  • Fail-safe behavior The plugin announces each action in one line. If any part of it fails, the session continues as if the plugin were not installed, and calls that get no reply are logged to ~/.tokeneconomizer/errors.log. If the agent CLI reports that it is not signed in, the plugin pauses its model calls and the next session start says so.
  • Experiment harness The experiments folder contains the harness, launchers and task sets that ran Claude Code, Codex and the Copilot CLI on SWE-Bench and Web-Bench for the paper, with one command per result. It shares only the tokeneconomizer/ package with the plugin and is not installed with it. Offline tests run with python -m pytest tests.

Where TokenEconomizer fits

Repeated agent sessions in the same repository

The project targets developers who run the same coding agent on the same repository many times. Each finished session's log updates what all three mechanisms know about that repository, and the next session starts with the active facts and the current deny list. Learning is kept per agent and repository, so facts Claude Code learned in a repository are not used by Codex there, while settings are shared by every agent.

Lowering per-request tool overhead

Because every loaded tool definition is part of every request, tool pruning reduces the size of each request once tools have gone unused for long enough. The toolprune command shows what was left out, what would be left out next and the evidence, and toolprune measure on Claude Code compares a request with and without the proposal. The PLUGIN.md document records how each agent's hooks and settings were verified to behave.

Handling turns stuck in failure loops

When a turn keeps producing the same failing output, the loop guard sends a digest to a judge model and, on a confident "stuck" verdict, adds a short redirect to try another approach. If the turn is still stuck afterwards, a notice states how to stop it on that agent, for example Esc in Claude Code or Esc followed by /stop in Codex. In headless runs such as claude -p or codex exec, a flagged turn continues until it ends, and te status later counts the redirects and notices.

Learning repository facts without model calls

With microskills=envfacts, the plugin learns only from repeated environment failures, so it adds no model calls of its own. Combined with the default tool pruning and an on-device judge on macOS 27, this keeps the plugin's own paid overhead limited to the cases the documentation describes. The README notes that how much micro-skills saves depends on the repository and the work done there.

Starting from existing Claude Code history

On Claude Code, config set history_import=on --global lets the first session in each repository read that repository's earlier Claude Code sessions in the background. This gives the mechanisms evidence before any new session has finished. The history import --dry-run command reports what would be read, and pruning based only on imported sessions waits for an explicit toolprune apply.

Reproducing the paper's measurements

Researchers can rerun the SWE-Bench and Web-Bench experiments from the experiments README, which gives the setup and one command per result. The benchmark adapters for SWE-Bench, Web-Bench, CredData and ReposVul sit in experiments/te_bench/adapters/, and the full method and results are in the arXiv paper. Pi users can find the host on iThub as Pi, and Codex users as Codex CLI.

Reviews of TokenEconomizer

No reviews yet

Be the first to share your experience with TokenEconomizer.

Loading review form…

Found TokenEconomizer useful? Upvote it todayYour vote helps other IT teams find it in the daily ranking.

Similar to TokenEconomizer

Compare:TokenEconomizer vs CodeBurnTokenEconomizer vs AutoModeTokenEconomizer vs Craft Anything

  1. CodeBurnLocal tracker of AI coding token usage and cost by tool, model, project, branch and taskAI Coding Assistants & Agent Tooling5 views
  2. AutoModeFree Claude Code plugin that routes each prompt to Haiku, Sonnet or Opus, with risk floors and reviewAI Coding Assistants & Agent Tooling8 views
  3. Craft AnythingRust app, CLI and MCP server that studies websites, apps and games, then has a coding agent build your own versionAI Coding Assistants & Agent Tooling59 views
  4. ArchonSelf-hosted engine that runs Claude Code, Codex and Pi through YAML workflows with approval pausesAI Coding Assistants & Agent Tooling16 views
  5. HOL GuardLocal-first runtime security for AI coding agents: review commands, packages and MCP calls before they runAI Coding Assistants & Agent Tooling14 views
  6. LazySkillsInspect, diagnose and manage AI agent skills across projects, global installs and agent hostsAI Coding Assistants & Agent Tooling12 views
  7. Grok BuildSpaceXAI terminal coding agent with a full-screen TUI, headless CI mode, ACP server and OS sandboxAI Coding Assistants & Agent Tooling9 views
  8. HappyRun Claude Code, Codex, Grok and Gemini agents on your own subscriptions, from desktop or phoneAI Coding Assistants & Agent Tooling8 views