Esc-Esc, rewind, and what git still owns
Three edits into a session, Claude Code starts changing a file you never meant for it to touch. Your first instinct is to type three more corrections trying to talk it back into place. There was a faster way the whole time: undo it, and go back to before it wandered.
16 min · You'll know exactly what a session's undo can and can't save you fromYou'll learn the real undo built into every Claude Code session, exactly what it can and can't take back, and why git still matters even after you've learned to rewind.
Step 1 of 6: The idea
Step 1 of 6
The one idea this lesson is about, and why it matters.
Complete Run a first safe session first; this lesson is the safety net for when that first safe session drifts anyway.
Quick recall · Run a first safe session
Last lesson, you learned to isolate risky work in a separate worktree before it starts. From memory, what's the relationship between that habit and this lesson's rewind?
A worktree is prevention, set up before risky work starts, so your main project stays untouched no matter what happens. Rewind is the cure, used after something already went sideways, to get the current session back to a known-good point. You want both: isolate what you can ahead of time, and know how to undo what still goes wrong anyway.
A session going sideways is not an emergency. It is the single easiest thing in Claude Code to take back.
| Session rewind (Esc-Esc) | Git |
|---|---|
| Undoes | |
| Claude Code's own file edits, and the conversation | Any committed change, to any file, from any source |
| Lasts | |
| About 30 days | Permanently, across sessions and restarts |
| Cannot touch | |
| Shell-command changes, or edits from other programs | Anything you never committed |
| Use it for | |
| "That last stretch went wrong, take me back" | "I want to return to this exact state next month" |
Use both. Rewind is the cure for a session gone sideways; git is the memory that outlives the session.
The real mechanic: in the terminal, press Escape twice, with an empty prompt box, and Claude Code opens a rewind menu, a short list of earlier points in this session you can jump back to. Pressing Escape twice with something still typed instead just clears your draft, so the empty-box part matters. From that menu you can restore the conversation and the code together, the conversation alone, or the code alone, back to that point.
| Prompt box empty | Text still typed |
|---|---|
| Escape twice does | |
| Opens the rewind menu | Just clears your draft |
The box has to be empty first. Otherwise Escape twice only clears what you typed.
What it actually undoes, said plainly: rewind tracks edits Claude Code made through its own file-editing tool. It does not track changes from shell commands it ran (commands typed to the computer itself, like rm to delete a file or mv to move one), and it does not track edits any other program made to your files. If a step in your session ran a command that touched files directly, rewind may not be able to put those back.
This is not a small footnote, it is the one thing worth remembering before you trust it.
Session undo and git are two different safety nets, not one. Rewind lives inside a Claude Code session and is cleared out after about 30 days, though a session you come back to and resume can still rewind to its earlier points. Git, your project's own saved history, the record of every version you have chosen to keep, is your project's permanent history, the one that survives closing the terminal, restarting your computer, or coming back next week.
Committing just means telling git "save this version," a habit worth building even if Claude Code does it for you when you ask. Rewind is for "that last stretch went wrong, take me back." Git is for "I want to be able to return to this exact state a month from now."
Use rewind for the first, and keep committing to git for the second. Neither one replaces the other.
Set up git once, by asking. Paste this into Claude Code: Is this folder in git? If not, turn it into a git project, then save everything as the first commit with the message "first save". It tells you the answer and does the setup. To save again later, say: Commit my changes with a short message that says what changed. To check it worked, ask: Show me the last three commits.
Getting a deleted file back. Say: The file [name] was deleted. Restore it from the last saved commit, then show me that it is back. That works only if the file was saved in a commit before it was deleted.
If it was never committed, git has no copy, so it is gone. That is why you commit before risky work.
Rewind per surface. In the terminal, press Esc twice with an empty prompt box, or type /rewind (/undo does the same). Anthropic's docs describe both for Claude Code sessions in general, but they do not say where the desktop app or the web version shows the rewind menu.
So if you are in the desktop app, ask: Undo the last change you made, then show me the file so I can check it. To tell it worked, open the file yourself and look. The change should be gone. If it is not, restore the file from your last commit (see above).
To bring back an older session, type /resume in the terminal and pick it from the list.
Worked example. Three edits into a session, Claude Code starts refactoring a file you never asked it to touch.
Claude Code v0.0.0
Sonnet (200K context) · Claude Pro
~/project
Refactoring UserSettings.tsx to use the new hook pattern...
Rewind menu, your prompts this session: 3. Fix the settings toggle 2. Add a test for the toggle 1. Set up the project Pick a point, then choose: Restore code and conversation
Instead of arguing it back into place, you open the rewind menu (Escape twice in the terminal, or an ask to undo in the desktop app), see the point right before it wandered, and restore the conversation and code together. You are back to the known-good state, and you re-brief it with the boundary you forgot to name the first time.
Claude Code v0.0.0
Sonnet (200K context) · Claude Pro
~/project
Restored. UserSettings.tsx and the conversation are back to right before the refactor started.
It is also completely normal to just throw a session away. Many practitioners restart a good share of their sessions, not because something broke, but because starting clean was faster than untangling where it drifted. That is routine, not a sign you did something wrong.
Rewind is the undo for the session you are in right now. Git is the memory that outlives it. Know which one you need before you need it.
That is the idea. Next you watch it work.
Step 2 of 6
See one real prompt do one real job, then see which part of it made that work.
You type this
Claude Code just started refactoring a file that has nothing to do with what I asked. Undo the changes it made to that file since my last prompt, then show me the file so I can check the refactor is gone.
Claude Code does this
Claude Code goes next.
Step 3 of 6
Write one part of the prompt yourself, then compare with one good answer.
What actually gets that file back
Rewind only tracks edits made through Claude Code's own file-editing tool. A deleted-by-command file is a different kind of problem.
Your answer is saved with your progress, so leave out anything private.
Try it before you go on.
Getting it wrong first is what makes it stick.
Step 4 of 6
Do the task on your own work, in your own tool.
Think of one real Claude Code session that went sideways recently, even a small one. Write three lines: what went wrong, whether rewind alone would have fixed it or you needed git too, and one habit you'll change (committing more often, or reaching for rewind sooner) because of it.
Go do it for real.
Come back with a result.
Leave out anything private. This uses one of your Course Council messages.
Step 5 of 6
Fill in your own card, then save it to your workbook.
Your takeaway
Loading your card…
Save your card before you go on. It goes in your workbook.
Step 6 of 6
Say it from memory first, then check it.
Pulling this out of your own head now is the part that actually moves it into long-term memory. Re-reading only feels like it does.
From memory, name the keybinding that opens the rewind menu, and the one category of change it cannot undo.
Escape twice, with the prompt box empty. It cannot undo changes made by shell commands, like rm or mv, or by any program other than Claude Code's own file-editing tool. That gap is exactly why git still matters even after you've learned to rewind.
You can open the rewind menu and choose what to restore
Esc-Esc opens a real undo for this session's conversation and code. It cannot undo shell commands or other programs, and it clears out after about 30 days, so git still owns your permanent history.
You do not have to argue a session back on track. In the terminal, clear the prompt box, press Escape twice, and pick the point right before things went wrong. In the desktop app, ask Claude Code to undo its last change, then open the file to check. Either way going back is one step away, not a crisis.
That is the lesson. Mark it complete, and its question comes back to you in three days.