# Repository Briefing: microsoft/TokenEconomizer
> Source: https://repoforai.com/repo/microsoft/TokenEconomizer (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/microsoft/TokenEconomizer
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: A+ (93/100 · Maintenance 35/35 · Adoption 18/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.1.0 (2026-10-26) — https://github.com/microsoft/TokenEconomizer/releases
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: CLI
- **Momentum**: 8,344 ★ total (+12 24h / +173 7d) · 601 forks
- **Topics**: `agentic-ai`, `agentic-coding`, `ai-coding`, `ai-coding-assistant`, `anthropic`, `artificial-intelligence`, `claude-code`, `codex`, `coding-agent`, `coding-agents`, `cost-optimization`, `cost-reduction`
- **When to Use**: Best for: Teams that repeatedly use a supported coding agent in the same repositories and can compare billed cost, tool availability, and task success during a pilot. Skip if: Work mostly happens in one-off repositories, every tool must remain available, or policy rules out the extra model calls needed for the features you want.

## Overview
```text
### Architecture & Core Mechanics
TokenEconomizer is an in-process integration from the user's perspective, but it does not modify the host agent's code or model. It uses host hooks and session traces to learn repository facts, measure tool use, and establish what a normal turn looks like. Learning is scoped to each agent–repository pair, while settings are shared across agents. Interventions use interfaces the host already understands: injected context for facts and redirects, and native configuration for tool pruning.

The mechanisms, trace reader, ledger, and plugin runtime live in a Python package with no third-party runtime dependencies. The bundled `plugin/scripts/te` launcher does not require a separate package install. Pi has a TypeScript extension under `plugin/pi/` and declares `@earendil-works/pi-coding-agent` in `package.json`. Despite working with MCP tools on some hosts, TokenEconomizer is a host plugin, not a standalone MCP server.

### Key Capabilities & Differentiators
Micro-skills combine recurring failures with periodic model proposals. A fact enters the session-start context only after three sessions confirm it and is dropped if later evidence contradicts it. Tool pruning uses inactivity thresholds, but its precision depends on the host: individual tools in Claude Code, capability packages in Codex, and whole MCP servers in Copilot CLI. Pi has no pruning. The loop guard builds a baseline from successful turns, then evaluates suspected loops. It can bypass the judge when a turn repeatedly churns through the same edits and failures beyond 2.5 times its typical length. It redirects rather than interrupting execution.

Across 277 SWE-Bench tasks from six repositories, five agent–model combinations recorded 18.4–30.9% lower mean cost, and Pass@1 improved in four of five. Costs include cached-token pricing and the plugin's own model calls. Tasks were run in order within each repository starting with no learned state, so the aggregate result includes a cold start but is not a prediction for an isolated session.

### Trade-offs & Limitations
Compared with hand-written repository instructions and a fixed tool allowlist, TokenEconomizer reduces manual upkeep by learning from what actually happens in sessions. The cost is a warm-up period and less predictable tool availability: pruning a whole MCP server can hide a rarely used but important tool along with the unused ones. Micro-skills are off by default because their proposer adds model calls, and the value of those calls depends on how often work repeats.

Pruning changes only plugin-managed entries, preserves existing deny rules, and can be reversed with `toolprune restore`. When a target file cannot be edited safely—for example, a tracked `.codex/config.toml` or invalid JSON—the plugin leaves a proposal instead of writing it. Measure billed cost and task completion together during a pilot. Use the terminal CLI for routine inspection when possible, since invoking the equivalent command inside the agent costs a model turn.

### Hardware & Deployment Guide
Put Python 3.10+ on `PATH` and sign into a supported host. The standard plugin needs neither its own API key nor a GPU stack. Claude Code, Codex, and Copilot CLI install through a marketplace backed by a local clone, which must stay in place; Pi uses `pi install git:github.com/microsoft/TokenEconomizer`. Review host permissions during setup. Codex hooks take effect in the next session after approval, and Claude Code and Copilot CLI require a tool catalog refresh on initial setup and after host updates.

The first release, v0.1.0, covers Claude Code 2.1.300–2.1.329, Codex 0.153.1–0.171.0, Copilot CLI 1.0.83–1.0.114, and Pi 1.2.0–1.5.2, with a separate load-by-path route for Pi 0.99.x. Only the endpoints of the listed ranges were tested; newer versions are untested. Treat experimental hosts as separate rollout targets: for example, Cursor's tested headless configuration did not provide session usage, and its interactive TUI remains untested.
```

## Key Capabilities
```text
- Runtime: The Python 3.10+ core has no third-party dependencies and ships a launcher at `plugin/scripts/te`; the Pi integration declares `@earendil-works/pi-coding-agent`.
- Micro-skills: Off by default; when enabled, the model proposer runs every three sessions by default, and a fact is injected only after confirmation in three sessions.
- Pruning evidence: A tool qualifies after 10 unused prompts across at least two sessions, or five sessions of any length; deny-list writes wait for 60 minutes of repository inactivity by default.
- Host granularity: Claude Code prunes individual tools, Codex prunes capability packages, and Copilot CLI prunes entire MCP servers; Pi does not prune.
- Loop policy: After five successful baseline turns, the default judge threshold is 0.7 with at most one redirect per turn; a 2.5× backstop covers prolonged repeated failures.
- Cost accounting: On 277 SWE-Bench tasks, mean cost was 18.4–30.9% lower across five agent–model combinations, with cache pricing and plugin model calls included.
```

## Quick Start / Clone
```bash
git clone https://github.com/microsoft/TokenEconomizer.git
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizer
```
