Short answer: Press Esc twice with an empty prompt, or type /rewind. Pick the prompt you want to go back to, then Restore code to undo Claude's file edits since then, Restore conversation to take back the messages but keep the files, or Restore code and conversation for both. It undoes edits made by Claude's file tools only: changes made by Bash commands, such as rm or mv, stay.
Claude went in the wrong direction, three files are half rewritten, and you wish you had committed first. You often do not need to: Claude Code takes a snapshot of the files it edits before every prompt you send, and keeps the last 100 of them per session.
How do you undo what Claude just did?
- Clear the prompt box and press
Esctwice, or type/rewindand press Enter. - The rewind menu lists the prompts you sent in this session. Choose the one you want to go back to.
- Choose what to restore:
| Option | Files | Conversation |
|---|---|---|
| Restore code and conversation | Back to before that prompt | Back to before that prompt |
| Restore conversation | Unchanged | Back to before that prompt |
| Restore code | Back to before that prompt | Unchanged |
| Summarize from here | Unchanged | Everything from here on becomes a summary |
| Summarize up to here | Unchanged | Everything before here becomes a summary |
| Never mind | Unchanged | Unchanged |
After restoring the conversation, the prompt you picked is put back in the input box, so you can change it and send it again: the quickest way to try the same task with better instructions. If text is already in the prompt box, the first double Esc clears it instead (it stays in your input history; press Up to get it back).
Which option should you choose?
- Claude broke something and the conversation went wrong too: Restore code and conversation, then send a better prompt.
- The files are fine but the discussion went off track: Restore conversation; your files stay as they are.
- You want the code back but Claude should remember what it learned: Restore code. Claude still knows what it tried, so it can avoid it the second time.
- The session is long and the context is filling up: Summarize from here, after a long debugging detour, keeps your first instructions word for word and compresses the rest.
The two code options only appear when there are tracked file changes after that point to undo.
What does /rewind not undo?
| Change | Restored by /rewind? |
|---|---|
| Files Claude edited with its own edit and write tools | Yes |
Files changed by Bash commands (rm, mv, cp, a formatter, a script) | No |
| Edits made by a subagent | Usually not, except files Claude itself had already edited in your conversation |
| Your own edits in an editor, and other Claude Code sessions | No |
| Symlinked and hard-linked files | No; they are skipped with a warning |
The first two rows matter most. If Claude deleted or moved files with a shell command, or ran a code generator, /rewind cannot bring that back. That is what git is for: commit (or at least git stash) before you hand Claude a large task, and checkpoints become a convenience on top rather than your only way back.
How long do checkpoints last?
They are saved with the conversation, so /rewind still works after you leave and come back with claude --continue or claude --resume. Each session keeps snapshots for its 100 most recent checkpoints, and old sessions' snapshots are deleted by the regular cleanup, by default about 30 days after the session last saved one. The cleanupPeriodDays setting keeps them longer:
{
"cleanupPeriodDays": 90
}What is the difference between /rewind, /compact and forking?
| Command | What it does |
|---|---|
/rewind | Goes back to an earlier point in this session, for files, conversation or both |
Summarize from here, in /rewind | Compresses part of the conversation, like a targeted /compact |
/branch or claude --continue --fork-session | Starts a copy of the session to try another approach, leaving the original as it was |
Use rewinding to undo, forking to explore: with a fork, both attempts stay available to compare.
Where can you check this?
Can you set how long Claude Code keeps sessions?
Config Studio for Claude Code has cleanupPeriodDays with Claude Code's other settings, each explained, and writes the settings file for you, so your checkpoints and transcripts stay as long as you want them. Nothing changes on your computer until you run its install script yourself.

