↓ Skip to main content
  1. Articles/

Claude Code Subagent Cost Controls: autoCompactWindow, Workflow Model Pinning, and Cache-Write Telemetry

·772 words·4 mins·
Florent Clairambault
Author
Florent Clairambault
CTO & software engineer — writing daily about spec-driven development and agentic coding

Claude Code Subagent Cost Controls: autoCompactWindow, Workflow Model Pinning, and Cache-Write Telemetry

Multi-agent setups get expensive in a boring way. No single call is outrageous. Ten subagents each drag a bloated context through a dozen turns, and the bill arrives as a surprise. The last two Claude Code releases add three small controls aimed at exactly that. Everything below comes from the official changelog. I have not run these features hands-on, so treat the behavior descriptions as the changelog’s claims, not my measurements.

autoCompactWindow: compaction per subagent
#

v2.1.296 (October 9) added autoCompactWindow to subagent frontmatter and to --agents definitions. The changelog’s wording: a subagent can now auto-compact earlier than the main conversation’s window.

Why it matters: a research subagent that greps a monorepo accumulates tool output fast. Previously it inherited the same compaction threshold as everything else. A short-lived worker rarely needs a huge window. It needs to finish and hand back a summary. Setting a smaller window per agent keeps each turn’s input smaller, which is where most of the spend sits.

A sketch of what the frontmatter might look like (field name from the changelog; the value and its unit are my assumption, so check the docs before copying):

---
name: repo-scout
description: Finds call sites and summarizes them
model: haiku
autoCompactWindow: 60000
---
Search the codebase for the requested symbol. Return a summary of at most 20 lines.

CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL: one model for the whole workflow
#

Also in v2.1.296: the CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL environment variable runs every workflow agent on one model, while other subagents keep theirs.

This pairs naturally with Haiku 5.5’s pricing as a cheap worker tier. Fan out a workflow of twenty agents and you can force the entire fan-out onto a small model with one variable, rather than editing each definition. The trade-off is obvious and worth saying out loud: a pinned cheap model on a hard step will fail more, and you will pay for the retries. Use it for mechanical fan-out such as per-file review or migration passes, not for the planner.

The same release also priced Sonnet 5.5 cache reads at $0.10 per million tokens in /cost, the status line, --max-budget-usd, and the SDK (it was $0.20). That is a display-side correction to match the halved price, but it means budget caps now count differently, so a limit you tuned last month will stretch further.

Cache-write telemetry in v2.1.300
#

v2.1.300 (October 14) added cache_creation_5m_tokens and cache_creation_1h_tokens to the OpenTelemetry api_request event, splitting cache writes by lifetime.

This is the piece I’d adopt first. Last week’s idle-compaction change in v2.1.299 exists because a one-hour prompt cache expiring mid-session forces a full reprocess. Until now you could see that cost only in aggregate. With the split, you can answer concrete questions:

  • Are my subagents writing 1-hour cache entries for work that lasts three minutes?
  • Which workflows churn 5-minute entries because they idle between turns?
  • Did a config change move writes between buckets?

If you already export OTel to a dashboard, adding two fields to a panel is cheap. If you don’t, this is a decent reason to start.

Smaller changes worth a line
#

  • Large requests to api.anthropic.com now use gzip compression even with telemetry disabled; CLAUDE_CODE_GZIP_REQUEST_BODIES=0 turns it off. If you run behind a proxy that inspects bodies, test this before rollout.
  • Exit now force-kills background commands still running 1.5 seconds after being asked to stop. Good for leaked processes, bad if you relied on a background job surviving a quit.
  • CLAUDE_CODE_OVERLOADED_RETRY_MAX_DELAY_MS sets a longer maximum backoff for 529 overloaded retries, useful for unattended runs.
  • The MCP tool-description cap sent up front moved from 2,048 to 4,096 characters.
  • virtualText for mod prompt decorations draws text in the prompt box that never enters the submitted prompt.

What to do this week
#

  1. Add autoCompactWindow to your two or three most-spawned subagents and compare token usage before and after.
  2. Pin mechanical workflow fan-out with CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL, keep planning on your strongest model.
  3. Add the two cache-creation fields to your telemetry so you can see what you are paying for.

The bigger point
#

This is the unglamorous side of spec-driven development. When the spec is good and the agents run unattended, cost per run becomes a property you tune, like latency. Editor-bound tools that keep a human approving each step never face this problem, because the human is the throttle. A terminal-native agent that fans out to dozens of workers needs budgets, per-agent limits, and telemetry, and Claude Code is now shipping them release by release. That is what autonomy at scale requires. The caveat stands: until someone publishes measurements, how much these save is unknown. Measure your own runs.

Sources
#

Related