phantanphatdgteam-gif/snagon-dev-mods/cost-aware-claude-pipeline
Claude Code and agent skill by phantanphatdgteam-gif/snagon-dev-mods
- community
Checking that the SKILL.md file is still in the repository.
Cost-aware patterns for apps that call the Claude API and for Claude Code subagents, updated for the current lineup (Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 4.5; Haiku 3.5 is retired). Covers which levers to pull first (prompt caching, batch, effort) before model routing, current prices and per-model cache minimums, immutable budget tracking, the SDK's built-in retries, and choosing the `model` and `effort` for each subagent. Use this whenever you write or review code that calls Claude or another LLM API and spend matters, route work across model tiers, set an API budget, process batches, or are about to spawn subagents / Agent-tool workers that a cheaper model could handle - even if the user never says "cost".
Install
npx vskill@latest install phantanphatdgteam-gif/snagon-dev-mods/cost-aware-claude-pipelineSKILL.md
The same SKILL.md was published earlier as phantanphatdgteam-gif/snagon-dev-mods/cost-aware-claude-pipeline.
Cost-Aware Claude Pipeline
The goal is a lower cost per completed task without lower quality. A cheap request that needs a retry or a second pass is not cheap.
Model IDs and prices below are a snapshot (2026-09-25, taken from the claude-api skill). They go stale - that is how the original upstream skill ended up recommending Sonnet 5 and the retired Haiku 3.5. For everyday decisions the snapshot is enough. Before hardcoding an ID into code that ships, or quoting prices in a report, confirm them with the claude-api skill or client.models.list() - that lookup costs extra tokens, so don't repeat it for every answer.
To audit the bill of an existing codebase end to end (measure, rank levers, propose diffs), run the claude-api skill's cost-optimize workflow. This skill is the pattern library that work draws on.
1. Current models (snapshot 2026-09-25)
| Model | ID | Input / Output ($ per 1M tokens) | Cache read | Context / max output | Reach for it when | |
|---|---|---|---|---|---|---|
| Claude Fable 5.1 | claude-fable-5-1 | $10 / $50 | $0.25 (0.025x) | 1M / 128K | The hardest long-horizon reasoning, and only when asked for: thinking is always on and it requires 30-day data retention | |
| Claude Opus 5.5 | claude-opus-5-5 | $4 / $20 | $0.20 (0.05x) | 1M / 128K | Complex coding and agentic work; the general default. Effort defaults to medium on this model | |
| Claude Sonnet 5.5 | claude-sonnet-5-5 | $2 / $10 | $0.20 (0.1x) | 1M / 128K | Everyday coding, agents, and workers that still need judgment | |
| Claude Haiku 4.5 | claude-haiku-4-5 | $1 / $5 | about $0.10 (0.1x) | 200K / 64K | High-volume work with checkable outputs: classification, extraction, read-and-summarize workers |
What changed since the upstream original:
- Sonnet 5 to Sonnet 5.5 costs the same per token ($2 / $10). The upgrade buys a newer model, not a lower price, and it is still a migration (for example
thinking: {"type": "disabled"}now returns a 400) - use theclaude-apiskill'smigrateworkflow. - Opus got cheaper: Opus 5.5 is $4 / $20, against $5 / $25 for Opus 5 and Opus 4.8 / 4.7 / 4.6. Moving an Opus 4.x workload to Opus 5.5 is often the easiest saving there is.
- Haiku 3.5 (`claude-3-5-haiku-20241022`) was retired on 2026-02-19 - calls to it fail. Use
claude-haiku-4-5. - Previous generation, still served: Fable 5 ($10 / $50), Opus 5 and Opus 4.8 / 4.7 / 4.6 ($5 / $25), Sonnet 5 ($2 / $10), Sonnet 4.6 ($3 / $15). Deprecated or already retired - migrate off: Opus 4.1, Opus 4, Sonnet 4, Haiku 3.
- Use the aliases exactly as written and don't append date suffixes. Haiku 4.5 also has the snapshot ID
claude-haiku-4-5-20251001, but the alias is preferred.
Price modifiers that often matter more than the list price:
- Prompt caching: writes cost 1.25x (5-minute TTL) or 2x (1-hour TTL); reads cost about 0.1x (0.05x on Opus 5.5, 0.025x on Fable 5.1). Two requests on a 5-minute cache already break even.
- Batch API: 50% off every token, including cache reads and writes - the discounts stack.
- Fast mode on Opus 5.5 ($8 / $40) is a speed premium, not a saving.
2. Pull the levers in this order
The first levers lower the bill without touching quality. The later ones trade capability for cost, so they come last and get measured on an eval.
- Prompt caching - stable content first, volatile content after the last breakpoint (section 6).
- Token hygiene - send less input (retrieve only what the task needs), cap output verbosity, and keep agent loops from re-sending an ever-growing history.
- Batch API for anything no one is waiting on: nightly jobs, backfills, eval runs (section 8).
- Effort - sweep
output_config={"effort": ...}on the current model before switching models (section 7). - Task budgets (beta) for agent loops that run long.
- Model routing - last, and judged on cost per completed task (section 3).
3. Model routing - when it earns its place
Check for an upgrade before a step-down: a newer model at lower effort is often cheaper per solved task than an older model at high effort. Price the hard tail of the workload, not the median - the bill is decided by the tasks the cheap model fails. Caches are scoped per model, so a cascade gives up cache reuse; switch models between conversations, not in the middle of one (the cache cold-starts and newer models drop other models' thinking blocks).
Routing to a cheaper tier changes what the product can do, so it is the owner's decision - validate it on an eval before shipping.
Log every routing decision together with its outcome, so the thresholds get tuned from data instead of guessed.
4. Immutable cost tracking
Price each response from its usage block. input_tokens excludes the cached part of the prompt, so cache reads and writes are priced separately.
Check the budget before each call and stop early. Because the tracker never mutates, every step of a run can be audited afterwards.
5. Retries - let the SDK do them
The SDK already retries 408, 409, 429, 5xx (including 529 overloaded) and connection errors with exponential backoff, 2 retries by default. A hand-written retry loop on top multiplies the attempts and burns budget. Raise the retry count instead, and fail fast on errors a retry cannot fix (400, 401, 402, 403, 404, 413):
6. Prompt caching
A prefix shorter than the model's minimum silently doesn't cache (no error, cache_creation_input_tokens == 0):
| Minimum cacheable prefix | Models | |
|---|---|---|
| 512 tokens | Opus 5.5, Opus 5, Fable 5.1, Fable 5, Sonnet 5.5 (confirm in the caching docs before relying on it) | |
| 1024 tokens | Sonnet 5, Opus 4.8, Sonnet 4.6 | |
| 2048 tokens | Opus 4.7 | |
| 4096 tokens | Haiku 4.5, Opus 4.6, Opus 4.5 |
The minimum is not monotonic: a 3,000-token system prompt caches on Sonnet 5.5 but not on Haiku 4.5, which can change which tier is actually cheaper for a workload.
- TTL: the default 5-minute TTL is refreshed by every read, so requests less than 5 minutes apart keep it warm. Use
{"type": "ephemeral", "ttl": "1h"}only when the same prefix is reused with 5 to 60 minute gaps. - Silent invalidators: timestamps or request IDs in the system prompt, unsorted JSON, a tool list that changes between requests. Caches are also per model and per workspace.
7. Effort - the cost knob inside one model
- The default is
highon current models except Opus 5.5, where it ismedium- set it explicitly. - Research and knowledge work has nearly flat curves, so
lowormediumsave a lot. Long-horizon coding is a real tradeoff - measure it. - With a checker (tests, a validator), run everything at a low setting and re-run only the failures at a higher one; that kept the pass rate for a little over half the cost in Anthropic's coding runs.
- Haiku 4.5 has no effort parameter (it errors); its cost knob is the model choice itself.
- Thinking is adaptive by default on current models. On Opus 5.5 it cannot be disabled (400) - lower the effort instead. On Sonnet 5.5,
{"type": "disabled"}is a 400; send{"type": "between_tools"}if a route must stay thinking-off.
8. Batch API
Batches are single-shot (no tool loop inside a request), and the 50% discount stacks with caching.
9. Claude Code subagents - choose the model and effort on purpose
When the main agent spawns a subagent with the Agent tool and leaves model unset, the subagent falls back to its definition's model, then CLAUDE_CODE_SUBAGENT_MODEL, then the session model - usually Opus 5.5 ($4 / $20), sometimes Fable. That is the most expensive way to grep a repository.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cost-aware-claude-pipeline/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phantanphatdgteam-gif/snagon-dev-mods/cost-aware-claude-pipeline)