How to Undo in Claude Code (The Complete Guide)
Need to undo something in Claude Code? Here's the full ladder: the fast undo for Claude's edits, what it can't reach, and exactly how to undo a deleted file, a terminal command, or a bad commit.
You changed something in Claude Code and you want it back. The fastest undo is /rewind: press Esc twice, and Claude reverses its own recent edits in the current session. That covers most everyday "put that back" moments. But "undo" in Claude Code is not one button, it's a ladder, because a deleted file, a terminal command, and a bad commit each need a different rescue. This guide gives you the right move for each, starting with the easiest.
The fast undo: /rewind (Esc Esc)
/rewind is Claude Code's built-in undo for the edits Claude makes directly to your files. You ask it to rewrite a function or a paragraph, you don't like the result, you press Esc twice, pick a checkpoint, and the old version comes back. The official checkpointing docs describe exactly this: Claude saves a checkpoint before each change so you can step back through them.
For its actual job, it's great. Reach for it first. The trap is assuming it undoes anything, and it doesn't.
What /rewind can't undo
There are three blind spots, and most of the time the thing you're trying to undo lives in one of them:
- Terminal commands. Claude doesn't only edit files, it also runs shell commands like
rm(remove),mv(move), andcp(copy or overwrite). Rewind never tracks those, so anrm -rfis invisible to it. - Untracked files. Your
.env(the file holding your secret keys), a local database, or a file you created five minutes ago often sit outside every net, rewind included. - Other sessions. Rewind only reaches back through the session you're in. Cross a session boundary and it can't see it.
If you already pressed Esc twice and your file didn't come back, you're not doing it wrong, you hit one of these. The full breakdown is here: Does Claude Code's /rewind Undo Deleted Files?
The full undo ladder, by what you're trying to undo
Find your situation and work the steps in order. Stop the moment your work reappears.
You want to undo Claude's last edit
Press Esc twice for /rewind, pick the checkpoint from before the change, and confirm. Done. This is the one case rewind owns.
You want to undo a deleted or overwritten file
Rewind is out, so work this list:
- Trash / Recycle Bin. The most common save. If the file was moved rather than wiped, it's right there. Right-click, Put Back (Mac) or Restore (Windows).
- Backup or cloud version history. Time Machine, iCloud, Dropbox, Google Drive, OneDrive, and Windows File History all quietly keep older versions. Roll back to one from before the loss.
- Git history. If the project is a git repo and you committed recently, the file is recoverable. Just ask Claude: "Is this a git repo? Show recent commits and help me restore the file that was just deleted, explaining each step first."
- File-recovery software, last resort. Tools like Disk Drill or Recuva scan the drive. The sooner the better, and an overwritten file (not just deleted) is often already gone.
The full platform-by-platform walkthrough is here: Claude Code Deleted My Files? How to Recover Them.
You want to undo a terminal command (rm, mv)
Same list as above, because once the filesystem changed there's nothing for rewind to read. The one extra tip: avoid creating new files in that folder until you've recovered, because new data can overwrite the disk space the deleted file used.
You want to undo a git commit or a bad merge
Don't fight git by hand. Ask Claude: "Show me the recent commits and help me safely undo the last one, explaining each command before you run it." Git is built to reverse changes without losing your history, and Claude will pick the right move (a revert, a reset, or restoring a single file) for your case.
How to stop needing the hard undos
The everyday undo (rewind) you already have. The painful undos (deletes, terminal commands, untracked files) you can make almost impossible to need, with a setup you do once. Easiest first:
- Keep your project in a backup-synced folder. Dropbox, Google Drive, OneDrive, iCloud, or Time Machine on its location. Now every change keeps a recoverable history automatically.
- Ask Claude for a git checkpoint before big tasks. You never touch a git command. Just say: "Set up git if needed and commit a checkpoint now, so I have a safe point to return to." Do it before anything risky ("clean this up," "fix the build," "reorganize these files").
- Add a net for the files git and rewind skip. This is the real gap: your
.env, a local database, a brand-new file. Undeletable saves a byte-for-byte copy of a file before Claude touches it, whether Claude edits it directly or deletes it from the terminal. If something goes wrong you type/restore. It runs locally (no account, no cloud), it's a one-time $19, and it only protects from the moment you install it, so the time to add it is before you need it.
The complete prevention setup is spelled out here: How to Set Up Claude Code So It Can't Delete Your Work.
Undo isn't one button, so build the net once
Use /rewind for Claude's edits and you've got the everyday case covered. For everything it can't reach, the answer is a few minutes of setup, not a frantic recovery later.
Start with the free Claude Code Safety Checklist. It's the calm, plain-English, do-this-then-this version of the setup above, and we'll email it to you so it's on hand the next time something goes sideways. When you want the always-on net for the files rewind misses, Undeletable is $19, one time, and lives quietly on your machine.
Related reading: Does Claude Code's /rewind Undo Deleted Files? · Claude Code Deleted My Files? How to Recover Them · How to Set Up Claude Code So It Can't Delete Your Work · The free Claude Code Safety Checklist
Frequently asked questions
- How do I undo the last thing Claude Code did?
- Press Esc twice to open /rewind. It undoes Claude's own recent Write and Edit changes inside the current session, which covers most "I don't like that change, put it back" moments. It does not undo terminal commands like rm or mv, and it does not reach files it never tracked, such as your .env. For those you use the Trash, a backup, or git instead.
- Can I undo a file that Claude Code deleted?
- Not with /rewind. A deleted file usually comes back from somewhere else: the Trash or Recycle Bin first, then a backup or cloud version history (Time Machine, iCloud, Dropbox, OneDrive), then your git history if you committed it. If the file was git-ignored or never saved anywhere, there may be no copy to restore, which is the gap a snapshot tool closes.
- How do I undo an rm command Claude ran in the terminal?
- /rewind never tracks terminal commands, so it can't help here. Check the Trash or Recycle Bin, then your backup or cloud version history, then git. Stop the moment the files reappear. The sooner you look, the better the odds, especially before you create new files that could overwrite the old space on disk.
- How do I undo a git commit Claude made?
- Ask Claude in plain English: "Show me the recent commits and help me undo the last one safely, explaining each step before you run it." Git has built-in ways to reverse a commit without losing history, and Claude can walk you through the right one for your situation.
- Is there a single undo button that covers everything?
- No. Claude Code has /rewind for its own edits, but deletes, terminal commands, and untracked files each need a different net. That's why the reliable answer is layering: keep your project in a backup-synced folder, ask Claude to make git checkpoints, and add a snapshot tool for the files git and /rewind skip.
Never lose your work to Claude Code.
Drop your email. The free Claude Code Safety Checklist lands in your inbox. The 2-minute setup that stops almost every “Claude deleted my work” story.
free · one email · the checklist · unsubscribe anytime