Developers working repeatedly in the same repository can reduce the cost of AI coding agents rediscovering familiar procedures and loading unused tools. TokenEconomizer is an open-source plugin from UC Berkeley, Microsoft Research, and Microsoft Security. It applies repository-specific experience from earlier sessions to subsequent tasks. It works alongside existing workflows without changing the agent or model.

1. Repetition and failures drive up costs

Microsoft Research examined Claude Code on 60 tasks from SWE-Bench, a benchmark of open-source Python bug fixes that tests task-solving ability. Tasks ran sequentially within each repository. In repositories with at least 5 completed tasks, 30% of tool calls repeated past work from that repository. Calls matching records from other repositories accounted for 7%.

The agent received 23 tool descriptions each turn, but 16 of those tools were never called. Failed tasks made up 17% of all tasks but accounted for 32% of total spending. The analysis attributed token costs to rediscovering familiar procedures, unused tool descriptions, and unsuccessful attempts.

The researchers also tested three open-source plugins with fixed cost-saving strategies. Each reduced costs in some repositories but not in others. The team concluded that savings strategies needed to adapt to each repository's task history.

2. Turning session histories into guidance for the next task

After each session, TokenEconomizer reads the record and updates its understanding of the repository. Micro-skills, small instructions summarizing recurring work, turn repeatedly observed task patterns into one-line notes. Notes enter the agent's starting context—the information given to the model at task startup—only after patterns recur across sessions. They are withdrawn if later evidence contradicts them.

The original diagram gives an example of remembering how to run tests with this command.

python -m pytest

Tool pruning removes tools unlikely to be used based on repository history, while retaining essential tools for running commands and editing files. Removed tools can be restored when needed.

Failure-loop intervention uses a separate model to check whether a task is stuck or still progressing when the same error recurs. If it judges the task to be stuck, it sends a short note suggesting another approach. All three methods work through interfaces the agent already provides.

3. Lower costs on bug-fixing tasks

The evaluation covered 277 SWE-Bench tasks, 6 repositories, and 5 agent-model combinations. Each repository started without prior session history. According to the company, average costs fell by 18.4~30.9%, with the largest savings across all 30 repository-combination pairs. Task success rates were largely maintained, and the share of tasks solved in a single attempt rose in four of the five combinations.

For comparison, the team also examined lowering reasoning effort, the computation a model uses to find an answer. The researchers reported similar or greater savings from that method, but with a larger performance decline. Each of TokenEconomizer's three techniques contributed to savings, with the largest reduction when used together.

4. Savings across other task structures

According to the company, costs fell by 16.0~21.2% on Web-Bench, a sequential web development benchmark. Security audits, reviews that check for vulnerabilities and use a new repository for each task, saw reductions of 6.4~19.6%. The team reported savings not only on repeated tasks that favor accumulated experience, but also on tasks that switch repositories each time.

5. Recovering initial learning costs through cumulative savings

The plugin works without a separate API key or changes to the existing agent and model, and stores what it learns on the developer's computer.

Reducing repeated exploration requires extra model calls to analyze records and make judgments; the company's reported savings include these costs. Initial tasks can cost more due to learning overhead. In the Claude Code evaluation, however, cumulative costs in every repository fell below the default configuration by the sixth task. Adoption thus hinges less on the first task's bill than on the cumulative cost of continued work in the same repository.

If a task remains stuck after failure-loop intervention, the plugin notifies the developer rather than stopping it directly.

TokenEconomizer turns repository experience from repeated use into cost savings, with gains growing as experience accumulates beyond the initial learning overhead.