How to undo what Claude Code changed: /rewind and git
Undo Claude Code's edits with /rewind, git restore and reflog. What checkpoints cover, what they miss (bash, subagents), and habits that make undo painless.
To undo what Claude Code just did, run /rewind (alias /undo), pick the message you want to go back to, and choose to restore the code, the conversation, or both. That covers edits made with Claude's own file tools. For anything else, such as files changed by shell commands, you need git. This page explains where each tool stops, so you know which to reach for.
#What are the three layers of undo?
| Layer | Undoes | Does not cover |
|---|---|---|
/rewind (checkpoints) | Claude's file edits in this session, and the conversation | Files only a bash command touched, other sessions, your manual edits |
| Git | Anything committed, stashed or tracked | Untracked files you never added (unless you stash them) |
| Your tool's own undo | Depends on the tool | Depends on the tool |
Use /rewind for "that last prompt went wrong". Use git for "the last hour went wrong", and commit before anything big so git has something to go back to.
#How do you rewind in Claude Code?
Two ways to open the menu: type /rewind (aliases /undo and /checkpoint), or press Esc twice with an empty prompt box. If the box has text, double Esc clears it instead, and the text goes to your history so Up brings it back.
The menu lists the prompts you sent. Select one, then choose:
- Restore code and conversation: both go back to that point.
- Restore conversation: the messages rewind, the files stay as they are.
- Restore code: the files rewind, the conversation stays.
- Summarize from here / Summarize up to here: compress part of the conversation to free context. It changes no files.
- Never mind: close the menu.
After a restore, the original prompt comes back into the input field so you can edit and resend it. That is the real use of rewind: "same request, better wording" without the debris of the failed attempt in your context. Checkpoints are saved with the conversation, so /rewind still works after you resume a session.
#What does a checkpoint not cover?
The docs list the limits, and they matter:
- Bash command changes. If Claude already edited a file with its edit tools,
/rewindalso undoes later bash changes to that file. A file that only a bash command changed (sed -i, a formatter,rm, a generator) is not tracked and stays as it is. - Subagents. A subagent's edits usually are not captured in your session's checkpoints, with one exception: a foreground skill that runs as a fork. A background
/code-review --fixis in the same boat. - External changes. Edits you make yourself, or that another Claude session makes, are normally not captured.
- Symlinks and hard links. Restore skips them and warns
Restored the code, but skipped N files. This bites with dotfile managers and pnpm. - Old checkpoints. Claude keeps file snapshots for the 100 most recent checkpoints of a session, and deletes a session's snapshots after about 30 days by default (
cleanupPeriodDaysin settings changes that). - Mid-turn messages. A message you typed while Claude was working can be marked "No code restore". Select the prompt that started the turn instead.
Checkpoints are session-level recovery, not version history. The docs say so in as many words.
#How do you undo with git?
When /rewind does not reach it, git does. The commands worth memorizing:
git status # what changed
git diff # how it changed
git restore path/to/file # discard unstaged changes to one file
git restore . # discard all unstaged changes (careful)
git stash -u # park everything, including untracked files
git clean -n # dry run: list untracked files that would go
git clean -fd # then actually delete them
If Claude already committed and you want that commit gone but the changes kept:
git reset --soft HEAD~1 # undo the commit, keep changes staged
And when something truly disappeared (a bad reset --hard, a deleted branch), git reflog lists where HEAD has been, and git switch -c rescue <hash> brings a state back. Git keeps those entries for weeks by default, so you can almost always get back.
git restore . and git clean -fd delete work without asking, and untracked files are not in git at all. Run the dry run first.
#How do you try something risky and keep an exit?
Make the exit before you need it:
- Commit first. A clean tree means
git restore .is a full reset. "Commit what we have" is a prompt worth saying before a large refactor. - Use a branch or a worktree.
git switch -c experimentcosts nothing. A worktree isolates the experiment completely, and removing it removes the work. - Plan first. In plan mode Claude proposes before it edits, so a bad idea costs a rejected plan instead of an undo.
- Branch the conversation.
/branchcopies the conversation so far and switches you into the copy, leaving the original intact, so you can explore another direction without losing the first. - Keep permission prompts on for destructive commands. See permission modes.
If you want it automatic, a PreToolUse hook can run a script of yours (a git stash create, say) before shell commands.
#What if the conversation is the problem, not the files?
Sometimes the code is fine and the session has gone sideways: it keeps repeating a wrong assumption, or its context is full of a dead end. Choose Restore conversation to rewind the messages and keep the code, or Summarize from here to compress the noisy part. /clear starts fresh and saves the old session for /resume. If the context is simply full, see Claude Code's context window.
#In Relais
Relais puts a ↺ icon on each of your messages: "Undo changes from here". It shows a confirmation, runs a dry run first, then calls Claude Code's own file-checkpoint rewind, so it has the same limits: files changed by bash commands are not covered. Claude learns about the undo with your next message. Relais also snapshots each file before a session first edits it, which is how the Changes tab marks a session's files with a dot, including files outside git. Discard there sends every version it replaces to the Trash. See features.