TokenEconomizer

Cuts coding-agent token cost by up to 31% by learning per-repository facts, pruning unused tools and interrupting failure loops in Claude Code, Codex and Copilot CLI.

TokenEconomizer — preview card

The gist

An experience-driven, black-box cost control plugin for coding agents (Claude Code, OpenAI Codex, GitHub Copilot CLI, Pi, and experimental opencode) developed by UC Berkeley, Microsoft Research, and Microsoft Security. TokenEconomizer operates without touching model weights or agent code, cutting token expenditure by up to 31% in recurring repositories by extracting micro-skills from session logs, pruning unused tool schemas, and steering agents out of repetitive failure loops.

What it does

  • Micro-skills extraction: Learns repository-specific workflows and constraints (such as build commands, missing packages, or required environment variables) from session logs, establishing facts once confirmed across three sessions and pruning them if contradicted.
  • Dynamic tool pruning: Automatically removes unused tool definitions from the agent's context across sessions (removing tools unused over 10 prompts across 2+ sessions or across 5 consecutive sessions), slashing per-turn prompt overhead while remaining restorable with a single command.
  • Failure-loop intervention: Monitors repetitive error loops and applies a calibrated judge model (≥0.7 confidence) to inject a single redirect prompt per turn, advising the developer on how to interrupt runaway cycles without unilaterally terminating sessions.
  • Empirically validated token savings: Benchmarked across 277 SWE-Bench tasks in 6 repositories with 5 agent-model combinations, achieving 18.4% to 30.9% lower mean costs across all 30 repository-combo cells while maintaining or improving Pass@1 in 4 of 5 combinations.
  • Zero API key overhead: Keeps all state local in ~/.tokeneconomizer, utilizing the developer's existing agent subscription/credentials with all auxiliary model calls accounted for in cost reporting.

How it works

Architecture Diagram
TokenEconomizer Architecture Diagram

TokenEconomizer installs directly as a local plugin and hook layer within your existing agent CLI. It runs silently in the background, reviewing local session logs every k=3 sessions to hypothesize and validate repository facts, adjusting agent configuration files to prune inactive tool definitions, and passing turn history through a lightweight evaluator to suggest failure escapes. All state remains isolated on your local machine in ~/.tokeneconomizer with no external telemetry or separate credentials required.

Best for

  • Software engineers and teams using Claude Code, Codex, or Copilot CLI on a daily basis within the same core repositories.
  • Developers running multi-turn autonomous coding tasks who want to reduce API billing and token burn without degrading benchmark solve rates.
  • Users looking for transparent, locally managed prompt optimization that introduces no third-party cloud proxy or credentials.

Watch out for

  • Strict agent-version pinning: Supported agent ranges are narrow (Claude Code 2.1.300–2.1.310, Codex 0.153.1–0.164.0, Copilot CLI 1.0.83–1.0.102, Pi 1.2.0–1.3.0, opencode 1.19.5/2.2.0 experimental); newer upstream agent releases may break plugin hooks.
  • Multi-step setup and re-configuration: Setup requires running /tokeneconomizer:toolprune refresh-catalog initially and after each agent update, while Codex requires re-adding plugins and trusting hooks on each git pull.
  • Agent configuration modifications: Tool pruning directly edits your agent's local settings, prompting required trust and security confirmations during installation and hook registration.
  • Value accrues only in repeat repositories: Savings require return sessions to manifest, with facts requiring three validating sessions before activation; one-off codebases yield minimal benefit, and Pass@1 dropped slightly on Opus 4.8 (-1.0).

What you need: Python 3.10+ (standard library only) and a supported coding agent (Claude Code, Codex, or Copilot CLI). Cost: Free, open source (Apache-2.0).