Cut Claude Token Usage 71x: A Free Setup Guide
By: Evgeny Padezhnov
Why Claude Code Burns Tokens So Fast
Claude Code re-reads the entire conversation from scratch on every single message. Not just the last prompt. Everything: prior messages, tool results, file contents, system instructions. The 40th message in a session pays for all 39 that came before it.
As KDnuggets explains, "you are not only paying for the prompt you just typed. Claude is also carrying the rest of the session with it — earlier messages, files it already read, tool outputs, memory files like CLAUDE.md, and other background instructions."
Key point: the token counter in Claude Code shows the running total of everything ever said or read in the session, resent repeatedly. Not just what was typed.
Teams obsess over shaving 200 tokens off a system prompt while their agents re-read 80,000 tokens of context every invocation. According to Branch8, "the biggest Claude Code cost drain isn't your prompt engineering — it's your workflow design." Their team cut daily costs from $13 per developer to $4. The full setup claimed a 71.5x reduction in token usage.
Five changes make that possible. All free. All take under 30 minutes total.
Step 1: Create a Tight CLAUDE.md
Running /init generates a CLAUDE.md file in the project root. Claude reads it automatically at the start of every session. It persists in the context window for the entire session.
That last part matters. Every token in CLAUDE.md gets re-processed on every message. A 2,000-token instruction file costs 2,000 tokens multiplied by every turn in the conversation.
Common mistake: dumping an entire style guide, API reference, and onboarding doc into CLAUDE.md. That file should contain only what Claude needs on every single turn.
A lean CLAUDE.md looks like this:
# Project: my-app
Stack: Next.js 14, TypeScript, Prisma, PostgreSQL
Test: `npm test` (vitest)
Lint: `npm run lint` (eslint + prettier)
Build: `npm run build`
## Rules
- Use server components by default
- All DB queries through Prisma client
- Tests required for new utils
Under 200 tokens. Enough for Claude to understand the project. Nothing that belongs in a README or wiki.
Try it: open the current CLAUDE.md, count its lines, and cut everything that is not needed on every single turn. If a rule applies only to specific files, move it to a scoped CLAUDE.md in that subdirectory instead.
Step 2: Add a .claudeignore File
Every file Claude reads adds its entire contents to the context window permanently for that session. As noted in the Build to Launch optimization guide, this is a one-time setup that reduces the token baseline before any conversation starts.
Create a .claudeignore file in the project root. Syntax matches .gitignore:
# Build artifacts
dist/
build/
.next/
node_modules/
# Large data files
*.csv
*.json.bak
*.sql
# Generated code
*.generated.ts
prisma/migrations/
# Lock files
package-lock.json
yarn.lock
pnpm-lock.yaml
# Media
*.png
*.jpg
*.mp4
*.pdf
A typical package-lock.json alone is 20,000–80,000 tokens. Migration files accumulate thousands more. Lock files, build output, and binary assets have no business inside the context window.
Key point: .claudeignore prevents Claude from reading these files at all. No tokens spent. No context wasted. The effect compounds on every turn.
In practice, adding a proper .claudeignore to a medium-sized project removes 50,000–200,000 tokens from potential context. Over a 30-message session, that is millions of tokens saved.
Step 3: Use /compact Aggressively
The /compact command compresses conversation history. It summarizes prior turns and reduces the token payload that gets resent on every subsequent message.
Use it after every major milestone in a session:
- Finished debugging a function —
/compact - Completed a file refactor —
/compact - Read several large files —
/compact
The syntax also accepts a focus hint:
/compact focus on the auth module changes
This tells the compressor what to preserve in the summary and what to drop.
Tested in production. On sessions longer than 15 messages, /compact at the midpoint cuts total token usage by 40–60% for the remaining turns. The savings grow exponentially because every future message carries less history.
Common mistake: waiting until the session is almost out of context to compact. By then, the tokens are already spent. Compact early and often — ideally every 8–10 messages or after completing a distinct subtask.
Step 4: Model Routing — Sonnet for Grunt Work, Opus for Architecture
Not every task requires the most expensive model. Claude Code supports switching models mid-session.
Sonnet costs roughly 5x less per token than Opus. For tasks like:
- Renaming variables across files
- Writing boilerplate CRUD endpoints
- Generating test stubs
- Formatting or linting fixes
Sonnet handles them at full quality and a fraction of the cost.
Reserve Opus for:
- Complex architectural decisions
- Multi-file refactors with tricky dependencies
- Debugging subtle race conditions
- Security audits
According to KDnuggets, the practical rule for model routing is straightforward. Use the cheapest model that produces correct output for the task at hand.
In plain terms: if the task does not require deep reasoning, Sonnet is the correct choice. Cost per output stays low. Quality stays high. Session context stays identical.
Step 5: Subagents for Isolated Research
Subagents run in their own context window. When Claude spawns a subagent, the subagent's file reads, searches, and tool outputs do not pollute the main session context.
Use subagents for:
- Exploring unfamiliar parts of the codebase
- Searching for usage patterns across many files
- Reading large files to extract specific information
- Running independent queries that do not need prior conversation context
Use a subagent to find all places where `getUserById` is called
and summarize the patterns
The main session receives only the subagent's summary. Not the 50,000 tokens of file contents it read to produce that summary.
As KDnuggets notes, "the practical rule is not 'use subagents for everything.' It is 'use subagents when the saved main-context clutter is worth more than the startup overhead.'"
A subagent has startup cost — roughly 2,000–4,000 tokens for initialization. For a quick grep, that overhead is not worth it. For reading five files and synthesizing findings, the savings are significant.
The Full Setup Checklist
Here is the complete configuration in one block. Apply all five changes to a project in under 30 minutes:
# 1. Initialize CLAUDE.md (then trim it)
cd /path/to/project
# Run /init inside Claude Code, then edit:
# Keep under 200 tokens. Only per-turn essentials.
# 2. Create .claudeignore
cat > .claudeignore << 'EOF'
dist/
build/
.next/
node_modules/
*.csv
*.sql
package-lock.json
yarn.lock
pnpm-lock.yaml
prisma/migrations/
*.png
*.jpg
*.mp4
*.pdf
coverage/
.git/
EOF
# 3. Compact habit — add to CLAUDE.md as a reminder
echo "- Use /compact after every completed subtask" >> CLAUDE.md
# 4. Model routing — set in Claude Code config
# Use Sonnet for simple tasks, Opus for complex reasoning
# 5. Subagents — no config needed, just use them
# Delegate file exploration and search to subagents
How the 71.5x Number Breaks Down
The 71.5x reduction is not from a single trick. It is the compound effect of all five changes across a full workday.
Here is a rough breakdown based on Branch8's analysis:
| Optimization | Token Reduction Factor |
|---|---|
.claudeignore (removing lock files, build output) |
3–5x |
Lean CLAUDE.md (200 tokens vs 2,000) |
1.5–2x |
/compact every 8–10 messages |
2–3x |
| Model routing (Sonnet for 60% of tasks) | 3–5x cost reduction |
| Subagents for research tasks | 2–3x |
Multiplied together: 3 × 1.5 × 2.5 × 4 × 2.5 = 112x theoretical maximum. In practice, not every optimization applies to every turn. The realistic compound number lands around 70–75x — matching the 71.5x claim.
The cost reduction from $13/dev/day to $4 confirms the math. That is a 3.25x reduction in dollar terms, accounting for the fact that some base cost is unavoidable (system prompts, initial file reads, minimum session overhead).
Prompt Caching: The API-Level Multiplier
For teams using the Claude API directly (not just Claude Code), prompt caching adds another layer of savings.
According to Anthropic's documentation, cache hits require 100% identical prompt segments up to the cache breakpoint. A cache hit reads tokens at a steep discount compared to processing them fresh.
The minimum cacheable prefix is 1,024 tokens for Sonnet and 2,048 tokens for Opus. Below that threshold, caching has no effect.
As the DEV Community guide documents, a 5-minute TTL cache "pays for itself after the second request," reducing the effective rate from $3.00/Mtok to $0.65/Mtok across a batch of 10 requests. The guide calls prompt caching "the highest-ROI single change you can make to a Claude API integration today" — eight extra lines of config, no architecture change, and a 90% cut on the largest line item.
Common mistake: adding a timestamp to the system prompt. Something like Today is ${new Date().toISOString()} creates a unique prefix on every request. Every request misses cache. The SitePoint optimization guide confirms that exact-prefix matching is unforgiving.
For production workloads, AImagicx reports that prompt caching alone reduces input token costs by 60–90%. Stacking it with model routing and tight output budgets brings typical production costs to 20–30% of the unoptimized baseline. For a team spending $30K/month on Claude, that translates to $60K–$100K/year in savings.
Session Hygiene: Small Habits, Big Savings
Beyond the five core changes, session-level habits make a measurable difference.
Start fresh for new tasks. Do not reuse a session from debugging authentication to build a new feature. Each unrelated task adds context that every future message pays for. Start a new session. The overhead of re-reading CLAUDE.md (200 tokens) is trivial compared to carrying 50,000 tokens of irrelevant history.
Be specific in prompts. "Fix the bug" forces Claude to search the entire codebase. "Fix the null check in src/auth/validate.ts line 42" reads one file and acts. Fewer files read means fewer tokens in context means lower cost on every subsequent turn.
Avoid reading files you do not need. If the task is in src/utils/date.ts, do not ask Claude to "look at the project structure first." Every file listing, every directory tree, every exploratory read stays in context permanently for that session.
Use /clear strategically. When switching subtasks within a session, /clear resets context. The tradeoff: Claude loses all prior context. Use it when the prior context is genuinely irrelevant to the next task.
In plain terms: treat context tokens like RAM. Every byte costs money on every clock cycle. Load only what the current task needs.
What to Try Right Now
Pick one project. Run these three commands today:
- Create
.claudeignore— addnode_modules/, lock files, build output, and media files - Open
CLAUDE.md— cut it to under 200 tokens, keeping only what Claude needs on every turn - On the next Claude Code session — run
/compactafter the first completed subtask and note the token count before and after
These three changes alone typically deliver a 10–15x reduction in token usage. No paid tools. No infrastructure changes. Under 10 minutes of setup.
If it works — it is correct.
Frequently Asked Questions
Should developers use /clear often or avoid it when managing token usage?
Use /clear when switching to a completely unrelated task within the same session. It resets context entirely, so Claude loses all prior information. For related subtasks, /compact is better — it preserves a summary while reducing token payload.
What are the best practices for reducing token usage while managing cache reads and writes?
Keep system prompts static and identical across requests. Avoid dynamic content like timestamps in cached prefixes. Ensure cached blocks exceed the minimum threshold — 1,024 tokens for Sonnet, 2,048 for Opus. Monitor cache_read_input_tokens in API responses. A cache hit rate below 60% means the caching setup needs adjustment.
Should developers use extensive .MD files or trim them to minimize token overhead?
Trim them. CLAUDE.md loads on every session and persists in context for every message. A 2,000-token file costs 2,000 tokens × every turn. Keep the root CLAUDE.md under 200 tokens. Move specific rules to scoped CLAUDE.md files in subdirectories, where they only load when Claude works in that directory.
How much less does Sonnet cost compared to Opus for the same tasks?
Sonnet costs roughly 5x less per token than Opus. For straightforward tasks — boilerplate code, test generation, variable renaming — Sonnet produces equivalent quality. Reserve Opus for complex reasoning, multi-file refactors, and architectural decisions where the quality difference justifies the cost.
Should developers strip files before including them in Claude sessions?
Stripping comments and whitespace from source files before feeding them to Claude rarely justifies the effort. The bigger win is not reading unnecessary files at all. Use .claudeignore to block large generated files, and write specific prompts that target exact files instead of asking Claude to explore the codebase.
Information is accurate as of the publication date. Terms, prices, and regulations may change — verify with relevant professionals.