Skip to content

How to Reduce Claude Code Token Costs: 5 Optimization Strategies That Work

Problem

Claude Code is powerful, but token costs can add up quickly, especially in long sessions or when using deep think modes.

How can I reduce costs without sacrificing code quality?

The 5 Strategies

Strategy 1: Use /compact Regularly

The /compact command compresses your conversation while preserving key information.

Use /compact
claude
> /compact
# Or enable auto-compact
claude --auto-compact

This can reduce token count by 70%:

Savings from /compact
Before: 50K tokens
After: 15K tokens
Savings: 70%

Strategy 2: Specify Exact File Paths

Broad requests cost more tokens because Claude has to analyze more context.

Be specific with paths
# BAD: Broad request (high token cost)
claude "修复认证相关的bug"
# GOOD: Specific request (lower cost)
claude "修复src/utils/auth.js中的bug"
# BAD: Analyze everything
claude "分析这个项目"
# GOOD: Targeted analysis
claude "分析src/components目录的组件设计"

Specificity can save 67% of tokens:

Savings from specificity
Broad request: 30K tokens
Specific request: 10K tokens
Savings: 67%

Strategy 3: Configure .claudeignore

Exclude large directories that Claude doesn’t need to read:

Create .claudeignore
echo "node_modules/" >> .claudeignore
echo "dist/" >> .claudeignore
echo "build/" >> .claudeignore
echo "*.log" >> .claudeignore
echo ".env" >> .claudeignore
echo "*.min.js" >> .claudeignore
echo "coverage/" >> .claudeignore

This can save 70% of tokens:

Savings from .claudeignore
Without .claudeignore: 40K tokens
With .claudeignore: 12K tokens
Savings: 70%

Strategy 4: Choose Appropriate Think Mode

Each think mode uses different amounts of tokens:

Think mode token usage
┌────────────────┬─────────┬─────────────────────────┐
│ Mode │ Tokens │ Best For │
├────────────────┼─────────┼─────────────────────────┤
│ think │ Low │ Simple questions │
│ think hard │ Medium │ Algorithm design │
│ think harder │ High │ Architecture analysis │
│ ultrathink │ Highest │ Complex problems │
└────────────────┴─────────┴─────────────────────────┘

Use think for simple questions, ultrathink only for complex problems.

Choose appropriate mode
# Simple question - use basic think (lowest cost)
claude "think 这个函数有什么问题?"
# Complex architecture - use ultrathink (highest cost)
claude "ultrathink 设计一个分布式消息队列系统"

Strategy 5: Monitor Usage

Track your token usage to identify optimization opportunities:

Monitor usage
# Check usage statistics
claude stats
# Check current conversation token count
claude token-count

Combined Savings

Using all strategies together:

Combined cost savings
┌─────────────────────────┬───────────┬───────────┬─────────┐
│ Strategy │ Before │ After │ Savings │
├─────────────────────────┼───────────┼───────────┼─────────┤
│ Using /compact │ 50K │ 15K │ 70% │
│ Specific file path │ 30K │ 10K │ 67% │
│ .claudeignore │ 40K │ 12K │ 70% │
│ Think mode (basic) │ 5K │ 1K │ 80% │
├─────────────────────────┼───────────┼───────────┼─────────┤
│ Combined │ │ │ Up to 85%│
└─────────────────────────┴───────────┴───────────┴─────────┘

Strategy by Subscription

Your subscription affects your optimization approach:

Strategy by subscription tier
Free Tier:
- Primarily use 'think' mode
- Use /compact after every 10 messages
- Always specify exact files
- Aggressive .claudeignore
Pro Tier:
- Balance think modes
- Use /compact periodically
- Moderate specificity
- Standard .claudeignore
Max Tier:
- Use ultrathink freely
- Less aggressive optimization
- Focus on quality over cost

Summary

In this post, I showed 5 strategies to reduce Claude Code token costs. The key points are:

  1. Use /compact regularly - saves 70%
  2. Specify exact file paths - saves 67%
  3. Configure .claudeignore - saves 70%
  4. Match think modes to task complexity - saves 80%
  5. Monitor usage with claude stats

Combined, these strategies can reduce costs by up to 85%.

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