A coding agent fills its context window fast, and quality drops long before the window is full. These habits keep a session lean. Most of them also keep the prompt cache warm, which makes turns faster and cheaper.
When to use it
All the time, but especially when a session feels slower or “dumber” than at the start, when the agent forgets something you agreed on, or before you start a big task in a session that has already done a lot.
How to do it
- Look before you guess. Run
/contextto see what is using space, by category, with suggestions. To keep the number on screen all the time, set up a status line with the context percentage. - Clear between unrelated tasks.
/clearstarts a new conversation with empty context. A backend bug and a form layout are two sessions, not one. See One task per session. - Compact on purpose, at a break.
/compact focus on the auth bugsummarizes the conversation and keeps what you name. Do it between tasks instead of waiting for auto-compaction to hit mid-task. Compaction rewrites history, so it also costs one cache rebuild. - Rewind instead of arguing. If the agent went the wrong way,
/rewind(orEsctwice) goes back to an earlier point in the conversation and/or code. That beats half a session of “no, do it differently”, and it reuses the cache. - Write specific prompts. “Fix the null check in
src/auth.ts” makes the agent read one file; “find where we handle auth” makes it read ten. - Keep lasting rules in CLAUDE.md. After compaction, the project-root CLAUDE.md is re-injected from disk, while rules you typed in chat may be summarized away. Remember that edits to CLAUDE.md apply only after
/clear,/compactor a restart. - Hand big research to a subagent. A subagent reads files in its own context window and sends back only a summary, so the reads never land in yours: “use a subagent to find every place we call
refreshToken()”. - Pick the model at the start. Switching models with
/modelmid-session throws away the cache.
Example
A session that fixed a login bug is now 60% full. You want to add a settings page next.
/context # mostly file reads from the login fix
/clear # new task, new context
Add a "notifications" toggle to src/pages/Settings.tsx, following the
pattern of the existing "dark mode" toggle in the same file. Run npm test.If instead you want to continue on the login code with less noise:
/compact keep the final fix in src/auth.ts and the failing test name, drop the logsCommon mistakes
- Waiting for auto-compaction. It fires when the window is nearly full, often mid-task, and you do not choose what it keeps.
- Correcting over and over in the same session instead of rewinding or starting fresh with a better prompt.
- Vague exploration prompts that make the agent read half the repo.
- Editing CLAUDE.md and expecting the running session to see it.
Related
- Context window: what fills the window and what survives compaction.
- Prompt caching: why some of these habits also save money.
- One task per session: the session-level rule behind step 2.
- Statusline: context percentage always on screen.