Keep a session on track
Everything in a session — your prompts, Claude’s replies, every file it read — sits in a finite context window. Long sessions drift unless you steer. Five commands are the wheel and the pedals.
01The goal
See how full the context is, compact or clear it on purpose, rewind a wrong turn, and resume yesterday’s conversation — the five commands that keep long work coherent.
02The idea
The context window is large but not endless, and a long, wandering conversation leaves less room for the work that matters now. Five commands keep it in hand:
| Command | What it does |
|---|---|
| /context | Shows how full the window is, as a colored grid, broken down by category — messages, files read, memory files |
| /compact | Summarizes the conversation so far to free space — optionally with instructions: /compact keep what we learned about the parser |
| /clear | Starts a new conversation with empty context; the old one stays retrievable |
| /rewind | Steps back to an earlier prompt, restoring the code, the conversation, or both |
| /resume | Picks up an earlier conversation; claude --continue from the terminal reopens the most recent one |
Compact when you want to keep going on the same task; clear when you start a different one. That sentence is most of the judgment: compacting across a task boundary drags the previous task’s assumptions along, and clearing mid-task throws away state you will re-fetch at full price.
/rewind has one hard edge worth knowing on day one: it restores Claude’s file edits, not the side effects of commands it ran. If Claude deleted a file with rm, rewind will not bring it back — git will. This is the second argument for lesson 3’s commit discipline: a commit is an undo point that never depends on the tool’s own bookkeeping. We treat sessions as disposable and commits as durable. Steer the session, but keep the landing points frequent.
03The walkthrough
- 01Start a session and run /context. The grid shows the window by category. An empty-repo session is mostly air; that changes fast.
- 02Fill it a little: "Explain how the checker decides a link is broken." Then /context again — the messages band has grown. This is the gauge on your fuel tank.
- 03Compact with intent: /compact keep what we learned about the checker. The conversation is replaced by a summary, and /context shows the messages band shrink. On a five-minute session the win is small; on the ninety-minute session it is the difference between finishing and degrading.
- 04Make an edit to undo — and be precise about how: "In cli.js, change the success message to ‘All relative links are fine.’ Use your file editing tool, not a shell command." Approve it, and git status shows the file.
- 05Rewind: /rewind (or Esc Esc with an empty prompt), pick the prompt from the previous step, choose "Restore code and conversation". If the menu offers only conversation options, Claude used a command — choose Never mind, git restore <file>, and repeat the edit with the file-editing instruction.
- 06The restored prompt lands back in your input box. Press Esc twice quickly to clear it — a hint reads "Esc again to clear" after the first press. Then /clear: fresh conversation, the old one still retrievable.
- 07/exit, then from the terminal: claude --continue reopens the most recent conversation in this folder. If it opens the cleared one, /resume and pick the earlier one.
The conversation you resume may still show the edit you rewound — it was saved before the rewind, while your files are as the rewind left them. Sessions are records, not state; the repository is the state.
04Your turn
The same circuit in your repo: /context, one question, /context, /compact with a keep-instruction, one file-tool edit, rewind with code restore, Esc Esc, /clear, /exit, claude --continue. Twenty minutes, and the fourth line of the course’s exit checklist is yours.
Watch the two edges: rewind does not undo command side effects (rm, git itself, installs) — commit before you experiment; and don’t compact across a task change, because the summary will faithfully carry the wrong task’s context into the next one.
Compact or clear — which keeps going on the same task?
- A/clear
- B/compact
- CBoth equally
→Check your answer
Compact summarizes and continues; clear empties the context for a different task.
What does /rewind not restore?
- AThe conversation text
- BClaude’s file edits
- CA file Claude deleted with rm
- DYour earlier prompt
→Check your answer
Rewind restores Claude’s file-tool edits and the conversation — not the side effects of shell commands it ran. Git is the floor under rewind.
What does /context show you?
- AHow full the window is, by category
- BYour plan-mode history
- CThe account’s usage limits
→Check your answer
A colored grid of the context window: messages, files read, memory files. (Usage limits live in /usage.)