claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Workflow docs: "default to omitting opts.model" makes every bare agent() run on the session model — the most expensive tier

Open DirtyDiablo opened this issue 2 months ago • 2 comments

The Workflow script reference (Claude Code 2.1.271) says of agent():

opts.model overrides the model for this agent call. Default to omitting it — the agent inherits the main-loop model (the resolved session model), which is almost always correct. Only set it when you're highly confident a different tier fits the task; when unsure, omit.

On a premium session model that default is the costliest option available, and the guidance steers authors into it.

What we measured (Windows 11, ground truth read from each subagent transcript's message.model, not self-report):

  • An 8-cell probe confirmed a bare agent() (no agentType, no model) runs on the session model, and that an agentType whose definition pins model: in frontmatter is honoured inside a workflow.
  • Every spawn pays roughly 50–180k cache-read plus 40–140k cache-write tokens of preamble before it does any work. At list prices a 100k + 100k preamble is about 9x more expensive on the top tier than on Haiku.
  • Over one working day, 41 bare agent() spawns accounted for $643.72 — 54% of all subagent spend. The same token volumes would have cost $170.76 on Sonnet and $85.38 on Haiku.

Suggested replacement text:

Omit it only when opts.agentType names a definition that pins a model — a definition's frontmatter model: is honoured inside a workflow. A bare agent() with neither agentType nor model inherits the session model, and each spawn carries roughly 100k cached input tokens of preamble before it does any work, so on a premium session that default is the most expensive option rather than the safest. When neither applies, name the tier the stage actually needs.

Related, different defect: #88695 (meta.phases[].model reads as an override but is display-only).

DirtyDiablo avatar Sep 15 '26 15:09 DirtyDiablo

Correction to the spend figures in the report above: our measuring script double-counted.

Claude Code writes one transcript record per content block (thinking, text, tool_use), and each record repeats the same message.id and usage. The script summed every record, and it also read some transcript files twice. With each message.id counted once and each file read once, per-spawn totals match the harness's own subagent_tokens to within about 0.1% on a check run.

Re-derived for the same day: 41 bare agent() spawns accounted for $110.62, 47% of subagent spend. The same token volumes would have cost $29.10 on Sonnet and $14.55 on Haiku.

The ratios and the request stand: the bare spawns still cost about 3.8x the Sonnet figure and 7.6x the Haiku figure. The absolute dollars in the original post were about 5.8x too high.

Side note for anyone building cost tooling on transcripts: dedupe usage by message.id, or every multi-block turn is counted two or three times.

DirtyDiablo avatar Sep 15 '26 17:09 DirtyDiablo

The quoted sentence is also inaccurate, not just costly, when CLAUDE_CODE_SUBAGENT_MODEL is set. The environment variable docs make it the default for "workflow agents that aren't assigned a model another way", and that's what happens: with CLAUDE_CODE_SUBAGENT_MODEL=sonnet in user settings env and an Opus 5.5 session, every bare agent() in my workflows runs on claude-sonnet-5-5, per each subagent transcript's message.model. The Agent tool's description already covers this ("inherits from the parent unless a default subagent model is configured"); the Workflow tool's doesn't.

The effect lands on the main model, which takes the description at its word. In one session it priced two workflow runs as Opus fan-outs ("7 source-auditor agents plus one completeness critic, all inheriting Opus") while every agent ran on Sonnet. The replacement text proposed above has the same gap, since it also says a bare agent() inherits the session model.

Whatever wording replaces it should follow the documented order: an explicit model or the agentType definition's model, then CLAUDE_CODE_SUBAGENT_MODEL, then the session model.

Observed on 2.1.299 (desktop app, Windows 10). The same sentence is still in the 2.1.304 Windows binary.

AI assistance: Claude Code (Claude Opus 5.5) traced the mismatch in session transcripts, checked the 2.1.304 binary and drafted this comment.

ItsColby avatar Oct 20 '26 00:10 ItsColby