Skip to content

Claude Code Cost Optimization: Model Selection and Usage Monitoring

I was burning through my Claude Code budget way too fast. After a week of heavy usage, I realized I’d spent $50 on tasks that could have cost $10. The culprit? Using Opus for everything—writing comments, formatting code, and simple refactors.

Let me show you how I fixed this.

The Problem: Wrong Model, Wrong Task

I started using Claude Code with the default Opus model for everything. It felt great—Opus is incredibly smart. But then I checked my costs:

Check cost command
/cost

The result shocked me. Simple tasks like adding comments to a function were costing 10x more than necessary.

The Solution: Match Model to Task Complexity

The key insight: not every task needs Opus-level reasoning.

Here’s the mental model I developed:

Task complexity spectrum
Task Complexity Spectrum
========================
Simple ───────────────────────────────────────────────── Complex
Haiku Sonnet Sonnet Opus Opus Opus
│ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼
Comments Bug Feature Multi- Archi- Complex
Format Fixes Dev file tecture Debug
Simple Refactor
Cost: Low ──────────────────────────────────────► High
Speed: Fast ────────────────────────────────────► Slow

Model Selection Commands

Switching models is straightforward:

Model selection command
# Interactive model selection
/model
# Shows available models and lets you pick
# Options typically include:
# - claude-3-5-haiku (fast, cheap)
# - claude-3-5-sonnet (balanced)
# - claude-4-opus (most capable)

I created a simple rule for myself:

Task TypeModelWhy
Writing commentsHaikuNo complex reasoning needed
Formatting codeHaikuPattern matching task
Simple bug fixesSonnetModerate debugging
Feature implementationSonnetBalanced capability
Multi-file refactorsOpusNeeds context tracking
Architecture decisionsOpusDeep reasoning required
Complex debuggingOpusFull analysis needed

Monitoring Costs: Two Essential Commands

Claude Code provides two commands for tracking usage:

/cost - Actual Billing

Check billing
/cost

This shows:

  • Current session cost
  • Total monthly spend
  • Token breakdown (input/output)

Use this to understand your actual spending.

/usage - Rate Limits

Check rate limits
/usage

This shows:

  • Remaining quota before rate limits
  • Current tier status
  • Reset time if limited

Use this when you hit rate limits or want to avoid them.

Trial and Error: Learning the Hard Way

I tried several approaches before finding the right balance:

Attempt 1: Always Use Haiku

I switched to Haiku for everything. Bad idea. Complex refactors produced incorrect code that I had to fix manually. The “savings” were eaten up by my time correcting mistakes.

Attempt 2: Always Use Opus

Back to Opus for everything. My costs tripled again.

Attempt 3: Strategic Selection (The Winner)

Finally, I developed a workflow:

Strategic model selection workflow
# Start session with Sonnet (good default)
/model claude-3-5-sonnet
# For simple tasks, stay with Sonnet or switch to Haiku
# Example: "Add JSDoc comments to all functions in utils.ts"
# For complex tasks, upgrade to Opus
/model claude-4-opus
# Then: "Refactor the authentication system to use JWT"
# Always check cost periodically
/cost

Alternative Models: Significant Savings

For even more savings, consider alternative models like Kimi K2.5 or GLM-4.7:

Configure Kimi alternative
# Configure Kimi for routine work
export ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic
export ANTHROPIC_MODEL=kimi-k2.5

I tested these alternatives on my daily tasks:

TaskOpusKimi K2.5GLM-4.7
Code comments
Bug fixes
Feature dev~80%
Architecture~70%~60%
Complex debug~60%~50%

For 60-70% of my daily work, the alternatives performed competitively at a fraction of the cost.

Cost-Saving Strategy Summary

Here’s my final workflow:

Cost optimization workflow
1. Start with Sonnet (balanced default)
├── Simple task? ──► Stay or switch to Haiku
└── Complex task? ──► Switch to Opus
└── Check cost every 30 min ──► /cost
2. Hit rate limit? ──► /usage ──► Wait or switch model
3. End of session? ──► Review /cost for learning

When to Pay the Premium

Don’t be penny-wise and pound-foolish. Opus is worth the cost for:

  • Architectural decisions: One wrong choice costs more than the tokens
  • Complex debugging: Opus finds bugs others miss
  • Security reviews: Don’t skimp on security
  • Multi-file refactors: Context tracking matters

The Numbers Don’t Lie

After implementing this strategy:

MetricBeforeAfter
Weekly cost~$50~$15
Task success rate95%94%
Time per taskSameSame

I reduced costs by 70% with negligible impact on quality.

Summary

In this post, I showed how to optimize Claude Code costs by matching models to task complexity. The key point is that Haiku/Sonnet are sufficient for most tasks, and you should reserve Opus for complex reasoning.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments