# microsoft/tokeneconomizer

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/microsoft-tokeneconomizer).**

_How this analysis was created: the description and tags below were written by an AI model that read this project's README and public documentation pages; stars, license and language come straight from the GitHub API. The model does not read the source code._

4,948 stars · 303 forks · Python · Apache-2.0

## Links

- GitHub: https://github.com/microsoft/TokenEconomizer
- awesome-repositories: https://awesome-repositories.com/repository/microsoft-tokeneconomizer.md

## Topics

`agentic-ai` `agentic-coding` `ai-coding` `ai-coding-assistant` `anthropic` `artificial-intelligence` `claude-code` `codex` `coding-agent` `coding-agents` `cost-optimization` `cost-reduction` `developer-tools` `github-copilot` `llm` `open-source` `openai` `productivity` `token-optimization`

## Description

TokenEconomizer is a plugin that cuts the token spend of AI coding agents without modifying the agents themselves. It learns from an agent's past sessions in a repository and applies that experience to later sessions. It installs into agents such as Claude Code, Codex, Copilot CLI and Pi, reuses the user's existing login, and has experimental support for other agents.

It does this through three mechanisms. Repository fact learning extracts recurring details such as working command spellings, required build steps and environment variables from repeated failures and session reviews, then states them at the start of each new session. Tool pruning tracks which tools go unused across enough prompts and sessions, then omits them through the agent's own settings so their definitions stop being sent with every request; a single command restores them. Failure loop breaking counts repeated failures within a turn, asks a separate judge model whether the agent is stuck, and sends a limited redirect toward a different approach.

Each mechanism and its thresholds can be switched on or off independently, per repository or globally. Users can inspect what was learned, injected and removed, and report session costs, including the model calls the tool itself makes. The repository also bundles a containerized harness with launchers and task sets for SWE-Bench and Web-Bench, so cost-savings experiments can be rerun and the results reproduced.

## Tags

### Artificial Intelligence & ML

- [Agent Token Optimizations](https://awesome-repositories.com/f/artificial-intelligence-ml/agent-token-optimizations.md) — Learns from past coding agent sessions in a repository and applies that experience to cut token spend in later sessions without modifying the agent.
- [Coding Agents](https://awesome-repositories.com/f/artificial-intelligence-ml/agentic-systems-frameworks/integration-deployment/ai-agent-tooling/coding-agents.md) — Cuts token spend of AI coding agents by learning from past sessions in a repository, without modifying the agents themselves.
- [Idle Tool Pruning](https://awesome-repositories.com/f/artificial-intelligence-ml/agent-architectures/tool-based-architectures/idle-tool-pruning.md) — Tracks tool usage across many prompts and sessions, then disables idle tools through agent settings so their definitions leave every request.
- [Agent Failure Mitigation](https://awesome-repositories.com/f/artificial-intelligence-ml/agent-failure-mitigation.md) — Detects repeated failures within a turn, checks with a judge model whether the agent is stuck, and sends a limited redirect toward another approach. ([source](https://github.com/microsoft/tokeneconomizer#readme))
- [Unused Tool Pruning](https://awesome-repositories.com/f/artificial-intelligence-ml/unused-tool-pruning.md) — Omits tools unused across enough prompts and sessions through the agent's own settings so definitions stop being sent, with one-command restoration. ([source](https://github.com/microsoft/tokeneconomizer#readme))
- [Stuck Agent Detection](https://awesome-repositories.com/f/artificial-intelligence-ml/machine-learning/infrastructure/model-evaluation-analysis/stuck-agent-detection.md) — Counts repeated failures within a turn and asks a separate judge model whether the agent is looping before sending a redirect.

### Data & Databases

- [Fact Extraction Pipelines](https://awesome-repositories.com/f/data-databases/data-processing-pipelines/data-processing/document-unstructured-extraction/fact-extraction-pipelines.md) — Extracts recurring facts such as working commands, build steps and environment variables from repeated failures and session reviews, then states them at session start. ([source](https://github.com/microsoft/tokeneconomizer#readme))
- [Project Knowledge Retention](https://awesome-repositories.com/f/data-databases/technical-knowledge-bases/knowledge-retention-tools/project-knowledge-retention.md) — Remembers working commands, build steps and environment details from earlier sessions so each new agent session already knows how the project behaves.

### System Administration & Monitoring

- [Token Cost Optimizations](https://awesome-repositories.com/f/system-administration-monitoring/usage-monitoring/token-usage-analytics/token-consumption-trackers/token-cost-optimizations.md) — Reduces token usage by pruning unused tool definitions, stating learned repository facts up front, and redirecting stuck agents, all without changing the agent.

### Development Tools & Productivity

- [Coding Agent Plugin Packages](https://awesome-repositories.com/f/development-tools-productivity/coding-agent-plugin-packages.md) — Installs as a plugin into coding agents such as Claude Code, Codex, Copilot CLI and Pi, reusing the user's existing login.

### Software Engineering & Architecture

- [Session Context Blocks](https://awesome-repositories.com/f/software-engineering-architecture/context-aware-tooling/prompt-context-aggregators/session-context-blocks.md) — Prepends distilled repository facts such as build steps and environment variables to each new session's context before the agent starts.
- [Agentic Error Recovery](https://awesome-repositories.com/f/software-engineering-architecture/stream-failure-recovery/agentic-error-recovery.md) — Spots when a coding agent repeats the same failing steps and nudges it toward a different approach to stop wasting tokens.
