GUIDESEPISODES
Claude Code cheat sheet: clean context, smarter Claude
Six hours into one chat, Claude still remembers the logo you argued about at lunch, and it just forgot your rule about keys. Its memory is full. Here is how to see what fills it, clear it, shrink it, and keep the rules that matter, in plain words, checked against Anthropic’s own docs.

01THE STORY
Six hours in, Claude’s memory is a storage unit
Why it mattersA full context window is a slower, pricier and more forgetful Claude.
You opened Claude Code at breakfast to tweak the logo. By lunch you were fixing login in the same chat. By dinner Claude kept bringing up the logo, ignored the rule you gave it about keys, and fixed the same bug three different wrong ways.

Open the full chapterIncludes a note
Nothing is broken. Claude’s memory is full of boxes you will never open again.
What “memory” means here
Claude Code’s context window holds your whole conversation: every message, every file Claude reads and every command output. In Anthropic’s words, “performance degrades as it fills”, and “Claude may start ‘forgetting’ earlier instructions or making more mistakes.”
So the job is a declutter. See what is in there and throw out what you don’t need. Shrink what you keep, and put the rules where they can’t get lost.
02TIP 1
Take inventory: /context shows what fills the unit
Why it mattersYou can’t clean a unit you haven’t looked inside.
Type /context. Claude Code draws a coloured grid of what is using the window right now, with suggestions for context-heavy tools, memory bloat and capacity warnings.

Open the full chapterIncludes code, a table, a note
/context a coloured grid of what fills Claude's memory right now,
with suggestions for what to trimWhat is already in there before you type
| Loaded at start | What it is |
|---|---|
| System prompt | Claude Code’s own instructions. You never see it. |
Your CLAUDE.md files | Project and personal instructions, loaded every session. |
| Auto memory | Claude’s own notes from past sessions: the first 200 lines or 25KB of MEMORY.md. |
| MCP tool names | Just the names by default. Full tool details load when a task needs them. |
| Skill descriptions | One line per skill. The full skill loads only when it is used. |
Then the conversation adds up. The docs are blunt about what costs the most: “File reads dominate context usage.” A specific prompt like “fix the bug in auth.ts” means Claude reads fewer files.
03TIP 2
Corrected twice? Stop arguing. Clear the unit
Why it mattersThree wrong fixes in the chat teach Claude three wrong fixes.
This is the tip people skip. Corrected Claude more than twice on the same issue? Then, in Anthropic’s words, “the context is cluttered with failed approaches.” Start over with a better first message, not a fourth correction.

Open the full chapterIncludes code, a note
/rename login-fix-try-1 name this session so you can find it again
/clear start a new conversation with empty context
/resume login-fix-try-1 bring the old session back later/clear also answers to /new and /reset. It keeps your project memory (CLAUDE.md); only the conversation goes.
Write the one better first message
Put in what you learned from the failed tries. Name the place to look, what “fixed” looks like, and what not to touch.
fix the login bugClaude has to guess where, what and when to stop.
Users get logged out when their session times out.
Look at src/auth/, especially the token refresh.
Fixed means: a test that reproduces it fails first, then passes.
Don't touch the signup page or the database schema.Where to look, what done means, what to leave alone.
04TIP 3
Can’t start over? Compact, and say what to keep
Why it mattersA summary you steer keeps the login fix. One you don’t might keep the logo.
Sometimes you are deep in one problem and the history is worth keeping. Then shrink it on purpose. /compact replaces the conversation with a summary. Add what matters, or the automatic pass decides for you.

Open the full chapterIncludes code, a table, a note
/compact focus on the login fix and the files we changed
/rewind (or Esc twice on an empty prompt)
pick a message → Summarize from hereThe docs: with a focus, “the summary keeps what you choose instead of what the automatic pass guesses is important.”
Shrink only part of the chat
Press Esc twice on an empty prompt (or type /rewind) and pick one of your earlier messages. Then choose an action.
| Option | What it does |
|---|---|
| Restore code and conversation | Both go back to that point. |
| Restore conversation | The chat goes back; your code stays as it is. |
| Restore code | File changes go back; the chat stays. |
| Summarize from here | Squashes everything after that message into a summary. |
| Summarize up to here | Squashes everything before it; recent messages stay in full. |
To steer a summary, highlight a Summarize option and type your instructions where the row says add context (optional). Summarizing doesn’t change any file on disk.
05TIP 4
Rules you typed in chat get lost. Put them in CLAUDE.md
Why it mattersClaude forgets your chat. It re-reads a file every time.
Here is the trap behind “it forgot my rule”. When a chat is compacted, a rule you only typed in the conversation is summarized with everything else. The memory docs say it directly: if an instruction disappeared after compaction, “it was given only in conversation”.

Open the full chapterIncludes a table, code, a note
What survives a compaction
| Where the instruction lives | After compaction |
|---|---|
| Typed in the chat | Summarized with the rest. Can be lost. |
Project-root CLAUDE.md | Re-read from disk and put back. |
| Auto memory | Re-read from disk and put back. |
CLAUDE.md in a subfolder, path-scoped rules | Load again when Claude touches a matching file. |
| Files Claude read or edited | Up to five of the most recently changed are re-read. |
# Commands
- npm run dev: start the app
- npm test: run the tests before you say you're done
# Rules
- Secrets live in .env files. Never read them, never paste a key into code, never commit a .env file.
# Compact instructions
When you compact, keep the list of files we changed and the test commands.Short is the point. The # Compact instructions heading is the docs’ own trick for telling every compaction what to keep.
- No file yet? Type
/init. Claude reads your codebase and writes a starterCLAUDE.md. If one exists, it suggests improvements instead of overwriting it. - Keep it under 200 lines. The docs: longer files “consume more context and reduce adherence.”
- Check it loaded: run
/contextand look under Memory files. - Already have an
AGENTS.mdfor other tools? Recent versions of Claude Code read it when there is noCLAUDE.md. To use both, startCLAUDE.mdwith the line@AGENTS.md.
06TIP 5
Padlock the .env: a deny rule Claude can’t talk its way past
Why it mattersA polite instruction can be summarized away. A deny rule can’t.
A key Claude never reads can’t end up pasted into code, a commit or a log. Tell Claude Code which files it may never open. Type /permissions and add deny rules, or put them in .claude/settings.json so your whole team gets them:

Open the full chapterIncludes code, a note
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
]
}
}Read(./.env) is the docs’ own example. A bare Read(.env) (or Read(**/.env)) matches a .env in any folder of the project.
Why a rule beats a request
- Deny wins. Rules are checked in order: deny, then ask, then allow. An allow rule can’t carve an exception out of a deny.
- Every mode. The docs: “Deny rules block in every mode, including
bypassPermissions.” That matters. By default, auto mode allows “Reading.envand sending credentials to their matching API”. - Reading includes editing. A
Readdeny rule also stops Claude’s Edit and Write tools on the same path.
Then make sure the file never reaches git:
.env
.env.*
!.env.exampleThe last line keeps a .env.example with fake values in the repo. If a real .env is already tracked, git rm --cached .env stops tracking it without deleting your copy; then rotate any key that was in it.
07THE SHELF
The rest of the cheat sheet: cost, effort and handovers
Why it mattersOld context isn’t free. You pay to resend it with every message.
A few more habits keep long sessions cheaper and calmer.
Open the full chapterIncludes a table, code
| Type this | When |
|---|---|
/usage | See where your usage goes. On paid plans it flags habits like long context or cache misses. |
/btw <question> | A side question whose answer never enters the conversation. |
/effort | Turn reasoning down (low) for small edits, up for tricky bugs. Thinking is billed as output. |
/init | A starter CLAUDE.md from your codebase. |
| “use a subagent to investigate X” | The file reads happen in the subagent’s own window; only its summary comes back. |
/autocompact 500k | Compact earlier than the default (newer versions). |
Why a chat left open all day costs more
Claude Code sends your full conversation with every request and leans on a cache to make that cheap. The cache lifetime is an hour on a subscription and five minutes by default on an API key. Your first message after a longer break reprocesses everything. On Pro and Max, Claude Code offers to resume a big session from a summary instead.
Hand over, then start fresh
Finished a task, or stuck in a loop? Ask for a handover note, clear, and start the next task from the note. It works in any agent.
Write a handover note: what we built, what is left, which files matter
and how to run the tests. Save it as HANDOVER.md.
# then, in a fresh session:
Read HANDOVER.md, then do this next task: ...Anthropic’s guide does the same with specs: write the plan to a file, then “start a fresh session to execute it.”
08THE REVEAL
The after shot: a five-step routine
Why it mattersFive habits, about a minute a task. That is the whole declutter.
Every new task, every time:

Open the full chapterIncludes steps, a note
- One task, one session.
/renameit,/clearwhen you switch to something else. - Look with
/contextwhen Claude feels slow or forgetful. - Two strikes, start over.
/clear, then one better first message. - Long but valuable?
/compactand name what to keep. - Rules live on disk: habits in
CLAUDE.md, hard limits inpermissions.deny.
Copy the prompt at the top of this page into Claude Code once. It writes your CLAUDE.md rule, adds the .env deny rules and checks your .gitignore, showing you each change first.
THE QUICK READ
What to take away.
In one minute.
- 01
Claude’s memory is its context window: every message, every file it read, every command output. The docs say performance drops as it fills, and Claude may start forgetting earlier instructions.
- 02
/contextshows what fills it as a coloured grid, with suggestions. A lot loads before you type: the system prompt, yourCLAUDE.md, memory, MCP tool names and skill descriptions. - 03
Corrected Claude more than twice on the same thing? The docs’ advice:
/clearand start fresh with a more specific prompt./renamethe session first so/resumecan bring it back. - 04
Can’t start over?
/compactplus what to keep. Or press Esc twice, pick a message and choose Summarize from here. - 05
A rule you only typed in chat can be lost in a summary. The project-root
CLAUDE.mdis re-read from disk after compaction. Keep it under 200 lines. - 06
Instructions shape what Claude tries; permission rules decide what it can do. A deny rule like
Read(./.env)blocks in every mode. A.claudeignorefile has no effect.
THE TAKEAWAY, IN ONE PASTE
Paste this once. Keep a clean memory.
Paste this into Claude Code. It writes to two files, CLAUDE.md and .claude/settings.json, and shows you each change before it saves. It never deletes a file and it won’t open your .env.
Clean up how you work in this project so you keep a clear memory and never read my secrets. Do these in order and show me each change before you save it: 1. Create or update CLAUDE.md (keep it under 200 lines): the build and test commands, my code conventions, and this rule word for word: "Secrets live in .env files. Never read them, never paste a key into code, never commit a .env file." 2. In .claude/settings.json, add these to permissions.deny (keep anything already there): "Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)". 3. Check .gitignore lists .env and .env.* . If a .env file is already tracked in git, tell me; do not delete it. 4. Finish with three short lines I can keep: when to type /context, when to type /compact plus what to keep, and when to type /clear and start over with one better message.
Paste it into the agent you already build with
- Claude
- ChatGPT
- Gemini
- Cursor
- Copilot
QUESTIONS PEOPLE ASK
Good questions.
Short answers.
What does /context show in Claude Code?
A coloured grid of what is using the context window right now, by category, with suggestions for context-heavy tools, memory bloat and capacity warnings. It also shows which CLAUDE.md and memory files loaded. Run it when Claude feels slow or forgetful.
When should I use /clear instead of /compact?
Use /clear when you switch to unrelated work, or after you have corrected Claude more than twice on the same thing. Use /compact with a focus when you are deep in one problem and the history still matters. /clear costs nothing. Compacting a large chat is itself a large request.
Will I lose my old conversation if I type /clear?
No. Name it first with /rename, then bring it back with /resume and its name. /clear also keeps your project memory, including CLAUDE.md.
Why did Claude forget a rule I gave it earlier?
Probably because the rule lived only in the chat. When a conversation is compacted, chat messages are summarized and details can drop out. The project-root CLAUDE.md is re-read from disk after compaction, so put rules there.
How long should CLAUDE.md be?
Under 200 lines, per Anthropic’s docs: longer files use more context and reduce adherence. Keep build and test commands, conventions and “always / never” rules. Type /init to generate a starter file.
How do I stop Claude Code from reading my .env file?
Add deny rules: type /permissions, or put "Read(./.env)", "Read(./.env.*)" and "Read(./secrets/**)" under permissions.deny in .claude/settings.json. Deny rules block in every permission mode. A .claudeignore file has no effect.
Does a deny rule stop every way of reading the file?
No. It covers Claude’s file tools, shell commands Claude Code recognizes like cat and head, and redirects. A script that opens files itself, or grep -r across a folder, isn’t covered. For an OS-level wall, turn on /sandbox.
Does Aster check any of this?
No. Context, compaction and permission settings live in Claude Code on your machine, and Aster’s audit doesn’t look at them. Aster reads your repository: it does flag leaked keys and committed .env files, which is exactly what tip 5 helps you avoid.
See what fills the unit, clear it when you switch tasks, compact with a focus, keep your rules on disk and padlock the .env. Shipping faster still needs a check before launch, and your first Aster repository audit is free.Source notebook8 links
- Claude Code Docs: Best practices (course-correct early, manage context, failure patterns)
- Claude Code Docs: Explore the context window (what loads, what survives compaction)
- Claude Code Docs: Commands (/context, /clear, /compact, /rename, /resume, /btw)
- Claude Code Docs: Manage costs (/usage, why usage climbs in a long session)
- Claude Code Docs: Checkpointing (rewind, Summarize from here)
- Claude Code Docs: How Claude remembers your project (CLAUDE.md, /init, under 200 lines)
- Claude Code Docs: Configure permissions (deny rules, Read(./.env), what they cover)
- Claude Code Docs: Choose a permission mode (deny rules block in every mode)






