Beginner · Lesson 4 of 5 · about 20 minutes · Needs: Your first change, from request to commit · Verified against Claude Code v2.1.292 (stable) on 2026-10-15
By the end of this lesson you can keep a session on track: see how full its context is, clear or compact it, rewind a change, and resume an earlier conversation.
- Your copy of the practice template with no uncommitted changes, and Node.js LTS (a Codespace on your copy has it). To practice in one of your own repositories instead, keep the template copy as well: the check runs from it. Set up the repository's
.practice/folder as lesson 1 describes, if you haven't yet. Start that repository with no uncommitted changes too: commit them, or set them aside withgit stash push --include-untracked. - Usage: light.
Everything in a conversation, your prompts, Claude's replies and every file it read, sits in the session's context window. The window is large but not endless, and a long, wandering conversation leaves Claude less room for the work that matters now (Explore the context window). Five commands keep it in hand (Commands):
| Command | What it does |
|---|---|
/context |
Shows how full the context window is, as a colored grid |
/compact |
Summarizes the conversation so far, to free space |
/clear |
Starts a new conversation with empty context |
/rewind |
Goes back to an earlier prompt, restoring the code, the conversation or both |
/resume |
Picks up an earlier conversation |
Compact when you want to keep going on the same task; clear when you start a different one. Rewind when a change went the wrong way (Checkpointing).
-
Start
claudein your practice copy and type/context. The grid shows how much of the window is used, broken down by category, including your messages and any memory files, such asCLAUDE.md, that loaded (Explore the context window). Your practice copy has noCLAUDE.mdyet, so you may see no memory files; lesson 5 adds one. -
Fill it a little:
Explain how src/check-links.js decides that a link is broken.Run
/contextagain: the messages part has grown. -
Compact, telling Claude what to keep:
/compact keep what we learned about check-links.jsThe conversation is replaced by a summary: in
/contextthe messages part shrinks and free space grows. After one short question there is little to summarize, so the change is small; compacting pays off when a conversation gets long. -
Make a change to undo. Rewind can't undo changes Claude makes by running commands (see Watch out), so the prompt asks for its file editing tool. Approve the edit if Claude asks:
In src/cli.js, change the success message to "All relative links are fine." Use your file editing tool, not a shell command.In a second terminal in the same folder, save what git sees:
git status --porcelain > .practice/b-4-before-rewind.txtThe file lists
src/cli.js. -
Rewind. Type
/rewind, or pressEsctwice with an empty prompt. Pick the prompt from step 4 and choose Restore code and conversation. If the menu offers only Restore conversation, the summarize options and Never mind, Claude changed the file with a command, which rewind can't undo: choose Never mind, pressEscto close the menu (Interactive mode), rungit restore src/cli.jsin the second terminal, and repeat step 4.Once the code is restored, save what git sees in the second terminal:
git status --porcelain > .practice/b-4-after-rewind.txtThis file is empty: the edit is gone. If a diff panel is open beside the conversation, it may still show the edit: Claude Code refreshes the panel each time Claude edits a file or runs a shell command (Interactive mode). The empty file shows what git sees.
-
The rewind put your step 4 prompt back in the input box, so anything you type now is added to it. Press
Esctwice quickly to clear it. Then type/clear. The conversation starts over with empty context, and the old one stays available. -
Type
/exit, then reopen the most recent conversation in this folder (Manage sessions):claude --continue
If it opens the empty conversation from step 6, run
/resumeand pick the earlier one. Inside a session,/resumewith no argument opens a picker of earlier conversations. The conversation you pick may still show the edit you rewound, because it was saved before the rewind. Your files stay as the rewind left them (git status --porcelainprints nothing), so don't ask Claude to make the edit again. If Claude offers to redo the rewound edit, say no.
Repeat the example in your practice copy, or your own repository:
- Run
/context, ask one question about the code, and run/contextagain. - Run
/compactwith a sentence about what to keep. - Ask for a small edit to one file, ending the prompt with "Use your file editing tool, not a shell command.", and approve it if Claude asks. Save
git status --porcelain > .practice/b-4-before-rewind.txt. - Rewind that prompt with Restore code and conversation, and save
git status --porcelain > .practice/b-4-after-rewind.txt. - Press
Esctwice quickly to clear the restored prompt, then run/clear, then/exit, thenclaude --continue.
You are done when all of these are true:
-
.practice/b-4-before-rewind.txtlists the file Claude changed:cat .practice/b-4-before-rewind.txt. -
.practice/b-4-after-rewind.txtlists no files:cat .practice/b-4-after-rewind.txtprints nothing. - Self-check (not tested): you can say when you'd use
/compactand when/clear.
Run npm run check -- b-4 in your practice copy. In your own repository, run npm run check -- b-4 --dir <your repo> from your practice copy instead.
If the first file lists nothing, you saved it before the edit was made; make the edit again, save the file after it, then rewind again. If the second file still lists the file Claude changed, rewind that prompt with an option that restores code, then save the second file again. When the menu no longer lists that prompt (after Restore conversation) or offers no option that restores code (Claude used a command), run git restore <file> and repeat Your turn steps 3 and 4 instead. Files you changed before the lesson also stay listed, because rewind can't undo them: commit them or set them aside with git stash push --include-untracked, then save the second file again.
- Rewind undoes only the edits Claude made with its file editing tools. Changes made by commands it ran, such as deleting a file with
rm, stay (Checkpointing); commit your work so git can bring it back.
- Explore the context window: an interactive view of what fills a session.
- Session management and 1M context: when to compact, clear or start fresh.
Sources: Commands · Explore the context window · Checkpointing · Interactive mode · Manage sessions
← Your first change, from request to commit · Beginner index · Project memory with CLAUDE.md → · Topic: Memory and context · Stuck on this lesson?