<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Agents' Codex</title><link>https://agentscodex.com/tags/agent-budget/</link><description>Practical, no-hype insights on AI agents — cost optimization, multi-agent architecture, and real-world operations.</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Thu, 10 Sep 2026 12:17:24 -0300</lastBuildDate><atom:link href="https://agentscodex.com/tags/agent-budget/index.xml" rel="self" type="application/rss+xml"/><item><title>Cost Regression Detection for AI Coding Agents</title><link>https://agentscodex.com/posts/2026-09-04-frugal-tokens-cost-regression-detection-coding-agents/</link><pubDate>Fri, 04 Sep 2026 06:00:00 -0300</pubDate><author>Agents' Codex</author><guid>https://agentscodex.com/posts/2026-09-04-frugal-tokens-cost-regression-detection-coding-agents/</guid><category>costregression</category><category>codingagents</category><category>tokenspendprofiling</category><category>claudecode</category><description>Learn how to detect cost regressions in AI coding agents, profile token spend per feature, and enforce budget gates before runaway costs hit your team.</description><content:encoded><![CDATA[<p><strong>TL;DR</strong></p>
<ul>
<li><a href="/posts/2026-07-17-ai-agent-ides-multi-agent-workspace-rebuild/">Claude Code</a>
 sends 4.7x more tokens than OpenCode before it even reads your prompt, so tool choice is a real cost lever.</li>
<li>Wattage&rsquo;s prefix_churn detector cut spend 44.7% on real traces just by enabling <a href="/posts/2026-03-05-cutting-llm-agent-costs-by-50-a-production-engineers-playbook/">prompt caching</a>
.</li>
<li>Pair local profiling, CI regression gates, and runtime kill switches to prevent surprise bills rather than react to them.</li>
</ul>
<p>A single afternoon of agent-assisted coding can quietly burn more money than a month of your CI bill, and you would never know from your provider&rsquo;s dashboard. Claude Code transmits 33,000 tokens before it reads a single prompt, compared to OpenCode&rsquo;s 7,000 [1]. That 4.7x difference is not a bug; it is the default behavior of a tool that never asked whether you cared. Cost regression detection for <a href="/posts/2026-07-10-persistent-state-attacks-coding-agents/">coding agents</a>
 flips this: instead of discovering overspending on an invoice, you catch it the moment a commit makes your agent more expensive. The real value here is not monitoring. It is treating token spend like a test that CI can fail — and a test you wrote, not one a vendor shipped.</p>
<h2 id="the-hidden-token-tax-why-coding-agents-cost-more-than-you-think">The Hidden Token Tax: Why Coding Agents Cost More Than You Think</h2>
<p>The overhead is structural, not incidental. Every agent re-sends system prompts, tool schemas, and conversation history on each turn so its context stays coherent. Systima&rsquo;s trace of real sessions found Claude Code pushed 33,000 tokens through the wire before ever reading the user&rsquo;s actual prompt, while OpenCode got by with 7,000 [1]. The same task, run through two tools, can differ in input cost by nearly five times before you have typed a word.</p>
<p>Tool calls make this worse: each function the agent invokes returns output that gets re-fed into the next turn&rsquo;s context; one long tool description can echo through a dozen later turns. An agent that retries a flaky API three times has tripled the tokens attached to that one step. Cache misses compound the damage further; when a stable prefix fails to hit the model provider&rsquo;s cache, you pay full price for content you have already sent once.</p>
<div class="alert alert-alert">
  <p class="alert-heading">ALERT</p>
  <p>The cost you can cut fastest is usually cache misses, not model choice. aireceipts traces show that when caching works, up to 85% of input tokens are served from cache instead of billed fresh [3].</p>
</div><h2 id="seeing-the-spend-local-profilers-for-early-cost-regression-detection">Seeing the Spend: Local Profilers for Early Cost Regression Detection</h2>
<p>Provider dashboards show aggregate usage after the fact; they do not show which feature, which session, or which subagent drove the spend. Local profilers close that gap by reading the agent&rsquo;s own session files and turning them into a live cost view. Agentic Metric is the closest thing to a <code>top</code> command for your coding agents: a real-time TUI tracking tokens and cost across Claude Code, Codex, OpenCode, Qwen Code, and VS Code Copilot [4].</p>
<p>CCTray takes a lighter approach for macOS: a menu bar indicator for Claude API usage with color-coded burn rate. Green means under 300 tokens per minute; yellow spans 300 to 700; red fires above 700 [5]. That single red dot tells you an agent is running hot before you ever open a dashboard.</p>
<p>Both tools share a philosophy: they instrument what you already run. No proxy. No new SDK. The agent keeps its shape; you just get a window into what it is actually spending. The difference is scope: a real-time window versus a persistent receipt (each answering a question you did not know you had).</p>
<h2 id="the-ten-waste-patterns-that-drain-your-agent-budget">The Ten Waste Patterns That Drain Your Agent Budget</h2>
<p>Wattage, a token-spend profiler built for regression testing, catalogs ten specific ways agents waste money and turns each into an automated check [2]. Knowing the list means you can spot waste by eye before you wire up automation.</p>
<table>
	<thead>
			<tr>
					<th>Waste pattern</th>
					<th>What it looks like</th>
					<th>Why it costs you</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>prefix_churn</td>
					<td>Stable context re-sent instead of cached</td>
					<td>Full price for content already sent</td>
			</tr>
			<tr>
					<td>cache gaps</td>
					<td>Reused prefixes never marked cacheable</td>
					<td>Missed 85% cache discount [3]</td>
			</tr>
			<tr>
					<td>non-convergence</td>
					<td>Loops that thrash without progress</td>
					<td>Unbounded spend on zero output</td>
			</tr>
			<tr>
					<td>retry storm / model mismatch</td>
					<td>Identical requests repeated; pricier models doing cheap-model work</td>
					<td>Redundant bills and over-spec&rsquo;d calls</td>
			</tr>
	</tbody>
</table>
<p>The strongest of these is prefix_churn, and Wattage proved it with a concrete number. Enabling prompt caching on a stable prefix took a real captured trace from $0.000199 down to $0.000110, a 44.7% reduction [2]. That is not a rounding error; it is a config change!</p>
<p>Model mismatch is the subtler killer: it never trips an alarm. A pricier model doing work a cheaper one could handle (say, a frontier model drafted for a job a budget model would finish) breaks nothing visible. That is exactly why nobody catches it without an explicit detector [2].</p>
<p>Two patterns deserve special attention in real codebases. Tool result bloat creeps in when a command returns megabytes of output that the agent then holds in context for every later turn (a single oversized read can quietly tax a dozen subsequent calls). Non-convergence loops are worse still: the agent keeps querying, editing, and re-querying without moving toward a result; each cycle bills the full context again [2].</p>
<p>Neither one announces itself; the bill arrives anyway!</p>
<div class="key-takeaway">
  <span class="key-takeaway-label">Key Takeaway</span>
  Waste in coding agents is rarely one big mistake. It is ten small ones, each invisible on its own, that compound into a recurring bill. Name the patterns and they stop hiding.
</div>

<h2 id="make-cost-regressions-fail-the-build-ci-budget-gates">Make Cost Regressions Fail the Build: CI Budget Gates</h2>
<p>Local profilers teach you what a healthy agent looks like. CI gates enforce it. Wattage plugs into existing pipelines and fails a pull request when a change makes the agent meaningfully more expensive, using regression thresholds instead of arbitrary caps [2]. You configure the conditions: score below a floor, cost delta percentage above a ceiling, or any critical waste pattern triggered.</p>
<p>But how do you make a dollar figure fail a build?</p>
<p>aireceipts attacks the same problem from the review side. It attaches an itemized cost receipt to the PR as a comment, so a reviewer sees the dollar impact of a change right beside the diff [3]. What did this change actually cost? The receipt answers that; it shows cache served 85% of input tokens, with costs attributed across Bash, Edit, Read, Write, and thinking calls [3].</p>
<p>The threshold choice is where most teams trip. Set it too tight and every refactor goes red; too loose and the gate never fires. Start wide (a ten percent delta), then tighten once you have a stable baseline [2].</p>
<p>The shift matters because it moves cost from a monthly surprise to a per-commit decision. When a test run tells you this refactor added eleven cents per invocation (an imaginary but realistic figure), you catch it before it ships; you do not wait for it to multiply across every user.</p>
<p>That is the whole point of a gate: make the cheap mistake visible at the exact moment it is still cheap to reverse.</p>
<pre class="mermaid">graph TD
  A[Session Traces] --> B[Local Profiler]
  B --> C[Baseline Established]
  C --> D[CI Gate: Compare Against Baseline]
  D --> E[Runtime Budget Switch]</pre><h2 id="kill-switches-at-runtime-enforcing-hard-budget-limits">Kill Switches at Runtime: Enforcing Hard Budget Limits</h2>
<p>CI gates protect the code you merge. They do nothing for an agent that runs wild at runtime and burns a budget on a runaway loop. What stops that? Runtime enforcement. AgentBudget frames itself as <code>ulimit</code> for <a href="/posts/2026-07-24-rotunda-agent-native-browser/">AI agents</a>
: drop-in SDK integration for Python, Go, and TypeScript that imposes a hard dollar cap and stops the session when it is hit [6].</p>
<p>The value is a clean stop. Instead of discovering on the invoice that an agent spent three times what you planned, the session simply ends at the number you set. AgentBudget ships with 108 GitHub stars and a small API surface, which matters because a budget gate you cannot integrate in five minutes is one you will skip [6].</p>
<div class="alert alert-alert">
  <p class="alert-heading">ALERT</p>
  <p>A hard kill is blunt. If your agent was mid-task, stopping it means losing that work. Set the ceiling generously enough to finish real work, and lean on CI regression gates for the fine-grained signal.</p>
</div><h2 id="tracking-multi-agent-and-subagent-spend-at-scale">Tracking Multi-Agent and Subagent Spend at Scale</h2>
<p>Once a team shares agents, you need to attribute cost across tools and hierarchies, not just per session. ObservAgent gives Claude Code zero-config observability via hooks, tracking cost, tool usage, latency, and subagent trees in real time [7]. lazyagent visualizes that subagent hierarchy in a TUI or web app for Claude, Codex, and OpenCode, breaking token usage down so cache savings become visible [8].</p>
<p>For teams already running OpenTelemetry, Lumina offers OTel-native observability for LLM apps with cost tracking, replay testing, and semantic comparison [9]. The ecosystem is young; star counts reflect it: Agentic Metric leads at 201 while lazyagent sits around 77 [4][8]. Treat these as instruments you can extend, and read the source before you bet a team on them.</p>
<p>The deeper problem is that none of this shows up in provider dashboards. You see a dollar total, not the reason behind it. Wattage&rsquo;s detectors exist precisely because the bill alone cannot tell you whether that total came from caching you forgot to enable or a loop that never should have started [2].</p>
<h2 id="practical-takeaways">Practical Takeaways</h2>
<ol>
<li>Profile before you enforce: run a local profiler like Agentic Metric for a week to establish a baseline tokens-per-feature number before setting any gate [4].</li>
<li>Enable prompt caching on stable prefixes first; it is the highest-value change, worth up to 44.7% on real traces [2].</li>
<li>Wire a CI regression gate (Wattage) with a cost-delta threshold so expensive changes fail the build instead of shipping silently [2].</li>
<li>Add a runtime dollar cap (AgentBudget) as the backstop for loops that CI cannot see [6].</li>
<li>Attach cost receipts to PRs so reviewers evaluate dollar impact next to the diff, not weeks later on an invoice [3].</li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Treating token spend as a regression test changes who feels the budget. Today most teams learn about agent cost from a finance person forwarding an invoice; flip the ordering and the engineer who wrote the expensive commit sees it first, because their build went red. The question worth watching is whether these open-source tools converge on a shared reporting format. If Wattage, aireceipts, and ObservAgent each emit spend in their own schema [2][3][7], team-wide cost visibility will stay a stitching problem long after the individual tools mature. Start by instrumenting one active agent and watching a week of real sessions.</p>
<h2 id="frequently-asked-questions">Frequently Asked Questions</h2>
<h3 id="do-i-really-need-all-three-layers-profiling-ci-gates-and-runtime-limits">Do I really need all three layers: profiling, CI gates, and runtime limits?</h3>
<p>No. Start with a local profiler for a week, then add a CI gate for whatever pattern you find. Runtime limits matter only if you run agents unattended in production.</p>
<h3 id="which-agent-should-i-switch-if-im-worried-about-token-overhead">Which agent should I switch if I&rsquo;m worried about token overhead?</h3>
<p>The overhead gap is real: Claude Code&rsquo;s 4.7x input overhead over OpenCode before a single prompt [1] makes tool choice a cost lever, not a matter of taste. But overhead is only part of spend. Measure your own agent&rsquo;s cache hit rate before migrating, because a tool with low overhead and a high miss rate can still cost more overall.</p>
<h3 id="how-big-is-the-prompt-caching-win-exactly">How big is the prompt caching win, exactly?</h3>
<p>On captured traces, enabling caching on a stable prefix cut cost 44.7%, from $0.000199 to $0.000110 [2]. Separately, aireceipts receipts show cache serving 85% of input tokens in a best case [3]. Your number depends on how much of your agent&rsquo;s context is stable across turns. If your system prompt and tool schemas barely change, you capture most of that 85%; if every turn carries fresh file contents, caching helps far less. That stability ratio is the single variable that determines your upside, and it is worth measuring directly rather than assuming. If you suspect you have a cache-gap problem rather than a stability problem, start with the prefix_churn row in the waste-pattern table above.</p>
<h3 id="are-these-cost-tools-production-grade-or-early-stage-experiments">Are these cost tools production-grade or early-stage experiments?</h3>
<p>Early. Star counts like 201 for Agentic Metric and 77 for lazyagent [4][8] signal a young ecosystem. Treat them as instruments you can read and extend, not platforms with SLAs. That is fine for detecting regressions, but budget accordingly before routing production traffic through them.</p>
<hr>
<h2 id="sources">Sources</h2>
<table>
	<thead>
			<tr>
					<th>#</th>
					<th>Publisher</th>
					<th>Title</th>
					<th>URL</th>
					<th>Date</th>
					<th>Type</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>1</td>
					<td>Systima</td>
					<td>&ldquo;Claude Code Sends 4.7x More Tokens Than OpenCode Before Reading Your Prompt&rdquo;</td>
					<td><a href="https://systima.ai/blog/claude-code-vs-opencode-token-overhead" target="_blank">https://systima.ai/blog/claude-code-vs-opencode-token-overhead</a>
</td>
					<td>2026-07-12</td>
					<td>Blog</td>
			</tr>
			<tr>
					<td>2</td>
					<td>faizannraza (GitHub)</td>
					<td>&ldquo;Wattage — A token-spend profiler and cost-regression gate for AI agents&rdquo;</td>
					<td><a href="https://github.com/faizannraza/wattage" target="_blank">https://github.com/faizannraza/wattage</a>
</td>
					<td>2026-09-02</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>3</td>
					<td>anandgupta42 (GitHub)</td>
					<td>&ldquo;aireceipts — Itemized cost receipts for AI coding agents&rdquo;</td>
					<td><a href="https://github.com/anandgupta42/aireceipts" target="_blank">https://github.com/anandgupta42/aireceipts</a>
</td>
					<td>2026-07-26</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>4</td>
					<td>MrQianjinsi (GitHub)</td>
					<td>&ldquo;Agentic Metric — top for your AI coding agents (token, cost tracking)&rdquo;</td>
					<td><a href="https://github.com/MrQianjinsi/agentic-metric" target="_blank">https://github.com/MrQianjinsi/agentic-metric</a>
</td>
					<td>2026-08-28</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>5</td>
					<td>goniszewski (GitHub)</td>
					<td>&ldquo;CCTray — macOS menu bar app to keep an eye on your Claude Code metrics&rdquo;</td>
					<td><a href="https://github.com/goniszewski/cctray" target="_blank">https://github.com/goniszewski/cctray</a>
</td>
					<td>2026-05-05</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>6</td>
					<td>AgentBudget (GitHub)</td>
					<td>&ldquo;AgentBudget — Real-time dollar budgets for AI agents&rdquo;</td>
					<td><a href="https://github.com/AgentBudget/agentbudget" target="_blank">https://github.com/AgentBudget/agentbudget</a>
</td>
					<td>2026-08-24</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>7</td>
					<td>darshannere (GitHub)</td>
					<td>&ldquo;ObservAgent — Observability for Claude Code (cost, tools, subagents)&rdquo;</td>
					<td><a href="https://github.com/darshannere/observagent" target="_blank">https://github.com/darshannere/observagent</a>
</td>
					<td>2026-07-30</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>8</td>
					<td>chojs23 (GitHub)</td>
					<td>&ldquo;lazyagent — Watch what your AI coding agents are doing&rdquo;</td>
					<td><a href="https://github.com/chojs23/lazyagent" target="_blank">https://github.com/chojs23/lazyagent</a>
</td>
					<td>2026-07-29</td>
					<td>Documentation</td>
			</tr>
			<tr>
					<td>9</td>
					<td>use-lumina (GitHub)</td>
					<td>&ldquo;Lumina — Open-source observability for LLM applications&rdquo;</td>
					<td><a href="https://github.com/use-lumina/Lumina" target="_blank">https://github.com/use-lumina/Lumina</a>
</td>
					<td>2026-02-27</td>
					<td>Documentation</td>
			</tr>
	</tbody>
</table>
<h2 id="image-credits">Image Credits</h2>
<ul>
<li><strong>Cover photo</strong>: Image generated with gpt-5.4-image-2 (Agents&rsquo; Codex AI illustration)</li>
</ul>
]]></content:encoded><media:content url="https://agentscodex.com/images/covers/2026-09-04-frugal-tokens-cost-regression-detection-coding-agents/cover.jpg" medium="image"/><media:thumbnail url="https://agentscodex.com/images/covers/2026-09-04-frugal-tokens-cost-regression-detection-coding-agents/cover.jpg"/></item></channel></rss>