Direct answer
Cost optimization on Claude Code involves selecting the right model for each task, using Sonnet for deep reasoning and execution balance, Haiku for repetitive batches, and a consistent decision matrix to reduce monthly expenditure by 40-60% without degrading quality, making it a matter of discipline rather than cleverness or intuition.
Cost optimization on Claude Code is not negotiating the price for tokens (the list price is that), it's Choose the right model for each task.Process for deep reasoning, Sonnet for execution balanced, Haiku for repetitive batches. A consistent decision matrix reduces monthly expenditure by 40-60% without degrading measurable quality.
Independence Disclaimer: I am not affiliated with Anthropic. The numbers cited are sanitized: ranges instead of exact values, ratios instead of absolute ones. Enough for reasoning, not for financial audit.
The three models in brief (approximate cost ratio)
- Version 4.7Deepest reasoning. Cost ~5x Sonnet. Use case: planning, plan checker, architectural decision making.
- I couldn't find any Italian text to translate. Please provide the Italian text you'd like me to translate, and I'll be happy to assist you.Balanced cost/quality ratio. Best coding model. Use case: execution, research, UI researcher, code reviewer, refactor cleaner.
- Haiku 4.590% sonnet capability at a lower cost ratio. ~3x cost savings compared to Sonnet. Use cases: batch lookup, simple parsing, simple verification, and document generation routine.
Decision matrix for task type
| I don't see any Italian text provided. Please provide the Italian text you'd like me to translate, and I'll be happy to assist you. | Model | I'm ready to translate. Please provide the Italian text. |
|---|---|---|
| GSD-Planner (Creating Plans) | I'm ready to translate. Please provide the Italian text. | Deep analysis on complex trade-offs |
| gSD-Plan Checker (Validation) | I'm ready to translate. Please provide the Italian text. | Structured verification on defined dimensions |
| Phase Researcher | I'm ready to translate. Please provide the Italian text. | Technical writing discipline |
| gds-executor (execution plan) | I'm ready to translate. Please provide the Italian text. | Disciplined execution on specific tasks |
| GSD UI Researcher | I'm ready to translate. Please provide the Italian text. | UI design contract is balanced |
| Code generation (new feature) | I'm ready to translate. Please provide the Italian text. | Best coding model |
| Code review (post-write) * XPHX0XPHX * XPHX1XPHX * Post-write code review * Code review | I'm ready to translate. Please provide the Italian text. | Pattern matching on issue note |
| Refactoring and Cleanup | I'm ready to translate. Please provide the Italian text. | Orchestration tool noted |
| Documentation generation (README, API documentation) | I don't see any Italian text provided. Please share the text you'd like me to translate, and I'll be happy to assist you. | Repetitive patterns, no deep analysis |
| Batch parsing (frontmatter validation) | I don't see any Italian text provided. Please share the text you'd like me to translate, and I'll be happy to assist you. | Mechanical task, high volume |
| Simple verification (file exists, test passed) | I don't see any Italian text provided. Please share the text you'd like me to translate, and I'll be happy to assist you. | Boolean check, no reasoning |
| Architectural decision (multi-factor) | I'm ready to translate. Please provide the Italian text. | Complex tradeoffs on long-term impact |
| Brainstorming skill (decision making) | I don't see any Italian text provided. Please provide the text you'd like me to translate, and I'll be happy to assist you. | If a strategic decision is made, then Sonnet if a tactical move |
| Quick chat consultations | I'm ready to translate. Please provide the Italian text. | Web application default |
Monthly benchmark cost sanitized portfolio
Typical distribution of my monthly usage on my portfolio (indicative numbers, not exact):
- I'm ready to translate. Please provide the Italian text.~15-25% of tokens. Focus on the planner and plan-checker iterations 1 and 2, along with strategic decisions.
- I'm ready to translate. Please provide the Italian text.~65-75% of tokens. The majority of operational workflow.
- I don't see any Italian text provided. Please share the text you'd like me to translate, and I'll be happy to assist you.~10-15% of tokens. Batch jobs and repetitive verification.
Average expenditure: $100-$300 per month (Range that varies with usage intensity). Peak: ~€500/month in months with the "monster" feature (e.g. Phase 20 ~108k words of content + 10 plans + i18n bulk).
Without a decision matrix (Opus for All): estimated cost 2-3x = $200-$900/monthSaving annual: $1,500-$4,000.
Sub-agent isolation with worktree
Pattern for parallel executor sub-agents that modify files: each sub-agent turns in Temporary Git WorktreeAdvantages: Vantaggi: 1. Maggiore flessibilità nel lavoro 2. Miglior gestione del tempo 3. Aumento della produttività 4. Riduzione dello stress e dell'ansia 5. Miglior equilibrio tra vita lavorativa e personale
- Changes isolate for each sub-agent (no race condition file).
- Automatic cleanup if sub-agent does not produce any changes.
- Path + branch returned if changes exist (for merge orchestrator).
Typical invocation in spawn:
Agent(
description="...",
subagent_type="gsd-executor",
model="sonnet",
prompt="...",
isolation="worktree"
)
I'm ready to translate. Please provide the Italian text. Git stash does not work. because
refs/stash is shared. Use git checkout -- <file> For cleanup, do not stash. Personal lesson: the first time I used a worktree, I made a stash and then 'pop' pulled all WIP from the sibling worktree. Saved in memory for not to repeat.
Operative Cost-Saving Strategies
- Consistent decision matrixAll sub-agents configured with the appropriate model from the start. Changing on the fly ("we use Opus for this single call") is an exception, not a rule.
- Sub-agent specialistsInstead of a sub-agency, "General Purpose" Opus that does everything, specialized on tasks Limited can often use Sonnet or Haiku.
- Cache content hashfor repetitive tasks (e.g. i18n translation, doc rewriting), caching of output for input hash avoids retyping or regenerating identical content.
- Skip redundantgsd-pattern-mapper is optional - skip if CONTEXT.md has already a code_context section. Saves ~25k tokens for the phase.
- Manual fallback for small tasksWriting a 200-line file manually often costs less time + token that spawns a sub-agent for that. The sub-agent has an overhead of setup.
Anti-pattern: Opus is everywhere
Initial temptation: "Opus is the best, I use it for everything". Cost explosion without proportional value. Sonnet 4.6 is already the "best coding model" - Opus marginal value on execution is low, marginal cost is 5x.
Mitigation: default sub-agent on Sonnet. Reserved operation for sub-agent planning + plan-checker + macro decisions (10-20% of total tokens).
Anti-pattern: Haiku on complex tasks
The opposite: Haiku for aggressive cost savings. On tasks requiring multi-step reasoning, Haiku produces lower quality output that requires 2-3 reworks and costs more than a single Sonnet shot.
Threshold: Haiku for tasks with deterministic input/output (parsing, validation, documentation routine). Sonnet for tasks that require "judgment".
Measuring real costs
Anthropic console shows consumed tokens per day. On my setup:
- Daily check console (~1 minute/day): what's the trend?
- Weekly check: ratio of Opus/ Sonnet/ Haiku in line with target?
- Monthly review: total spending vs budget? Growth trend?
Unexpected growth trend = some unexpected pattern of workflow has changed. Investigate: Has a new sub-agent been introduced? Is the plan checker being iterated and increased? Sub-agent timeouts (re-spawning) are occurring frequently?
Cost per phase budget
On the portfolio I use indicative budget for phase:
- Small phase (1-3 plan, no content writing): €10-20.
- Mid-term phase (4-7 plan): €30-€80.
- Monstrous phase (10+ plan + content writing): ~$100-300.
Phase 20 (~€80-150 estimated): (10 plans + 21 articles, content, i18n bulk, and verification). Budget respected.
What I learned writing this article
The thing that surprised me is how little intuitive the relationship between cost and quality was for Opus and Sonnet. I thought "Opus is better = always to prefer", but on the real portfolio Sonnet has execution qualities equivalent for most practical tasks. Opus shines in strategic decisions (planner, plan-checker) but wastes on execute.
Second insight: cost optimization is mainly discipline, not cleverness. A written decision matrix applied consistently is worth more than any case-by-case optimization trick. Set up the decision once and apply for months.
Avoided pattern
- Everywhere is Opus.Cost explodes without value. Default Sonnet.
- Haikus on a complex taskReinvesting in Costa is more than just saving money.
A story worth sharing
Placeholder Section If you have original cost optimization patterns,
write to me at federico@federicocalo.dev.
Previous cluster: IDE/web/CLI environments Next cluster (cross-framework): Debug-skill troubleshooting end-to-end →
Frequently asked questions
What is the primary goal of cost optimization on Claude Code?
The primary goal is to choose the right model for each task, rather than negotiating the price for tokens.
How can a decision matrix help reduce monthly expenditure on Claude Code?
A consistent decision matrix can reduce monthly expenditure by 40-60% without degrading measurable quality.
What are some common anti-patterns to avoid when using Opus and Haiku models on Claude Code?
Avoid using Opus for all tasks, as it can lead to cost explosion without proportional value. Also, do not use Haiku for complex tasks that require multi-step reasoning.
How can you measure real costs on Claude Code and identify potential issues with your workflow?
You can track consumed tokens per day in the Anthropic console and investigate any unexpected growth trends by checking if new sub-agents have been introduced or if plan checkers are being iterated.
Commenti
Caricamento commenti...
Sign in to comment