microsoft/TokenEconomizer

A cost-saving plugin for coding agents: without modifying the agent itself, it learns from sessions you have run in the same repository and reduces waste in three ways—remembering fixed facts about the repository, no longer loading tools that have not been used for a long time, and inserting a reminder when a turn gets stuck in a failure loop.

A cost-saving plugin for coding agents: without modifying the agent itself, it learns from sessions you have run in the same repository and reduces waste in three ways—remembering fixed facts about the repository, no longer loading tools that have not been used for a long time, and inserting a reminder when a turn gets stuck in a failure loop.

Stars 1945 (+49 / 24h)

Rationale

  • Micro-skills: Facts are extracted from failures that recur across multiple sessions and from model reviews every 3 sessions (for example, using python -m pytest here, or a specific build step that must run first). These facts are injected at the start of a session after being confirmed over 3 sessions, and are deleted if later disproven.
  • Tool pruning: If a tool is unused across 10 prompts spanning at least 2 sessions, or in any 5 sessions, it is excluded via the agent's own configuration file; this can be restored with a single command. Loop guard: When the same failure recurs, a judgment model checks it, and a redirection reminder is inserted only once if the confidence is ≥0.7; it never terminates the turn for you.
  • The paper claims that across 277 SWE-Bench tasks in 6 repositories, the average cost for 5 agent and model combinations decreased by 18.4–30.9%, with all 30 repository-combination cells showing savings, and Pass@1 improving for 4 combinations; costs are calculated using cached pricing and include the plugin's own model calls. The authors are from UC Berkeley, Microsoft Research, and the Microsoft Security Team.

Usage

  • Claude Code: After cloning the repository, run claude plugin marketplace add "$PWD/TokenEconomizer", then claude plugin install tokeneconomizer@tokeneconomizer. Enter the repository and run /tokeneconomizer:status. Run /tokeneconomizer:toolprune refresh-catalog once per machine.
  • Add the plugin marketplace in the same way for Codex and Copilot CLI; for Pi, use pi install git:github.com/microsoft/TokenEconomizer; opencode has experimental support. Requires Python 3.10+, no separate API Key needed.
  • Tool pruning and loop guard are enabled by default, while micro-skills are disabled by default (as they incur additional model calls): enable them with config set microskills=on; use toolprune=propose to only suggest changes without modifying settings; for a single session, you can disable them using TE\_DISABLE=1.

Risks

  • Tested only within the version ranges listed in the README (e.g., Claude Code 2.1.300 to 2.1.310, Codex 0.153.1 to 0.164.0); older versions are not supported, and Codex versions prior to 0.141.0 do not run plugin hooks at all.
  • Savings depend on how frequently you work repeatedly in the same repository; tool pruning writes to files such as .claude/settings.local.json (automatically added to .git/info/exclude); the repository was created on 13 10 month, licensed under Apache-2.0.

Open

Trendshift(GitHub Trending 快照)

Explore the latest AI Radar updates