← Back to Cheatsheet

Reduce Token Usage and Optimize Costs in Claude Code

Learn effective strategies to minimize token consumption, manage context efficiently, and reduce costs while maintaining code quality and AI assistant effectiveness.

1. Understand Token Counting and Pricing

Before optimizing, understand how tokens work and impact your costs:

💡 Pro Tip: Run an analysis weekly to see which workflows consume the most tokens. You may discover quick wins for optimization.

2. Choose the Right Model for the Task

Not every task requires your most powerful model. Match model to complexity:

💡 Pro Tip: Try Haiku first. If it fails, upgrade to Sonnet. Most coding work completes with Haiku or Sonnet, saving 80%+ on costs.

3. Optimize Context with Strategic Truncation

Large files and full codebase context drive token costs up. Be selective:

⚠️ Warning: Including a 50KB file in context can cost as much as 10-20 shorter prompts. Be selective.

4. Leverage the /memory Command for Persistent Context

Store important context once, reuse it forever without re-sending tokens:

💡 Pro Tip: Set up project memory once (5 minutes), then save thousands of tokens across all future sessions on that project.

5. Use Agents to Parallelize and Reduce Iterations

Running agents in parallel can actually save tokens by reducing back-and-forth:

6. Master Prompt Engineering for Efficiency

Precise prompts require fewer tokens and iterations:

7. Disable Extended Thinking When Not Needed

Extended thinking uses up to 10x more tokens for deep reasoning. Only enable when necessary:

💡 Pro Tip: Disable thinking by default. Enable it explicitly for specific tasks where you need deeper reasoning.

8. Reduce Output Verbosity

Longer outputs cost more tokens. Limit Claude's response length:

9. Batch Similar Tasks Together

Grouping tasks reduces per-task overhead and context setup:

💡 Pro Tip: Grouping 5 tasks can reduce overall token usage by 30-40% compared to doing them separately.

10. Use the --bare Flag for Scripted Workflows

The --bare flag skips loading unnecessary configs and MCPs:

11. Cache Responses with Smart Session Management

Reuse prior session results instead of re-running expensive operations:

12. Monitor Spending and Set Alerts

Track costs regularly and set up monitoring:

13. Progressive Enhancement: Start Simple, Upgrade on Failure

The most effective cost optimization strategy:

  1. Start with Haiku: Try the cheapest model first
  2. Measure success: Did it work? Great, you're done
  3. Upgrade on failure: If Haiku fails, retry with Sonnet
  4. Reserve Opus: Only use Opus for tasks that require its reasoning capability

This approach saves 80%+ on token costs because most coding tasks complete with cheaper models.

Real-World Token Optimization Example

Scenario: Refactor a large codebase with 50 files.

Conclusion

Token optimization isn't about being cheap — it's about being smart. The strategies in this guide will save you thousands of dollars annually while actually improving your workflow speed and code quality.

Start with the three highest-impact strategies: (1) choose the right model, (2) optimize context, (3) use /memory for reusable context. These alone will cut your token usage in half.