Token cost is the hidden tax on AI-assisted development. A focused coding session with Claude Code can consume thousands of tokens in minutes — and an unfocused one can consume ten times as many for the same output. The difference comes from habits that either burn tokens or preserve them.
The Biggest Lever: Model Selection
The single highest-impact thing you can do is use the right model for each task.
Sonnet 4.6 and Opus 4.6 produce nearly identical output for 80-90% of coding tasks. Opus genuinely outperforms Sonnet only in specific cases: multi-file bugs with indirect causation, architecture decisions, security review.
# Default: Sonnet (fast, cost-effective)
claude
# Only when you need deeper reasoning
claude --model claude-opus-4-6
The rule: start every session in Sonnet, switch to Opus only when Sonnet fails on the same problem twice. Using Opus by default for ordinary tasks is the most common way Claude Code users overspend.
Context Window: The Compounding Leak
Every message includes the full conversation history up to that point. As a session grows longer, each subsequent message gets more expensive — not because the new message is bigger, but because the accumulated context is.
/compact — Summarize and Continue
When a session is getting long but you're not done:
/compact
Replaces conversation history with a compressed summary. You lose exact phrasing but keep important decisions and context. Much cheaper per subsequent message.
Use /compact when: session has been running 45+ minutes, or you're starting a new subtask.
/clear — Start Clean
/clear
Wipes the conversation entirely. Next message starts with zero accumulated context — only your CLAUDE.md. Use this when moving to a completely unrelated task.
CLAUDE.md: Tokens You Never Spend Twice
Every time you re-explain your stack or conventions, you're spending tokens you already spent in a previous session.
# Project Context
## Stack
- Next.js 15, TypeScript strict, Drizzle ORM + Neon, Clerk, Bun
## Conventions
- Server actions in /src/actions/ — never inline mutations in components
- No Prisma, no NextAuth, no npm (use Bun)
## Key files
- /src/lib/db/schema.ts — full Drizzle schema
- /src/lib/auth.ts — Clerk session helpers
A 300-token CLAUDE.md that saves a 150-token re-explanation per session pays for itself in 2 sessions. Infinite return from session 3 onward.
Specific Prompts Beat Vague Requests
Vague prompts force Claude to explore before executing. Exploration costs tokens.
Vague (expensive):
"Fix the auth stuff"
Claude has to figure out what "auth stuff" means, read multiple files trying to identify the problem, make assumptions, possibly go down the wrong path.
Specific (efficient):
"The JWT validation in /src/lib/auth.ts line 47 fails when the token
contains a custom claim. The claim key is 'org_id'. Fix the validation
to accept it."
Claude reads one file, makes one targeted change. Done.
The pattern: tell Claude exactly what file, what function, what the expected behavior is, and what the current failure is. The more context you provide upfront, the less Claude has to spend tokens discovering it.
Plan Mode for Complex Tasks
For tasks that touch multiple files or have non-obvious scope, Plan Mode is more token-efficient than direct execution:
claude --plan
# Review the plan before any tokens are spent on wrong code
# Redirect if the approach is wrong (costs almost nothing)
/execute # Execute once confident — first-attempt success
One failed multi-file refactor with two correction rounds costs 4-5x what a planned implementation would have. Use Plan Mode for anything touching 3+ files.
Batch Related Changes
Each message exchange has overhead — the context is re-sent, Claude processes the full history. Sending 10 separate single-instruction messages costs 10x the overhead of one message with 10 instructions.
Inefficient:
"Add email validation"
"Add password validation"
"Add loading state"
"Add error display"
Efficient:
"Do these four things in the signup form:
1. Email validation (format + required)
2. Password validation (min 8 chars + required)
3. Loading state on submit button
4. Error message display below each field"
Same output, ~25% the overhead.
What Costs More Than You Think
- Asking Claude to explore: "What's the best way to handle X?" requires reading files, reasoning about options, writing a detailed answer. Use sparingly.
- Correction cycles: Every "no, not like that" correction costs as much as the wrong response. Better prompts upfront are cheaper than corrections.
- Leaving sessions running: A session doesn't get cheaper as the day goes on — it gets more expensive per message as history accumulates.
- Unnecessary file reads: "Read the whole codebase" is expensive. Do it once and capture the useful parts in CLAUDE.md.
The Token Efficiency Checklist
Before starting a task:
- [ ] Using Sonnet? (switch to Opus only if needed)
- [ ] Is CLAUDE.md current? (no re-explaining context)
- [ ] Prompt specific enough that Claude won't explore?
- [ ] Should I use Plan Mode? (3+ files, non-obvious scope)
- [ ] Can I batch multiple changes into one message?
During a long session:
- [ ] Running 45+ minutes? →
/compact - [ ] Starting an unrelated task? →
/clear
Applied consistently, these habits reduce token consumption by 40-60% compared to unstructured usage — with no reduction in output quality.
Full article at stacknotice.com/blog/claude-code-token-usage-optimization
Top comments (0)