Skip to content

Token Budgeting and Cost Management

Track your spending, understand token consumption patterns, and prevent runaway costs. Practical cost optimization without sacrificing quality.

Most developers have no idea how much they spend on AI tooling until they get the bill. The average Claude Code user spends about $6 per day. Roughly $100 to $200 per month with Sonnet 4.6. Ninety percent of users stay under $12 per day.

But the variance is massive. Some developers burn through tokens like they're free. Others squeeze incredible value from minimal usage. The gap comes down to understanding how tokens work and being deliberate about it.

How Token Costs Work

Every interaction involves two token types: input and output. Input tokens are everything sent to the model. Your prompt, file contents Claude Code reads, tool results, CLAUDE.md files, conversation history. Output tokens are everything generated back. Code, explanations, tool calls, reasoning.

Output tokens cost significantly more than input tokens. This is the single most important thing to internalize.

A vague prompt like "improve this codebase" forces Claude Code to generate enormous output as it explores, reads, and rewrites. A specific prompt like "refactor the error handling in auth.ts to use early returns" produces targeted output and costs a fraction. Same quality. Wildly different bill.

There's also background token usage you might not think about. Conversation summarization, command processing, context management. Typically under $0.04 per session. Negligible.

One thing working in your favor: prompt caching. Claude Code automatically caches repeated content like system prompts and CLAUDE.md files. Same content across multiple requests means you pay full price once, then get heavy discounts on subsequent uses. You can disable this with DISABLE_PROMPT_CACHING=1, but don't.

Tracking Your Spend

Claude Code gives you three commands. Each serves a different purpose.

/cost shows your current session's token consumption. Total cost, API duration, wall duration, code change summary. Mostly useful for API users paying per token.

/usage shows plan limits and rate limit status. Run this when you hit a rate limit.

/stats is the interesting one. It visualizes daily usage patterns, session history, streaks, and model preferences. This is where you spot trends.

Open Claude Code right now and run all three:

/cost
/usage
/stats

Look at your /stats output. What's your average daily cost? Which model are you using most? If you've been running Opus for everything, that's probably your biggest cost driver right there.

Hard Limits for Automation

For batch workflows, set a maximum budget with --max-budget-usd. Only works in print mode:

claude -p --max-budget-usd 5.00 "Analyze all test files and suggest improvements"

Claude Code stops at $5. This is non-negotiable for CI pipelines and automation. Never let an unattended process run without a spending cap. Ever.

Cutting Your Bill (Ranked by Impact)

1. Manage your context window. Run /clear between unrelated tasks. Use /compact with focus instructions when conversations get long. A bloated context window means every new message carries the weight of everything before it.

2. Pick the right model. Sonnet handles the vast majority of coding tasks. Opus is for genuinely complex reasoning. Haiku for subagent tasks. If you're running Opus for everything, that's your biggest cost driver.

3. Write specific prompts. "Fix the bug in the login flow where users get redirected to a 404 after OAuth callback" costs way less than "fix all the bugs." Vague prompts force broad exploration, more file reads, more output tokens.

4. Reduce MCP server overhead. Every connected MCP server adds tokens to your context, even if you never call it. Disable servers you aren't actively using. Prefer CLI tools like gh or jq over MCP servers when the CLI can do the same job.

5. Offload work to hooks and skills. Running linters or processing data? Do that before Claude Code sees the output. Feed it clean, filtered input instead of asking it to parse raw logs.

6. Move specialized CLAUDE.md content to skills. Your CLAUDE.md loads into every conversation. Large instruction blocks that only apply to certain tasks should be skills that load on demand.

7. Adjust extended thinking. Lower the reasoning effort for simple tasks. Claude Code expends fewer tokens when you tell it something is straightforward.

8. Delegate verbose operations to subagents. Processing lots of files or generating massive output? Subagents work in their own context window and return a summary, keeping your main session lean.

Teams

If you're managing a team, the Anthropic Console provides workspace spend limits and cost reporting. Per-user budgets, aggregate usage tracking. Check the rate limit recommendations in the docs for team sizing guidance.

In Practice

Average spend is $6/day, $100-200/month with Sonnet 4.6. Know your baseline by running /stats. The single biggest cost lever is prompt specificity because vague prompts generate massive output tokens, and output is the expensive side. Use /clear between tasks, /compact when conversations grow. And put --max-budget-usd on every automated workflow. No exceptions.

Mastering Claude Code

Lesson 25 of 70