arXiv:2610.22732cs.CLOct 2026

Manuscript Offprint

arXiv:2610.22732

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 Gao

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Advances in frontier coding agents have sharply increased the token costs of AI-assisted software engineering. Their token efficiency is typically evaluated on isolated tasks, whereas real-world developers use them to continuously build, update, and maintain large-scale projects. This mismatch motivates us to evaluate agents over sequences of realistic coding tasks, where we find that agents exhibit recurring environment-dependent token costs that existing methods struggle to reduce. To minimize these costs, we introduce TOKENECONOMIZER, an external controller that cuts environment-specific token costs over a sequence of tasks. These cuts come from determining (i) which operational micro-skills to inject, (ii) which persistently irrelevant tools to prune, and (iii) when to intervene in unproductive failure loops. Across Claude Code, Codex, and GitHub Copilot CLI paired with frontier models, TOKENECONOMIZER reduces the average token cost by 18.4–30.9% with comparable task success. Savings hold in every repository under every tested agent–model setting and generalize to diverse domains such as sequential web development and security auditing, where costs fall by 6.4–21.2% depending on task structure. Our work establishes adaptive black-box cost control as a promising direction for reducing token costs of coding agents in realistic settings.

1 Introduction

Frontier large language models (LLMs), coupled with agent harnesses that support tool use (Yang et al., 2024; Wang et al., 2024b; 2025a), have become increasingly capable of completing realistic, long-horizon software engineering tasks (Jimenez et al., 2024; Zhou et al., 2024; Xu et al., 2025; Deng et al., 2025; Merrill et al., 2026; Huang et al., 2026). These components are commonly packaged as commercial products, including Claude Code, Codex, and GitHub Copilot CLI. These agents are designed primarily for generic task success, but their increased capability comes at a substantial token cost. As shown in Fig. 1a, the billed context at each turn includes persistent system and user instructions together with an expanding history of model outputs and tool interactions, causing earlier content to be charged repeatedly across the trajectory.

Token efficiency has primarily been studied and optimized at the level of individual tasks. Model-level controls such as lower reasoning effort save tokens at a cost in task success (Table 1), while harness-level controls such as tool availability and auxiliary instructions typically require manual configuration. More targeted approaches to trajectory compression, observation filtering, and specialized repository exploration often require agent-loop modifications or additional trained components (Xiao et al., 2025; Kovács, 2026; Li et al., 2026b), limiting their plug-and-play deployment. More importantly, task-local optimization overlooks the continuity of software development, where successive changes occur within an evolving codebase (Xu

*Work done during an internship at Microsoft Research. Correspondence to: aaronjli@berkeley.edu.

Figure

(a) Anatomy of a billed trajectory (schematic)

Figure

(b) Cost-quality tradeoff on SWE-Bench

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.

et al., 2025; Joshi et al., 2025; Zhu et al., 2026; Yan et al., 2026). Such continuity creates an opportunity for cost control: within a shared environment, such as a code repository, completed executions can provide reusable experience for future tasks. We therefore optimize cumulative cost across a sequence of tasks in that environment, rather than treating each execution in isolation.

We first test whether fixed, externally applied cost-control strategies can deliver consistent token savings. Our cost profiling covers 60 SWE-Bench tasks across 6 repositories (Jimenez et al., 2024) and evaluates three representative fixed strategies from popular open-source plugins: command-output compression with Rust Token Killer (RTK), semantic code navigation with Serena, and structural context injection with Aider's repository map. Empirically, we find that no fixed strategy reduces cost consistently: each has both positive and negative repository-level effects, and their pooled effects are small (Fig. 2). Meanwhile, the default traces reveal three recurring sources of headroom: operational knowledge is repeatedly rediscovered, most loaded tools remain unused, and failed trajectories consume disproportionate cost. Taken together, these findings point to strategies that adapt to each environment from its accumulated traces, rather than fixed strategies applied uniformly.

Motivated by these findings, we introduce TOKENECONOMIZER, an experience-driven external controller for coding agents. It treats each agent as a black box: it acts through exposed prompt and tool settings, monitors execution events, and does not modify model weights or agent-loop code. At its core, a controller applies general cost-control meta-strategies to continually refine environment-specific policies from completed execution traces. These policies adaptively determine (i) which one-line operational facts about the environment to activate as micro-skills, (ii) which loaded but irrelevant tools to prune, and (iii) when to intervene in unproductive failure loops. We evaluate TOKENECONOMIZER with Claude Code, Codex, and GitHub Copilot CLI, paired with frontier models, on 277 SWE-Bench tasks across 6 repositories, 102 Web-Bench tasks across 5 web-development projects, and 200 tasks from two security-auditing benchmarks. Including all controller overhead, our method reduces mean per-task cost on SWE-Bench by 18.4–30.9%, while improving Pass@1 over default execution in 4 of 5 agent-model settings. Cost savings hold in every repository under each tested agent-model setting (Fig. 5a), and TOKENECONOMIZER variants account for every point on the cost-quality Pareto frontier at or above the default pass rate (Fig. 1b). On Web-Bench and the security benchmarks, it reduces cost by 16.0–21.2% and 6.4–19.6%, respectively, with Pass@2 and detection F1 remaining comparable to default execution. Our results show that our external cost-control framework can deliver consistent and transferable cost reductions across distinct agent harnesses while maintaining comparable task quality.

Figure

Figure 2. Per-repository cache-aware cost change of the three fixed strategies relative to default execution on the 60 profiled tasks (negative is cheaper). Every strategy lowers cost in some repositories and raises it in others.

Our contributions can be summarized as follows:

  1. We formulate coding-agent cost optimization over sequences of tasks and define a standardized protocol for cumulative end-to-end accounting. Our cost profiling identifies repository-dependent effects of fixed strategies and three actionable sources of headroom.

  2. We introduce TOKENECONOMIZER, an external controller that learns environment-specific policies for micro-skill activation, tool pruning, and failure-loop intervention.

  3. We evaluate TOKENECONOMIZER across three popular coding agents and four benchmarks spanning 579 tasks, demonstrating cost reductions that hold in every setting we measure, with comparable task success.

References (85)