Claude Code

Cutting token usage in Claude Code: 8 habits from the official docs

TL;DR

Claude Code cost scales with context size. The highest-impact habits: /clear between tasks, Sonnet by default, lower effort for easy work, disable unused MCP servers, keep CLAUDE.md under 200 lines, filter logs with hooks and name the file in your prompt.

Claude Code is billed by tokens, and tokens grow with context size: the more Claude has to "read", the more each message costs. According to Anthropic's cost management page, across enterprise deployments the average developer costs about $13 per working day, $150–250 per month, and 90% of users stay under $30 a day. That number swings a lot with work habits. This post collects the token-saving practices recommended in the official docs, ordered by impact.

Summary table

HabitHowWhy it saves
Clear between tasks/rename then /clear; come back with /resume if neededOld context is resent with every later message
Pick the right model/model; Sonnet for everyday work, Opus for architecture/multi-step reasoningOpus costs more; subagents inherit the session's model
Lower effort/effort or inside /modelThinking tokens are billed as output, possibly tens of thousands per request
Prefer CLIs over MCPUse gh, aws, gcloud…; disable unused MCP servers in /mcpCLIs don't add tool lists to context
Move instructions into skillsWrite PR review, migration… workflows as skillsCLAUDE.md loads every session; skills load only when used
Filter output with hooksA hook greps logs and returns only error linesFrom tens of thousands of tokens down to a few hundred
Push "noisy" work to subagentsRun tests, read docs, process logs in a subagentLong output stays in the subagent's context; only a summary comes back
Specific promptsName the file, function and expected result"Improve the codebase" triggers broad scanning

1. /clear is the cheapest saving button

Every request resends the whole conversation. A one-line question in a session that's been open all day still drags the full history along (even if most of it is read from cache at a lower price). When switching to unrelated work: name the session with /rename, then /clear. /clear costs nothing, whereas /compact has to read the whole conversation to summarise it, so it's a big request in itself.

When you need to keep the thread, compact with instructions:

/compact Keep the sample code, the agreed API and the list of failing tests

Or set it permanently in CLAUDE.md:

# Compact instructions
When you are using compact, please focus on test output and code changes

2. Output-filtering hook: the official example

Instead of letting Claude read 10,000 lines of test logs, a PreToolUse hook can rewrite npm test/pytest/go test commands so they only print failures:

# the core idea inside the hook script
filtered_cmd="$cmd 2>&1 | grep -A 5 -E '(FAIL|ERROR|error:)' | head -100"

The hook returns updatedInput with the filtered command. Check it with /hooks. Use a strict pattern so the hook only applies to test commands and doesn't accidentally rewrite others.

3. CLAUDE.md under 200 lines

CLAUDE.md is loaded into context as soon as a session starts. Detailed instructions for one specific workflow living there means you pay tokens for it even while fixing an unrelated bug. The docs recommend keeping it under 200 lines, essentials only, and moving the rest into skills.

4. Code intelligence plugins for typed languages

One "go to definition" call replaces a chain of "grep → read several candidate files". The language server also reports type errors after edits, so Claude catches mistakes without running the compiler.

5. Stop early when it goes off track

  • See Claude heading the wrong way: press Esc immediately. Use /rewind or double Esc to return to a previous checkpoint.
  • Complex task: enter plan mode (Shift+Tab) to agree the direction first.
  • Provide verification criteria (test cases, screenshots, expected output) so Claude fixes things itself instead of you nudging over many turns.

Track where you spend

  • /usage: the session's estimated cost, split by model, with a prompt cache statistics line. Pro/Max/Team/Enterprise plans also get a breakdown by skill/subagent/MCP and reduction suggestions.
  • /context: see what's taking up space in context.
  • A status line can show context usage continuously.

Caveats

  • Agent teams use roughly 7× the tokens of a normal session when teammates run in plan mode, because each has its own context. Keep teams small and shut teammates down when done.
  • Background tasks (summarising the conversation for --resume, prompt suggestions…) also use tokens, typically under $0.04 per session.
  • Figures in /usage are list-price estimates; check the Console for the exact bill.

How to apply it

  • Dev: The three most valuable habits: /clear when switching tasks, Sonnet as the default, prompts that name the exact file/function.
  • Tech Lead: Review the repo's CLAUDE.md, cut it under 200 lines, move workflows into skills. Add a shared test-output filtering hook for the team.
  • PM / budget owner: Pilot with a small group to get a cost/dev/day baseline before rolling out; set a workspace spend limit.

Sources & references

  1. Manage costs effectively — Claude Code Docs