Claude Code Tips to Save Tokens: Context, Compaction, Scope
Claude Code tips to save tokens: read /context, compact or clear at the right time, scope reads, load skills on demand and keep exploration in subagents.
By Matthews WongReviewed on Checked against Claude Code v2.1.296
Key takeaway
Saving tokens in Claude Code means keeping the context window small, because every request sends what is already in it. Run /context to see what fills it, /clear between unrelated tasks, and /compact with a focus when you need continuity. Keep procedures in skills and noisy exploration in subagents, so only descriptions and summaries reach your conversation.
You will be able to
- Read /context and name what is filling the context window.
- Choose between /clear, /compact and rewind's summarize for the task in front of you.
- Move procedures into skills and noisy reads into subagents, so they stop costing tokens on every turn.
Step through the diagram
Press Play, or step with the arrows. Every step is written out below the diagram.
What fills the context window, and how to keep it small
The context window holds the system prompt, CLAUDE.md and memory, skill descriptions, MCP tool names and the conversation; skills, scoped reads and subagents keep it small, and /compact and /clear reset it.
Reviewed on 13 October 2026 · Claude Code v2.1.296
Keys: ← → step · Home / End · K play or pause
Everything Claude sees shares one context window: system prompt, CLAUDE.md and memory, skill descriptions, MCP tool names and the conversation. Every request sends all of it.
Run /context before you trim anything. It draws current usage as a coloured grid and suggests fixes for heavy tools, memory bloat and capacity.
/contextPredict the next step A skill is installed, but nobody has used it yet. What does it cost? (Only its description · Its full body, on every request)CLAUDE.md is sent with every request, but a skill costs only its description until it is used. Move long procedures into skills; their bodies load on demand.
description: The mechanical pipeline for shipping a bilingual blog post in this repository …Name the file and the function you mean. A vague request triggers broad scanning, and every file Claude reads stays in the conversation from then on.
add input validation to the login function in auth.tsHand test runs, log digging and wide searches to a subagent. The verbose output fills its window; only a short summary reaches yours.
Predict the next step You run /compact. What is re-read from disk afterwards? (Instructions you typed in chat · The project-root CLAUDE.md)/compact swaps the conversation for a summary, and auto-compaction does the same near the limit. Project-root CLAUDE.md is re-read from disk; chat-only instructions are not.
/compact focus on the auth bug fixFor unrelated work, /clear starts an empty conversation and costs nothing, while /compact has to read everything it summarises. /resume brings the old session back.
/rename auth-fix /clear
What fills the Claude Code context window?
Everything Claude works with sits in one context window: the system prompt, your CLAUDE.md files and auto memory, the names of MCP tools, every skill's description, and then the conversation itself, including every file Claude reads and every command output. Claude Code sends the whole conversation with every request, so a one-line question late in a long session still carries everything before it. Token use grows with context size.
Read more (2)Show less
Each feature loads differently. CLAUDE.md loads in full and is paid for on every request. Skills cost only their descriptions until one is used. MCP servers cost their tool names, because tool search defers the full schemas until a tool is called. A subagent runs in a separate window, and a hook costs nothing unless it returns context.
Size is not the only cost. The docs are blunt that performance degrades as the window fills: Claude starts to lose track of earlier instructions. So the habit is the same whether you care about usage or quality. Run /context to see the split as a coloured grid with suggestions, and /usage for the session's token usage and activity. /cost and /stats are now aliases of /usage.
When should you use /clear, /compact or rewind's summarize?
/clear starts a new conversation with empty context. Use it whenever the next task is unrelated: it costs nothing, and running /rename first lets you find the old session again with /resume. The docs add a sharper rule: if you have corrected Claude more than twice on the same issue, the context is full of failed approaches, so clear it and write a better first prompt.
Read more (2)Show less
/compact replaces the conversation with a summary when you need continuity. Give it a focus, such as /compact focus on the auth bug fix, and the summary keeps what you chose instead of what the automatic pass guesses. Compaction is itself a large request, because it reads everything it summarises. Auto-compaction runs the same pass as you approach the limit, and /autocompact sets how full the window gets before it does. To condense only part of a session, press Esc twice or run /rewind, pick a message and choose Summarize from here or Summarize up to here.
Know what survives. Project-root CLAUDE.md and auto memory are re-read from disk. Path-scoped rules and nested CLAUDE.md files return only when Claude touches a matching file again. Up to five of the files Claude read or edited are re-read, most recently modified first, and invoked skills come back capped at 5,000 tokens each and 25,000 in total. An instruction you only typed in chat lives on only inside the summary, so anything that must last belongs in CLAUDE.md.
How do skills and scoped reads cut Claude Code token usage?
CLAUDE.md is the most expensive text you write, because it rides along on every request. The docs suggest keeping it under 200 lines and moving workflow detail into skills. Claude sees a skill's description up front, cut off at 1,536 characters in the listing, and loads the body only when the skill is used. After that the body stays in the conversation, so write it as standing instructions rather than one-time steps. In this repo, about 900 lines of blog procedure live in four skills and cost only their descriptions until one is needed.
Read more (1)Show less
Scoping is the cheapest saving of all. A vague request such as improve this codebase makes Claude scan widely, while add input validation to the login function in auth.ts needs a handful of reads. The same thinking applies to tools: MCP tool schemas are deferred by default, an installed CLI such as gh adds no per-tool listing at all, and servers you are not using can be switched off in /mcp.
How do subagents and hooks protect the main context?
A subagent reads in its own context window and hands back a summary, so test runs, log digging and documentation fetches never enter your conversation. Its requests still draw on your usage, and many subagents that each return long reports can fill your context anyway. That is why this repo's blog-post-author ends with an instruction to return a compact report, not the article text.
Read more (1)Show less
Hooks run outside the model and cost nothing unless they return context. Used well, they shrink it: the docs' example filters a test run down to its failures before Claude ever sees the output. Used carelessly, a hook that injects a whole file after every edit becomes a cost on every turn. This repo's figure-review hook caps itself at twelve findings and points to the full script for the rest.
The real config behind this lesson
Excerpts from the repository that builds and deploys this website, quoted as they are.
---
name: drawing-blog-diagrams
description: Draw in-article explanatory diagrams for blog posts in this site's visual language instead of sourcing them. Use when adding a diagram, figure, illustration or in-article image to a blog post; when a borrowed diagram has foreign-language labels or is unreadable on the dark page; when working with scripts/generate-blog-diagram.mjs, BLOG_FIGURES, lib/blog-figures.ts, BlogFigure, the stack or columns layout, scripts/audit-blog-figures.mjs or scripts/review-blog-figures.mjs; and when the figure-fitness hook reports subject-absent, subject-distant, own-work-preferred, caption-restates-alt, alt-prefix, overused-figure or portrait-figure. Covers the palette, layout primitives, label writing rules, wiring a figure into a post bilingually, the audit gate and the fitness review.
---This frontmatter is all that sits in context until the skill is used; the body of more than 300 lines loads only when a request matches. The description is a list of the words a request will contain, including the finding codes the figure hook prints, and at about 780 characters it stays well under the 1,536-character listing cap.
# Report back
Return a compact report, not the article text:
- Slug, translationKey, component filename, category, read time
- The title with its character count, and the description with its count
- One line per section heading, so the argument is reviewable at a glance
- The 4–5 source URLs with the HTTP status you observed for each
- The validator's final line
- Anything you deliberately left out, and why — a claim you could not source, a
figure you would want, an angle that duplicated an existing postA subagent's report is the only part of its work that lands in your context, so this repo specifies its shape. The main session gets the counts, one line per heading, the source statuses and the validator's last line, which is enough to review the work without pulling a whole article into the conversation.
/** Findings a hook may inject before it costs more context than it saves. */
const HOOK_MAX_FINDINGS = 12;The PostToolUse hook that reviews figures after every edit budgets its own output. Past twelve findings it adds one line saying how many more there are and which script lists them, and when there is nothing to report it prints nothing at all.
Mistakes that cost real time
Compacting by reflex
/compact reads the whole conversation to summarise it, so compacting a huge session is itself a large request. When the next task is unrelated, /clear is free and /resume can bring the old session back.
A rule that lived only in chat
After compaction, an instruction you only typed in the conversation survives, at best, as a line in the summary. Project-root CLAUDE.md is re-read from disk. If a rule keeps vanishing, it belongs in CLAUDE.md, not in a message.
The kitchen-sink session
One task, then an unrelated question, then back again: the context fills with material that helps neither. The docs' fix is /clear between unrelated tasks, and a fresh prompt after two failed corrections.
A hook that floods the context
Context a hook returns is added every time it fires. Return only the lines that matter, cap the count the way this repo's figure hook stops at twelve findings, and stay silent when there is nothing to say.
What I'd change here: the root CLAUDE.md
This repo's CLAUDE.md has grown past 500 lines, well over twice the documented target of 200, and every line rides on every request. Its long cover and figure procedures already live in skills, so the next cleanup moves them out and keeps only the facts and the hard rules.
| /clear | /compact | Rewind: Summarize from here | |
|---|---|---|---|
| What it does | Starts a new conversation with empty context | Replaces the conversation with a summary | Condenses the messages after a chosen point |
| Use it when | The next task is unrelated | You need to keep going on the same task | One stretch is bloated, such as a big log read |
| What stays | CLAUDE.md and memory; the old chat via /resume | The summary, project-root CLAUDE.md, recent files | Earlier messages in full, later ones as a summary |
Do it on your own machine
You need Claude Code in any git repository. Make a noisy log file first, then watch what each habit does to /context.
Create a large log with two real errors buried in it.
mkdir -p logs seq 1 20000 | sed 's/^/INFO request ok id=/' > logs/app.log echo "ERROR payment timeout id=777" >> logs/app.log echo "ERROR db connection reset id=901" >> logs/app.logStart a session and run /context before typing anything else. Note how much the memory files and skill descriptions already take.
/contextAsk Claude to read the whole log, then run /context again and compare.
Read logs/app.log and list every error /contextOpen the rewind menu, pick that message and choose Summarize from here. Check /context once more.
/rewind /contextAsk the same question through a subagent and compare how much your context grows.
Use a subagent to find the errors in logs/app.log and report only the matching lines /contextAsk a side question that never enters history, check the session's usage, then finish cleanly before the next task.
/btw which log file did we search? /usage /rename log-hunt /clear
Three questions before you move on
Pick an answer to see why it is right or wrong. Nothing is saved or graded, so guess freely.
Answer in your head, then check
1.When should you use /clear instead of /compact?Show the answer
Answer:When the next task is unrelated. /clear costs nothing and /resume brings the old session back, while /compact must read the whole conversation to summarise it.
2.You loaded a path-scoped rule, invoked a skill, and the project-root CLAUDE.md is present. What comes back after compaction?Show the answer
Answer:The project-root CLAUDE.md is re-read from disk. The skill body is re-attached, capped at 5,000 tokens per skill and 25,000 in total. The path-scoped rule returns only when Claude touches a matching file again.
3.You moved a long deploy procedure out of CLAUDE.md into a skill. What still costs tokens on every request?Show the answer
Answer:Only the skill's description, which the listing cuts off at 1,536 characters. The body loads when the skill is used, and from then on it stays in the conversation.
4.An older guide tells you to run /cost. What should you run instead?Show the answer
Answer:/usage. /cost and /stats still work, but they are aliases that open /usage.
Related deep dives on this site
Sources
Primary sources checked on the research date. Follow them for the current version.
- Claude Code docs: Reduce token usage
- Claude Code docs: Why usage climbs in a long session
- Claude Code docs: Context cost by feature
- Claude Code docs: What survives compaction
- Claude Code docs: When your context fills up
- Claude Code docs: Commands reference (/context, /compact, /clear, /usage)
- Claude Code docs: Avoid common failure patterns
- Claude Code docs: Rewind and summarize
- Claude Code docs: Skill content lifecycle
- Claude Code docs in Indonesian: managing token usage