How to undo Claude Code changes with /rewind and git
Undo Claude Code changes with /rewind or Esc twice, and git for the rest. What checkpoints track, the four restore options and the git commands to use.
Contents
To undo Claude Code changes, press Esc twice with an empty prompt, or run /rewind. Pick the prompt you want to go back to and choose Restore code, Restore conversation, or both. That covers edits Claude made with its file tools. Changes made by shell commands, by you, or by another session need git.
How Claude Code checkpoints work#
Claude Code takes a checkpoint every time you send a prompt that starts a turn: it "automatically captures the state of your code before each prompt" (Claude Code docs: Checkpointing). A few details from the same page:
- It keeps file snapshots for the 100 most recent checkpoints in a session.
- Checkpoints are saved with the conversation, so
/rewindstill works after you close the terminal and resume the session. - Snapshots are deleted in the retention sweep, by default about 30 days after the session last saved one. Change that with
cleanupPeriodDays.
The rewind options#
Run /rewind (or Esc Esc on an empty prompt). The menu lists the prompts you sent. Pick one, then an action:
| Option | Your files | The conversation |
|---|---|---|
| Restore code and conversation | Back to that point | Back to that point |
| Restore conversation | Left as they are | Back to that point |
| Restore code | Back to that point | Kept |
| Summarize from here | Left as they are | Later messages squeezed into a summary |
| Summarize up to here | Left as they are | Earlier messages squeezed into a summary |
| Never mind | Nothing changes | Nothing changes |
The two code options only show up when there are tracked file changes after that point. After restoring the conversation, your old prompt comes back into the input box, so you can edit it and send it again.
Which one to pick:
- Claude went the wrong way: Restore code and conversation, then send a better prompt.
- The code is fine, the chat is cluttered: Restore conversation, or one of the summarize options.
- You want to try another approach but keep the discussion: Restore code.
What /rewind can't undo#
Anthropic lists the gaps plainly:
- Bash commands. "Checkpointing does not track files modified by Bash commands." An
rm,mvorcpcan't be rewound. - Changes from outside. Your own edits in an editor, and edits from other concurrent sessions, are normally not captured.
- Most subagent edits. A subagent's edits to files Claude hadn't already edited in your conversation stay put; the docs say to use git for those.
- Symlinked and hard-linked files are skipped, with a "Restored the code, but skipped N files" warning.
- Expired snapshots. Past the retention period a rewind can fail with "No files were restored".
And the line that matters most: checkpoints are "designed for quick, session-level recovery. For permanent version history and collaboration, continue using version control" (Checkpointing). Anthropic's best-practice page says it more bluntly: "This isn't a replacement for git" (Best practices).
How to undo Claude Code changes with git#
Git sees every change in the folder, whoever made it. Start every task from a clean, committed state, and these commands cover what /rewind can't:
- See what changed:
git statusandgit diff. - Throw away changes to one file:
git restore path/to/file. - Throw away every uncommitted change to tracked files:
git restore . - Remove new files the agent created:
git clean -nto preview, thengit clean -f(add-dfor folders). This deletes for good. - Keep the changes aside instead:
git stash, andgit stash popto bring them back. - Undo a commit that's already in:
git revert <commit>, which adds a new commit that reverses it.
Commit before you hand over a task. Then "undo everything since" is one command, and nothing depends on a 30-day snapshot. Give each task its own branch, better still its own worktree. Throwing the attempt away is then deleting a branch, and your main branch never saw it. Claude Code's claude --worktree <name> does this for you. We wrote up the full routine in a git workflow for Claude Code that keeps main clean.
How Shuriken makes it one action#
In Shuriken, every new chat starts on its own branch in its own git worktree (parallel agents, and why we made it the default in a worktree per chat). The one exception is each project's Main chat, which works on your own branch for quick changes, so commit before you hand it anything big.
So undoing a whole attempt is one action: archive the chat. If its branch still holds uncommitted changes or unpushed commits, Shuriken tells you how many lines and commits first. Then it removes the chat's worktree and leaves the branch alone, and your main branch never saw any of it. Keep the work instead, and Finish merges it.
If you'd like every attempt on its own branch without typing git worktree again, download Shuriken.
Sources
- Claude Code docs: Checkpointing (accessed 22 October 2026)
- Claude Code docs: Best practices (accessed 22 October 2026)
- Claude Code docs: Explore the .claude directory (accessed 22 October 2026)
- Git documentation: git-restore (accessed 22 October 2026)
Frequently asked questions
How do I undo the last change Claude Code made?
Press Esc twice with an empty prompt, or run /rewind, pick the prompt before the change, and choose Restore code. That reverts the edits Claude made with its file tools since that prompt.
Does /rewind undo files changed by bash commands?
No. Anthropic's docs say checkpoints don't track files changed by Bash commands such as rm, mv or cp. Use git to get those back.
Can I rewind after closing Claude Code?
Yes. Checkpoints are saved with the conversation, so /rewind works after you resume the session. Snapshots are deleted after about 30 days by default.
Do checkpoints replace git?
No. Anthropic calls them quick, session-level recovery and says to keep using version control for permanent history. Commit work you want to keep.
What is the difference between Restore code and Restore conversation?
Restore code puts your files back and keeps the chat. Restore conversation takes the chat back to that prompt and leaves your files as they are. Restore code and conversation does both.