TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents

Aaron J. Li, Weijia Xu, Chandan Singh, Zixiao Chen, Jeevana Priya Inala, Charlotte Siska, Acar Tamersoy, Bin Yu, Ion Stoica, Michel Galley, Jianfeng GaoarXiv 2026

TL;DR

TokenEconomizer is an external "black-box" controller that slashes the token costs of AI coding agents by up to 31% without sacrificing performance. By learning from past tasks in a specific codebase, it adaptively prunes unused tools, injects "micro-skills" to prevent trial-and-error, and kills expensive, unproductive failure loops.

What Problem Does This Paper Address?

Modern AI coding agents (like Claude Code or GitHub Copilot CLI) are powerful but notoriously expensive. They operate in a "harness" that manages tools and context, but as an agent works, its conversation history grows. Because LLMs are billed for the entire context at every turn, earlier parts of the conversation are paid for repeatedly.

Furthermore, most evaluations treat coding tasks as isolated events. In reality, developers work in the same repository for long periods. Current agents often "rediscover" the same environment facts—like how to run a specific test suite or where certain files live—every time they start a new task, wasting thousands of tokens on repetitive exploration.

Methods

The authors introduce TokenEconomizer, a controller that sits between the user and the agent. It treats the agent as a "black box," meaning it works with existing commercial products without needing access to their internal code or model weights. It uses three adaptive "meta-strategies":

  1. Experience-grounded Micro-skills: It distills operational facts (e.g., "use python -m pytest for tests") from previous successful runs and injects them as a short "manual" in the prompt. This prevents the agent from wasting tokens guessing the wrong commands.
  2. Tool Pruning: Most agents are loaded with dozens of tools, many of which are never used in a specific repo. TokenEconomizer identifies and masks these irrelevant tools to keep the system prompt lean.
  3. Failure-loop Intervention: It monitors the agent's live rollout. If the agent gets stuck in a repetitive loop (e.g., editing the same file over and over with the same error), an LLM "judge" intervenes to either redirect the agent with a hint or abort the run to save tokens.
Figure 1. Trajectory anatomy and the cost–quality tradeoff. (a) Schematic of how the persistent prefix and interaction history accumulate across agent turns. (b) Cost and Pass@1 change of each method relative to high-effort default execution, one point per method in each of the five agent–model settings; the dashed line marks the Pareto frontier.

Datasets

The system was evaluated across several diverse benchmarks:

  • SWE-Bench (Verified & Full): 277 real-world software engineering tasks across 6 major Python repositories (e.g., Django, scikit-learn).
  • Web-Bench: 102 sequential tasks for building web applications.
  • CredData & ReposVul: 200 security-auditing tasks focused on credential and vulnerability detection.

Key Insights and Ideas

  • Environment Continuity is an Opportunity: While individual coding problems are hard, the environment (the repo) is stable. Learning repository-specific policies from a stream of tasks is more effective than "fixed" strategies (like standard RAG) that don't adapt.
  • Failed Tasks are the Biggest Spenders: The authors found that while failed tasks were only 17% of the total, they accounted for 32% of the total token cost because they tend to run much longer than successful ones.
  • Fixed Strategies are Hit-or-Miss: Popular tools like "RepoMap" help in some repositories but actually increase costs in others. Adaptive control is necessary to ensure consistent savings across different codebases.
Figure 3. Three trace-derived sources of cost-control headroom across the 60 profiled tasks: (a) actions repeated from earlier tasks in the same repository, with another repository’s history as a control; (b) loaded tools used by each repository, with frequencies indicated by square sizes; and (c) the cost share and trajectory lengths of failed tasks.

Key Results

  • Significant Savings: TokenEconomizer reduced mean per-task costs on SWE-Bench by 18.4% to 30.9% across different models (Claude 3.5 Sonnet, Opus, GPT-4o variants).
  • Maintained Performance: Crucially, these savings didn't come at the expense of accuracy. In 4 out of 5 settings, the "Pass@1" success rate actually improved or stayed comparable to the expensive default execution.
  • Generalizability: The method transferred well to other domains, saving 16–21% on web development tasks and 6–20% on security audits.
  • Pareto Superiority: TokenEconomizer variants effectively define a new Pareto frontier, offering a better trade-off between cost and quality than simply reducing the model's "reasoning effort" (see Figure 1b above).

Limitations and Future Work

  • Risk of Incorrect Decisions: A meta-strategy might occasionally prune a tool that is actually needed for a rare task or misidentify a difficult but productive run as a "failure loop." The authors mitigate this with periodic "re-audits" and conservative intervention thresholds.
  • Harness Dependency: While "black-box," the controller still needs a lightweight "adapter" for each specific agent harness (e.g., one for Claude Code, one for Copilot) to read its event stream.
  • Interactive Workflows: The current evaluation uses independent fixes. The authors suggest that in real-world "interactive" sessions where tasks are highly interdependent, the potential for experience reuse—and thus cost savings—might be even higher.

Summary updated

BibTeX
@misc{li2026tokeneconomizer,
  author = {Aaron J. Li and Weijia Xu and Chandan Singh and Zixiao Chen and Jeevana Priya Inala and Charlotte Siska and Acar Tamersoy and Bin Yu and Ion Stoica and Michel Galley and Jianfeng Gao},
  title = {{TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents}},
  year = {2026},
  eprint = {2610.22732},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.22732},
}
Figure