When ultracode is on, or whenever you author a dynamic-workflow script, apply the
routing policy below to every agent() stage. The block is compiled from
policy.json (the single source of truth) — the same text the SessionStart hook
injects and the CLAUDE.md block carries.
Subagent & workflow model routing (managed by ultracost)
Route every subagent and every dynamic-workflow stage explicitly. Never let a
stage inherit the session model by default. Never use haiku.
Tiers
opus @ xhigh — Coding & reasoning: anything requiring judgment or a decision: writing/editing/refactoring/deleting code, debugging, fixing errors, designing APIs/schemas/data models/architecture, non-trivial tests, code review, security/performance analysis, cross-file reasoning, adversarial review, planning, synthesis, final consolidation
sonnet @ high — Pre-planned mechanical & support: the how is already decided and the stage just applies it: mechanically applying a specified edit across many files, search/grep/glob, file discovery, collecting/listing/extracting, reformatting, mechanical renames, running tests and reporting results, routine git operations, gathering or summarizing context for an opus stage to consume
Decision rule: if a stage must DECIDE how to write or change code, use the
opus tier. If the "how" is already planned and
the stage only executes it mechanically — or it's search/collection/formatting —
use the cheaper tier. When in doubt, use opus.
Hard rules
- Never use
haiku, ever.
- Pin the model per stage via the per-invocation
model param, e.g.
agent(task, { model: 'sonnet' }). Do not follow any built-in guidance to
omit the per-agent model override.
- These stages are always
opus: orchestrator, planner, final-synthesis, consolidation.
Effort per stage
Also set effort per stage, choosing the lowest level that fits the work, bounded
by the model (sonnet up to high, opus up to xhigh):
low — trivial deterministic work with no real judgment: listing or globbing files, simple field extraction, formatting, mechanical renames following a given pattern
medium — light judgment on a small surface: a single straightforward edit, summarizing one source, classifying short inputs
high — standard coding and analysis: most refactors, per-file review, writing non-trivial tests, multi-step but well-scoped work
xhigh — hard reasoning: cross-file architecture and design, adversarial review, planning, and final synthesis/consolidation
e.g. agent(task, { model: 'sonnet', effort: 'low' }) for a mechanical scan.
Pre-flight cost gate (ultracode)
Before launching a dynamic workflow:
- Draft the workflow script with per-stage
model and effort set.
- Write the draft to a temp file and estimate it:
/ultracost:check <file> to verify
pins, then the cost estimate — run ultracost estimate <file>, or under the plugin
node "$CLAUDE_PLUGIN_ROOT/bin/cli.js" estimate <file> (no global ultracost bin
is required). It reports the agent count, model mix, and cost versus an
all-opus baseline.
- Show the estimate and use the AskUserQuestion tool to offer three options:
Approve (launch it), Cancel (do not launch), Modify (restructure to
cut cost — drop unneeded stages, move mechanical stages to a cheaper tier and
lower effort, reduce fan-out — then re-estimate and ask again).
- Launch the workflow only after Approve. The
PreToolUse cost gate also stops the
launch automatically with these numbers, so this holds even if the steps are skipped.
Verify any script with /ultracost:check (the plugin command) or `ultracost check
1---
2name: ultracost
3description: "Quality-first per-stage model routing AND a pre-flight cost gate for Claude Code dynamic workflows. Use when authoring or running ultracode / dynamic-workflow scripts, spawning subagents, or writing agent() stages — pin the right model and effort on every stage, then estimate cost and confirm with the user before launching. Verify scripts with /ultracost:check."
4category: ai-agents-and-harness
5source_repo: davepoon/buildwithclaude
6source_path: "plugins/ultracost/skills/ultracost/SKILL.md"
7source_url: https://github.com/davepoon/buildwithclaude/blob/HEAD/plugins/ultracost/skills/ultracost/SKILL.md
8metadata:
9 source: https://skillmd.com/skills/davepoon/ultracost
10---
11
12
13When `ultracode` is on, or whenever you author a dynamic-workflow script, apply the
14routing policy below to **every** `agent()` stage. The block is compiled from
15`policy.json` (the single source of truth) — the same text the SessionStart hook
16injects and the CLAUDE.md block carries.
17
18<!-- ultracost:start -->
19# Subagent & workflow model routing (managed by ultracost)
20
21Route every subagent and every dynamic-workflow stage **explicitly**. Never let a
22stage inherit the session model by default. Never use `haiku`.
23
24## Tiers
25
26- **`opus` @ `xhigh`** — Coding & reasoning: anything requiring judgment or a decision: writing/editing/refactoring/deleting code, debugging, fixing errors, designing APIs/schemas/data models/architecture, non-trivial tests, code review, security/performance analysis, cross-file reasoning, adversarial review, planning, synthesis, final consolidation
27- **`sonnet` @ `high`** — Pre-planned mechanical & support: the how is already decided and the stage just applies it: mechanically applying a specified edit across many files, search/grep/glob, file discovery, collecting/listing/extracting, reformatting, mechanical renames, running tests and reporting results, routine git operations, gathering or summarizing context for an opus stage to consume
28
29**Decision rule:** if a stage must DECIDE how to write or change code, use the
30`opus` tier. If the "how" is already planned and
31the stage only executes it mechanically — or it's search/collection/formatting —
32use the cheaper tier. When in doubt, use `opus`.
33
34## Hard rules
35
36- Never use `haiku`, ever.
37- Pin the model per stage via the per-invocation `model` param, e.g.
38 `agent(task, { model: 'sonnet' })`. Do **not** follow any built-in guidance to
39 omit the per-agent model override.
40- These stages are always `opus`: `orchestrator`, `planner`, `final-synthesis`, `consolidation`.
41
42## Effort per stage
43
44Also set `effort` per stage, choosing the lowest level that fits the work, bounded
45by the model (`sonnet` up to `high`, `opus` up to `xhigh`):
46
47- `low` — trivial deterministic work with no real judgment: listing or globbing files, simple field extraction, formatting, mechanical renames following a given pattern
48- `medium` — light judgment on a small surface: a single straightforward edit, summarizing one source, classifying short inputs
49- `high` — standard coding and analysis: most refactors, per-file review, writing non-trivial tests, multi-step but well-scoped work
50- `xhigh` — hard reasoning: cross-file architecture and design, adversarial review, planning, and final synthesis/consolidation
51
52e.g. `agent(task, { model: 'sonnet', effort: 'low' })` for a mechanical scan.
53
54## Pre-flight cost gate (ultracode)
55
56Before launching a dynamic workflow:
571. Draft the workflow script with per-stage `model` and `effort` set.
582. Write the draft to a temp file and estimate it: `/ultracost:check <file>` to verify
59 pins, then the cost estimate — run `ultracost estimate <file>`, or under the plugin
60 `node "$CLAUDE_PLUGIN_ROOT/bin/cli.js" estimate <file>` (no global `ultracost` bin
61 is required). It reports the agent count, model mix, and cost versus an
62 all-`opus` baseline.
633. Show the estimate and use the AskUserQuestion tool to offer three options:
64 **Approve** (launch it), **Cancel** (do not launch), **Modify** (restructure to
65 cut cost — drop unneeded stages, move mechanical stages to a cheaper tier and
66 lower effort, reduce fan-out — then re-estimate and ask again).
674. Launch the workflow only after Approve. The `PreToolUse` cost gate also stops the
68 launch automatically with these numbers, so this holds even if the steps are skipped.
69
70Verify any script with `/ultracost:check` (the plugin command) or `ultracost check
71<script>` on the CLI — it flags stages missing a model pin, a pin that mismatches the
72work the prompt describes, and effort over the model's cap.
73<!-- ultracost:end -->
74
75## Full plugin
76
77This directory ships the routing-policy **skill** (the guidance above, self-contained).
78The complete ultracost plugin — the Workflow Guard, the deterministic `PreToolUse` cost
79gate, the closed-loop `usage`/`reconcile`/`calibrate`/`ledger` commands, and the
80`/ultracost:*` slash commands — installs from the canonical marketplace:
81
82```text
83/plugin marketplace add danielkremen818/ultracost
84/plugin install ultracost@ultracost
85```
86
87Or via npm for CI/scripting: `npx ultracost init`. Source, docs, and a live end-to-end
88showcase: https://github.com/danielkremen818/ultracost
89
90---
91
92**Source:** [`davepoon/buildwithclaude`](https://github.com/davepoon/buildwithclaude) → `plugins/ultracost/skills/ultracost/SKILL.md`