← All guides

Guide · Less context, longer sessions · ★★☆☆☆

How to save tokens in Claude Code: /clear, /compact and six more habits

Claude "forgot" a rule you gave it an hour ago. It didn't get tired: its working memory filled up. These habits keep that memory small, so your sessions last longer, cost less and stay sharp.

By Arthur Hsiao · Last updated · 7 min read

Why context is the cost. The context window is everything Claude can see in a session: your messages, its replies, every file it read, command output, and CLAUDE.md. All of it is sent again with every new turn, so a 20,000-token log you pasted early on is paid for on every later message. The window also has a size limit. Near the limit, Claude Code compacts on its own: it replaces the older conversation with a summary, and details can drop out. So most savings come from one idea: keep big things out of the conversation. Checked against the context window docs on 15 Nov 2026.

1See where the tokens go

/context

Shows how full the window is, as a coloured grid, split by what uses it: system prompt, tools, memory files, the conversation. It also gives tips, such as a memory file that has grown too big. Check it before you guess.

2One task, one session: /clear

/clear

Starts a new conversation with an empty window. Use it when a task is done and you switch to unrelated work: the old files and output only add cost and can mislead Claude. /new and /reset do the same. A roadmap file holds the plan between sessions, so starting fresh loses nothing.

Changed your mind? /resume brings back the old conversation. In the same Claude Code window, the rewind menu also shows it at the top of the list.

3Same task, later: /compact, and say what to keep

/compact keep the decisions, file paths and open to-dos

Replaces the conversation so far with a summary and keeps going. Use it when a task is still running but the session is long. Saying what to keep makes the summary keep the right things instead of guessing.

When the window fills up without you, Claude Code compacts for you. On this site that looked like this at the top of the next reply (27 Oct 2026):

This session is being continued from a previous conversation that ran out of context.
The summary below covers the earlier portion of the conversation.

That's the moment details get lost. Compacting yourself, earlier and with a focus, is better.

4Know what survives each one

After /clear After /compact
The chat so far Gone (until you /resume) Kept as a summary
Project CLAUDE.md Loaded again Loaded again from disk
Auto memory Loaded again Loaded again from disk
Your files on disk Untouched Untouched; up to five recent ones are re-read

The pattern: anything saved in a file survives. Anything that only lived in the chat may not. So when a rule matters, put it in CLAUDE.md instead of saying it once. This site's "stop every test server when you're done" rule started as a prompt I kept typing, and is now one line in the project's CLAUDE.md.

My routine when a job is done:

  1. Finish a task. Commit it.
  2. Ask Claude to write down what the next session needs. My real prompt from 26 Oct 2026: take note for anything that helps you to continue in new session.
  3. /clear, or close and run claude again.

The notes land in a file (here, the roadmap and Claude's memory files), so the next session starts small and still knows the plan.

5Keep CLAUDE.md short

CLAUDE.md is loaded at the start of every session, so every line costs tokens every time. Keep only what Claude can't work out for itself. See CLAUDE.md best practices. Long how-tos that are only sometimes needed belong in a skill instead, which loads only when used.

6Point at the exact files

Costs moreCosts less
Find where the footer is and add the version.Add the version to the footer in @src/app/app.html.

Typing @ and a path adds that file directly. Without it, Claude searches and reads several files to find the right one.

7Trim output before Claude sees it

Don't paste a whole log. Ask for, or paste, only the part that matters:

npm run build 2>&1 | tail -20
grep -n "ERROR" app.log | head -50

8Hand big reads to someone else

When a job means reading a lot (a whole folder, a long log, many search results), let something else read it and send back only the answer:

  • A subagent: ask Claude to "use a subagent to find where X is handled". It searches in its own separate context and returns a short report.
  • Gemini via MCP: Gemini reads the files on its own quota, and Claude only gets the summary. See the setup guide.

9Plan first, and match the model to the job

For bigger changes, switch to plan mode (press Shift+Tab until it shows) and agree on the plan before any code is written. Redoing work that went the wrong way is the most expensive kind of token use. For small, simple tasks, switch to a smaller, cheaper model with /model. More in which Claude Code model to use.

When to use which

  • New, unrelated task: /clear.
  • Same task, long session, Claude starting to slip: /compact with what to keep.
  • Only one part of the chat was noise (a long debugging detour): /rewind, pick the message, then "Summarize from here".
  • Not sure what's using the space: /context.

Don't over-save. Cutting context Claude actually needs leads to wrong answers and more back-and-forth, which costs more in the end. The aim is to keep out what's not needed.

claude-mem, ponytail and the rest of my setup are on my tools page, each with what to watch out for.

Next: how to write prompts for Claude Code, so fewer turns are needed in the first place. New here? Start with Claude Code for beginners.