How to undo Claude Code's changes: /rewind explained

Claude Code saves a checkpoint of your files before every prompt. Press Esc twice or run /rewind to restore the code, the conversation or both, or to summarise part of the session. What a checkpoint does not cover (Bash commands, most subagent edits, your own edits), how long they last, and why git still matters. Checked against Claude Code 2.1.308.

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?

  1. Clear the prompt box and press Esc twice, or type /rewind and press Enter.
  2. The rewind menu lists the prompts you sent in this session. Choose the one you want to go back to.
  3. Choose what to restore:
OptionFilesConversation
Restore code and conversationBack to before that promptBack to before that prompt
Restore conversationUnchangedBack to before that prompt
Restore codeBack to before that promptUnchanged
Summarize from hereUnchangedEverything from here on becomes a summary
Summarize up to hereUnchangedEverything before here becomes a summary
Never mindUnchangedUnchanged

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?

ChangeRestored by /rewind?
Files Claude edited with its own edit and write toolsYes
Files changed by Bash commands (rm, mv, cp, a formatter, a script)No
Edits made by a subagentUsually not, except files Claude itself had already edited in your conversation
Your own edits in an editor, and other Claude Code sessionsNo
Symlinked and hard-linked filesNo; 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?

CommandWhat it does
/rewindGoes back to an earlier point in this session, for files, conversation or both
Summarize from here, in /rewindCompresses part of the conversation, like a targeted /compact
/branch or claude --continue --fork-sessionStarts 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.

The tool

Do it in your browser.

Claude Code

Config Studio for Claude Code

Every file Claude Code reads, explained: what each setting does, where it lives, which file wins, and an editor that writes it for you.

Keep reading

More from the blog.

Every post