Getting startedFirst stepsContext
Cleaning and compacting
When to clear versus compact a Claude Code session, how /compact preserves intent, and everyday habits that avoid context bloat.
Cleaning means removing noise from what you send or what sits in the thread. Compacting means summarizing conversation history into a shorter surrogate so you can continue the same task with room left in the window.
Clear vs compact
| Action | What it does | When to use it |
|---|---|---|
/clear (aliases may exist) | Wipes the conversation and starts fresh; project memory reloads, but chat context is gone | Switching to a different task or demo where old chat would confuse the model |
/compact | Replaces long history with a summary you can steer (“retain the API contract; drop debug steps”) | Same goal, long session, context meter high, but you still need continuity |
Rule of thumb: if you would not explain the prior hour to a new teammate, /clear. If you would hand off a short brief, /compact.
Official behavior and flags change by version, use /help for your build.
Cleaning habits (no slash command required)
- Remove stale
@attachments before sending when you pivot. Once a file reference has been sent, its content is part of conversation history until/compactsummarizes it or/clearstarts fresh; there is no general post-send removal operation. - Paste excerpts: not full CI logs, use
@terminalor tail the relevant lines. - Promote stable decisions to
CLAUDE.md,AGENTS.md, ordocs/*-plan.mdso you do not rely on chat archaeology. - End noisy tool chains: ask for a summary before chaining more reads.
Compacting with intent
Good /compact instructions name what must survive:
/compact Retain: error message, root cause hypothesis, files we already ruled out, and the agreed fix approach. Drop: intermediate grep noise and failed attempts.After compacting, spot-check: if something critical is missing, state it again in one line before the next edit.
Workshop moments
- Between landing page and capstone, a
/clearkeeps “Taskflow” copy from steering a different product. - During checkbox execution,
/compactbetween phases can preserve plan state indocs/...-plan.mdwhile shrinking chat—the file is the source of truth; chat is negotiable.
Example prompts
Start fresh:
/clear
New task: same repo, but we are done with the landing page. Open AGENTS.md and summarize run/test commands, then wait for my capstone choice.Stay on task, shrink history:
/compact Keep the snack-poll requirements and the current checkbox; drop earlier styling debates. Then implement only the next unchecked item in docs/snack-poll-plan.md.