Get the free coreGet core

Claude Code undo: rewind, checkpoints and Git, explained

Updated 6 min readSection 04 / Incidents & recovery
SHORT ANSWER

For a Claude Code undo, type /rewind, or its alias /undo, to open the rewind menu. Pick what to restore: the code, the conversation, or both. Rewind covers the file edits Claude made with its own file editing tools. The table below shows what it misses, and Git is the way back for that.

Claude Code changed more than you asked for. Rewind is built in, and this page shows how to open it, what each choice does, and where it stops.

01Claude Code undo with /rewind and /undo

Claude Code automatically tracks Claude's file edits as you work. Each prompt you send that starts a turn creates a checkpoint, which is a saved point in the session that you can go back to. To undo edits, type this in your session:

/rewind

/undo is an alias for the same command. A shortcut also works: press Esc twice when the prompt input is empty. Both open the rewind menu, where you pick the point to go back to and then the kind of restore.

02The three rewind options

The menu offers three ways to go back. They differ in what they touch, so read the line before you press Enter.

OptionWhat it does
Restore code and conversationReverts both code and conversation to that point
Restore conversationRewinds to that message while keeping the current code
Restore codeReverts file changes while keeping the conversation

If Claude broke your files but the plan was fine, restore code. If the plan went wrong and you want to ask again, restore code and conversation. If the files are good and you only want to take back a message, restore the conversation. That last choice also answers the question of how to roll back a conversation without touching files. Checkpoints are saved with the conversation, so /rewind still works after you resume a session.

03What /rewind restores and what it misses

Rewind is not a full time machine. It works from the edits Claude Code itself saw.

What happenedDoes rewind bring it back?
Claude edited a file with its file editing toolsYes, Claude Code tracks those edits
A file was changed only by Bash commands (shell commands)No, it isn't tracked and stays as it is
You edited files yourself outside Claude Code, or another session didNormally not captured
A subagent (a helper Claude starts for a side task) edited filesClaude Code usually doesn't capture those edits
The checkpoint is older than the 100 most recent onesUsually not, file snapshots are kept for the 100 most recent checkpoints

The second row matters most. A delete or a bulk rename that Claude runs in the shell does not go through the file editing tools, so if Claude never edited those files with its tools, rewind will not return them. Claude Code deleted files walks through that case step by step. The Claude Code checkpoints page covers what is saved and for how long.

04Claude Code rollback changes with Git

For what rewind does not track, the docs point to version control, such as Git. Git is a separate record of your project, so it works even when Claude Code never saw the change.

Two words first. The working tree is the files in your project folder, as you see them. The index, also called the staging area, is the list of changes you have added for the next commit.

Warning: both commands below rewrite the file in your working tree, so edits you had not staged in that file are replaced. For one tracked file that was deleted, git restore <file> gets the file back from the index. To take a file as it was in an older commit, branch or tag, use git restore --source and name it, for example git restore --source master~2 Makefile.

The full set of cases, with which command to run for each, is on restore a deleted file in Git.

05When you need to go back to an earlier commit

If Claude Code made commits you want to drop, you are in git reset territory. Warning: git reset --hard overwrites all files and directories with the version from the commit you name, and may overwrite untracked files, meaning files Git has never tracked. Save where you are before you run it, as the next page explains in order: undo a Git reset.

In auto mode, Claude Code puts these commands behind a classifier, which is the check that screens each action. Anthropic's docs say it blocks git reset --hard and similar commands because it presumes they would discard uncommitted changes. The full list is on the auto mode page. Files that Git never tracked are a different problem, covered in restore untracked files.

06Does Git have your file?

Git can only give back what it tracked. A file that is not under version control is called untracked, and git restore has no copy to take it from, because it restores from the index, a commit, a branch or a tag. If you added the file or committed it before Claude touched it, Git has a copy. If Claude created it during the session and you never added it, the copy may exist only in a rewind checkpoint, and only if Claude wrote it with its file editing tools. For files that fit neither case, see restore untracked files.

07Before you press Enter on a restore

A restore overwrites. Restoring code reverts file changes to the chosen point, so work you did by hand after that point can be replaced along with Claude's edits. Your manual edits outside Claude Code are normally not captured by checkpoints, which means a restore has no copy of them to give back. If you have edits you want to keep, commit them first or copy those files somewhere else, then open the rewind menu.

08Which way back to pick

Choose by what changed, not by what feels closest. Work down this list and stop at the first line that fits.

  1. Claude edited files with its file tools and you want them back: open /rewind and restore code.
  2. Claude's plan went wrong and you want to ask again: restore code and conversation.
  3. Only a message was wrong: restore the conversation and keep your code.
  4. A shell command changed or removed files that Claude never edited with its file tools: use Git, as above.
  5. You or a second session edited files outside this one: rewind normally does not capture that, so use Git again.

If you are unsure, open the rewind menu and read the options before you confirm anything. If the change you care about came from a script or a subagent, expect to need Git.

09How long can you rewind?

Rewind has a limit in two directions. Claude Code keeps file snapshots for the 100 most recent checkpoints in a session. It also deletes a session's file snapshots in a retention sweep, by default about 30 days after the session last saved one. So an old session may not rewind at all. If a change matters, commit it.

Cursor has a similar feature with its own limits. It is covered on Cursor restore checkpoint.

10What to remember about Claude Code undo

For a quick Claude Code undo, open the menu with /rewind or /undo. Pick code, conversation or both. For everything rewind does not cover, commit before long sessions and use Git, with git restore for single files.

Rewind undoes edits after the fact. Undo works best when you know what changed; Artificial Immunity's free, open-source core watches Claude Code sessions and program starts on your Mac and reports what it finds, without stopping anything.

FAQ

How do I undo in Claude Code?

Run /rewind, or its alias /undo, to open the rewind menu. You can also press Esc twice when the prompt input is empty. Then pick what to restore: code, conversation or both.

Does Claude Code have a rewind feature?

Yes. Claude Code automatically tracks Claude's file edits as you work, and /rewind (or /undo) opens the menu to undo them.

How do I undo a message or roll back a conversation in Claude Code?

In the rewind menu choose the option that restores the conversation: it rewinds to that message while keeping your current code. To go back on both, choose code and conversation.

Does /rewind undo changes made by Bash commands?

Not when only Bash commands changed the file: such a file isn't tracked and stays as it is. To revert it, use version control such as Git.

Can I still rewind after I resume a session?

Yes. Claude Code saves checkpoints with the conversation, so /rewind works after you resume.

How do I roll back Claude Code changes with Git?

For one deleted file, git restore <file> brings it back from the index, the list of what Git has staged for the next commit. To take a file from an older commit, use git restore --source with that commit. The recipes are on the Git pages linked below.

Sources

  1. Claude Code docs, checkpointing
  2. Claude Code docs, permission modes
  3. Git documentation, git-restore
  4. Git documentation, git-reset
  5. Git documentation, git-checkout
  6. Artificial Immunity
Rewinding after a bad session? Artificial Immunity watches the Mac where your agents work.Get the free core