How Much To Run AI

TokenEconomizer: measure the cost of repeated coding tasks

TokenEconomizer learns repo facts across coding-agent sessions, prunes unused tools and nudges stuck runs. See agent support, setup, costs and savings.

Last updated: 2026-11-21

TokenEconomizer is an open-source plugin for coding agents. It learns operational facts from earlier work in a repository, can leave persistently unused tools out of later sessions, and can nudge an agent when a task appears stuck in a failure loop. The project reports lower model costs across repeated coding tasks, with the plugin’s own model calls counted in those costs.

It fits teams or developers who return to the same codebase for many tasks. It has less to learn in a one-off repository, and it does not change a model’s token prices or make an agent work without its usual provider account.

TokenEconomizer defaults: micro-skills off, tool pruning on and reversible, loop guard on. Compare all model calls, plugin calls, retries, cache use and accepted tasks across sessions.

Original diagram of documented mechanisms and the task-cost comparison; research savings are not a fixed billing discount.

How TokenEconomizer works

TokenEconomizer keeps state on the machine running the agent, under ~/.tokeneconomizer. It uses three separate mechanisms:

  • Micro-skills put repeatedly confirmed repository facts into later sessions: a build command, an environment variable a test needs, or where generated files live. Micro-skills are off by default. If you enable them, an environment-facts mode can learn from repeated failures without a proposer call.
  • Tool pruning uses evidence that tools have gone unused before leaving them out of later sessions. The change is reversible. The available pruning unit depends on the agent: Codex can omit capability packages, while Claude Code can omit individual tools.
  • Loop guard checks turns that show signs of repeating failures. A judge model may add a short redirect. It does not stop the agent; if the task remains stuck, it tells you so you can decide what to do.

The mechanisms have separate switches and do not trigger on every task. Tool pruning and the loop guard are on by default; micro-skills are off. Micro-skills need repeated evidence before they inject a fact. Tool pruning waits for unused-tool evidence across prompts and sessions. The loop guard first needs examples of turns that made progress, then acts only when a turn appears stuck. Check status, microskills and config to see what the plugin has actually learned or changed. From a terminal in the repository, ~/.tokeneconomizer/bin/te toolprune restore restores tools removed by pruning.

Install TokenEconomizer in a supported agent

The plugin requires Python 3.10 or newer on PATH and one of its supported coding agents. For Codex, clone the repository, add its local marketplace and install the plugin:

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

Trust the plugin hooks when Codex prompts, then restart Codex so the hooks load in a new session. In the project you want to work on, run $tokeneconomizer:status to confirm the plugin is active. The clone must stay in place because the plugin runs from that folder. Claude Code and GitHub Copilot CLI have equivalent marketplace commands in the project README; Pi uses pi install git:github.com/microsoft/TokenEconomizer.

As of November 16, 2026, the project lists these tested release ranges as supported:

AgentTested versions
Claude Code2.1.300–2.1.310
Codex0.153.1–0.164.0
GitHub Copilot CLI1.0.83–1.0.102
Pi1.2.0–1.3.0

The README says newer versions have not been tested. It also lists opencode, Cursor Agent, Grok Build, Hermes Agent, Antigravity CLI and Factory Droid as experimental integrations, with missing features or untested surfaces. Check the current compatibility table before installing after an agent update.

TokenEconomizer is Apache-2.0 licensed. It does not need its own API key or subscription: its proposer and judge calls use the same agent login or plan as your regular work. Those calls still consume model usage and can add cost, especially if you enable the micro-skill proposer. With plan-based access, they use that plan’s allowance; with usage-based access, they are billed like other model calls. The plugin’s reports include its model calls and account for cached input tokens.

Tune TokenEconomizer's defaults

Each mechanism has its own settings, and config set changes them for the current repository; add --global to change every repository. Tool pruning waits for a tool to go unused across 10 prompts spanning at least 2 sessions, or across 5 sessions of any length, and writes its deny list only after your sessions have been idle for 60 minutes, so a resumed conversation does not force a full prompt-cache rewrite. The micro-skills proposer runs every 3 sessions by default, and a fact is injected at session start once three sessions have confirmed it. The loop guard waits for 5 turns that ended well before it acts, asks its judge for at least 0.7 confidence, and writes at most 1 redirect per turn.

Two quieter modes help you watch before committing. toolprune=propose lists the deny list it would apply without changing anything until you run toolprune apply; microskills=envfacts learns from repeated failures with no model calls at all. TE_DISABLE=1 turns TokenEconomizer off for a single session without touching your saved settings.

What TokenEconomizer's reported savings mean

The authors evaluated five agent-model combinations on 277 SWE-Bench tasks across six repositories. Each task ran in a new session; tasks for a repository ran in sequence, starting with no learned facts. The project reports 18.4–30.9% lower mean model cost, lower cost in all 30 repository-by-combination cells, and a higher Pass@1 score in four of five combinations. The paper also reports 6.4–21.2% lower costs on sequential web-development and security-auditing tasks.

For scale, if your comparable repeated-repository workload would otherwise cost $100 in model usage, applying the study’s 18.4–30.9% range gives an illustrative $69.10–$81.60 after TokenEconomizer, including its own model calls. That is a conversion of the authors’ experiment, not a guaranteed saving for an individual developer. Results depend on whether your sessions repeat the same facts, leave tools unused or encounter failure loops.

A GitHub issue shows why checking real activity matters. On November 2, a user reported 15 folded sessions and 161.5 million effective tokens but no learned facts, pruning proposals or loop redirects. Maintainer Aaron Li replied that the plugin had observed only about 14 turns and learned from four sessions because some conversations began before the plugin was enabled. Each mechanism also waits for its own evidence threshold. The user’s 0.6% overhead was observed in that setup; it is not a universal overhead rate. Use the status commands and compare complete task costs over repeated sessions before deciding whether to keep the plugin enabled.

Compare the cost of finished tasks

Choose several repository tasks with clear checks: a failing test that must pass, a bug report with a reproducible case, or a review whose findings you can verify. Keep the agent, model, reasoning setting and starting commit with each result. Save the entire session’s input, cached input and output usage, including TokenEconomizer’s own calls, along with whether the task passed and whether it needed another attempt.

If you are evaluating a change to model weights, the Qwen3.8-27B harness adapter case shows why comparing task completion alongside token use matters.

Compare a sequence of tasks rather than a single prompt, because learned facts and unused-tool evidence accumulate over time. Check the plugin’s status between sessions. If nothing has fired, the run is testing its inactive overhead as well as normal model variation; it does not tell you what pruning would save once it applies. With a flat subscription, compare allowance consumed and completed work separately from an API-equivalent dollar estimate.

For plain prompts against a cloud or local endpoint, the LLM CLI guide covers client setup and provider usage. For a coding-agent loop, compare DeepSeek Harness; TokenEconomizer supplements an agent rather than supplying that workflow itself. Use the budget notes to keep model usage and your own time in the same task budget.

Sources

Checked 2026-11-16: TokenEconomizer README, installation, compatibility and settings, research paper, GitHub issue #113 and maintainer reply, and Reddit discussion.