TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents
Organizations: UC Berkeley · Microsoft Research · Microsoft Security
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.
Figures & tables
| Claude Code | Codex | Copilot CLI | ||||||||
| Method | Sonnet 5 | Opus 4.8 | GPT-5.6 Terra | GPT-5.6 Sol | Sonnet 5 | |||||
| Cost | Pass@1 | Cost | Pass@1 | Cost | Pass@1 | Cost | Pass@1 | Cost | Pass@1 | |
| Default | — | — | — | — | — | |||||
| Default (medium effort) | ||||||||||
| Default (low effort) | ||||||||||
| RTK | ||||||||||
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Default | RTK | Serena | RepoMap | ||||
|---|---|---|---|---|---|---|---|
| Repository | Pass@1 | cost | Pass@1 | cost | Pass@1 | cost | Pass@1 |
| sklearn | 10/10 | 10/10 | 10/10 | 10/10 | |||
| SymPy | 10/10 | 10/10 | 10/10 | 8/10 | |||
| Django | 9/10 | 9/10 | 8/10 | 9/10 | |||
| Sphinx | 6/10 | 8/10 | 6/10 | 8/10 | |||
| Matplotlib | 8/10 | 9/10 | 8/10 | 9/10 | |||
| Config | Value |
|---|---|
| Micro-skill injection | |
| Skill sources | proposer |
| Proposer cadence | every 5 tasks |
| Confirmation | 3 confirmations on non-overlapping edited files |
| Need gate | rate over exercises |
| Support , | , |
| State | Injected into | Leaves the state when |
|---|---|---|
| Candidate | never | confirmed on 3 tasks with non-overlapping edited files confirmed |
| Confirmed | on each task, if its need rate is over exercised tasks; otherwise withheld, and rechecked before the next task | , or any contradiction of a high-stakes skill retired |
| Retired | never | never; the proposer may propose a replacement under a new identifier |
| Micro-skills | Tool schemas | Failure loops | |||||||
| Method | Proposed | Confirmed | Needed | Retired | Masked | Re-audits | Judged | Redirects | Aborts |
| Claude Code, Sonnet 5 | |||||||||
| Micro-skills | 11.4 | 7.2 | 268 | 2.1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| Tool pruning | 0.0 | 0.0 | 0 | 0.0 | 15.1 | 3.3 | 0.0 | 0.0 | 0.0 |
| Failure-loop guard | 0.0 | 0.0 | 0 | 0.0 | 0.0 | 0.0 | 10.8 | 4.4 | 1.4 |
| Combined | 12.1 | 8.4 | 301 | 2.6 | 14.8 | 3.1 | 9.9 | 3.9 | 2.0 |
| Group | Column | Unit | Definition |
|---|---|---|---|
| Micro-skills | Proposed | skills / stream | candidate skills in the stream’s final ledger |
| Confirmed | skills / stream | candidates that met the confirmation condition and were not retired | |
| Needed | tasks / stream | exercised tasks that needed a skill, summed over skills | |
| Retired | skills / stream | retired skills | |
| Tool schemas | Masked | schemas / stream | tools still masked at the last task, not a cumulative count |
| Re-audits | tasks / stream | tasks run as a full-catalog re-audit |
Token Efficiency
Token efficiency studies how to reduce language-model token use, cost, and latency while preserving task quality and equitable access.
See all 30 papers