Guide · checked against the Claude Code docs, 17 Nov 2026
How to reduce Claude Code token usage
Claude Code sends your whole conversation with every request, so most of what you pay for is context, not the prompt you just typed. These are the changes that actually shrink it, roughly in order of impact, with the command or setting for each. To see which files in your repo an agent can't use, run the free ctxray scan (step 6).
1. Where the tokens go
Every request carries the full conversation: CLAUDE.md, every file Claude has read, every tool result and every message. Each tool call is another request carrying that history again. Prompt caching makes the repeated part much cheaper, but not free, so a one-line question at the end of a long session still pays to re-read everything before it. After a break longer than the cache lifetime, the first message misses the cache and pays full price for the whole context.
Two other costs build up quietly. Extended thinking is billed as output tokens, the expensive kind. And every subagent sends its own requests on top of the main conversation.
For scale, Anthropic reports an average of about $13 per developer per active day across enterprise deployments, with 90% of users under $30.
2. Clear between tasks, compact on purpose
/clearwhen you move to unrelated work. Stale context is re-sent with every later message, and clearing costs nothing. Run/renamefirst if you might want to/resumethe session later./compact Focus on the API changes and the failing testswhen you need continuity. Compaction has to read the whole conversation to summarize it, so it is a large request in itself: compact once, deliberately, rather than repeatedly.- Standing compaction instructions can live in CLAUDE.md under a
# Compact instructionsheading.
3. Match the model and effort to the job
Sonnet handles most coding work. Keep Opus for architecture and long multi-step reasoning, and switch with /model. Subagents that only search or summarize can run on Haiku: set model: haiku in the subagent's configuration. Note that switching models mid-session re-reads the conversation uncached, because each model has its own cache.
| Per million tokens | Input | Output | Cache read |
|---|---|---|---|
| Opus 5.5 | $4.00 | $20.00 | $0.20 |
| Sonnet 5.5 | $2.00 | $10.00 | $0.10 |
| Haiku 5.5, prompt ≤ 100k | $0.10 | $0.50 | $0.01 |
| Haiku 5.5, prompt > 100k | $0.50 | $2.50 | $0.05 |
Haiku's price jumps five-fold once a single request goes over 100k input tokens, cache reads included. A long main session is often past that line, so Haiku pays off most in short, focused subagents.
Thinking is the other lever. You can't switch it off on the 5.5 models or Fable, but /effort lowers how much of it you pay for on simple tasks. On models with a fixed thinking budget, MAX_THINKING_TOKENS caps it.
4. Keep the always-loaded context small
- CLAUDE.md is loaded at the start of every session, whatever you are doing. Anthropic suggests keeping it under about 200 lines. Move workflow-specific instructions, such as how to review a PR or run a migration, into skills, which load only when used.
- MCP servers: tool definitions are deferred by default, so only names and server instructions enter context up front. Still, run
/contextto see what is taking space, disable servers you are not using in/mcp, and prefer a CLI such asghwhen one does the job.
5. Keep noisy output out of the main conversation
- Subagents for verbose work. Test runs, log digging and documentation lookups can flood the context. In a subagent the noise stays in its context and only a summary comes back.
- Hooks that filter before Claude reads. A
PreToolUsehook can rewrite a test command so only failures come back. The official example does this fornpm test,pytestandgo test, turning tens of thousands of tokens into hundreds. - Code intelligence plugins for typed languages: one go-to-definition call replaces a grep followed by reading several candidate files.
6. Stop Claude reading files it can't use
Most guides skip this one. Lockfiles, snapshots, generated code, minified bundles, fixtures and large data files cost tokens whenever a search or a read lands in them, and they teach the model nothing about your code.
A .claudeignore file does nothing. Claude Code doesn't read it. The supported mechanism is a Read deny rule in .claude/settings.json.
{
"permissions": {
"deny": [
"Read(package-lock.json)",
"Read(dist/**)",
"Read(tests/__snapshots__/**)"
]
}
}
Rules use gitignore syntax. A bare filename such as package-lock.json matches at any depth, and a single-directory deny pattern such as dist/** also matches nested copies. Claude Code applies Read rules to its file tools, to Grep and Glob, and to @-mentions on a best-effort basis, and to shell commands it recognizes, such as cat and head. They don't stop a recursive grep -r or a script that opens files itself; the sandbox covers that.
Which files? Measure instead of guessing
ctxray walks a repo the way an agent would, counts every file in tokens and flags the ones an agent can't use. On fresh shallow clones of six popular repos (12 and 13 Nov 2026):
| Repo | Tokens | Flagged | Biggest single source |
|---|---|---|---|
| langchain | 9.82M | 55% | 22 uv.lock files, 5.11M tokens |
| ollama | 9.26M | 51% | shakespeare.txt test data, 1.33M tokens |
| excalidraw | 4.50M | 54% | a wasm wrapper and a font source file, ~590k |
| fastapi | 8.47M | 43% | one drawio SVG, 631k tokens |
| shadcn/ui | 7.79M | 38% | 22 lockfiles, 813k tokens |
| express | 196k | ~0% | nothing worth flagging |
These are whole-repo totals, so treat them as an upper bound: no agent reads everything. They show where a stray search or read is expensive.
Run it, review the .agentignore it writes, then turn that file into deny rules:
npx github:geraltbhai/ctxray # breakdown by file and category
npx github:geraltbhai/ctxray init # writes .agentignore and an AGENTS.md scaffold
# .agentignore uses gitignore syntax, so each line maps to a Read deny rule
grep -vE '^[[:space:]]*(#|$)' .agentignore \
| sed -E 's#/$#/**#; s#.*#Read(&)#' \
| jq -R . | jq -s '{permissions:{deny:.}}'
Merge the output into .claude/settings.json; deny lists from different settings files combine, so existing rules stay. On shadcn/ui this produced 144 rules covering 2.85M tokens, 37% of the repo. Read the list before you commit it: anything you actually want Claude to see must not be on it, and paths containing brackets or parentheses, such as Next.js route groups, are worth a second look.
7. Ask precisely, plan first
- "Improve this codebase" makes Claude scan widely. "Add input validation to
login()inauth.ts" lets it read two files. - For bigger changes, press Shift+Tab into plan mode so the approach is agreed before any code is written. If it heads the wrong way, press Esc early, and use
/rewindto go back to a checkpoint. - Give Claude a way to check its own work, such as a test or an expected output, so mistakes get caught before another round trip.
8. Measure what changed
/usageshows session tokens and estimated cost, plus a prompt-cache line with hit rate and misses. On Pro, Max, Team and Enterprise it also breaks recent usage down by skill, subagent, plugin and MCP server, with recommendations; in recent versions, pressingfapplies the ones it can./contextshows what is filling the window right now./insightswrites a report on how you work across recent sessions.- Re-run
ctxrayafter adding rules. It reads.agentignoreback, so you can watch the flagged total drop.
FAQ
How much does Claude Code cost per day?
Anthropic reports an average of about $13 per developer per active day across enterprise deployments, with 90% of users under $30. Your number depends mostly on how much context each request carries.
Does .claudeignore work?
No. Claude Code doesn't read a .claudeignore file. To keep lockfiles, builds and fixtures out of context, add Read deny rules under permissions.deny in .claude/settings.json (step 6).
Do @imports in CLAUDE.md save tokens?
No. Imported files load at launch together with CLAUDE.md. What does load on demand: rules in .claude/rules with a paths: frontmatter, CLAUDE.md files in subfolders, and skills (step 4).
Is /clear or /compact cheaper?
/clear costs nothing: it just starts fresh. /compact has to read the whole conversation to summarise it, so it is a large request in itself. Clear between unrelated tasks; compact once, deliberately, when you need continuity (step 2).
Can I turn extended thinking off to save tokens?
Thinking is billed as output tokens. On the current 5.5 and Fable models it can't be switched off completely, but /effort lowers how much the model thinks (step 3).
Does Haiku cost the same for long prompts?
No. Haiku 5.5 costs $0.10 per million input tokens up to a 100k-token prompt and $0.50 above it, so a Haiku subagent that reads a lot can lose its price advantage. Keep Haiku jobs small (step 3).
Sources
- Claude Code docs: Manage costs effectively
- Claude Code docs: Configure permissions (Read rules, path patterns)
- Claude Code docs: Settings files and precedence
- Claude API pricing
- ctxray on GitHub (MIT; the token estimator's calibration script is in the repo)