You asked Claude Code for one small change. A few minutes later the login page is blank, a component you liked is gone, and the terminal shows edits to files you never mentioned. Claude Code has an undo feature built in, called checkpointing, and it can put tracked file edits back. It also has gaps, and knowing them decides whether you need git as well.
This guide is for you if you built an app with Claude Code and want it back the way it was. If you use Cursor or Windsurf instead, see Cursor or Windsurf agent broke your app? Undo it with git. Tool page: /fix/claude.
Stop prompting first
Don’t type “that broke everything, please fix it” yet. Claude Code saves a fresh checkpoint whenever a prompt begins a new turn, and every extra turn piles more edits on top of the broken state. The fewer extra turns there are, the easier it is to find the last point where the app worked.
If Claude is still working, interrupt it with Esc. Then write down, in plain words, what was working before and what broke. You’ll use that list to check the result after you undo.
Undo with /rewind
Before each new turn begins, Claude Code takes a snapshot of the files it is tracking. To go back to one of those snapshots:
- Clear the prompt box, then type
/rewindand pressEnter, or pressEsctwice while the prompt box is empty. If the box has text in it, the first doubleEsconly clears the text (you can get it back with theUpkey). - The menu shows every prompt from this session. Pick the last prompt sent before things went wrong. Restoring to a prompt puts the code back to how it was just before that prompt ran.
- Choose what to restore.
The restore choices, as listed in Anthropic’s checkpointing docs:
| Option | Your files | The chat |
|---|---|---|
| Restore code and conversation | Go back to that point | Goes back to that point |
| Restore conversation | Stay as they are now | Goes back to that point |
| Restore code | Go back to that point | Stays as it is now |
| Never mind | No change | No change |
For a broken app, Restore code and conversation is the cleanest choice: the files go back, and the conversation is reverted to that point, so the later prompts that led to the break are no longer in the chat. Pick Restore code if the conversation holds context you still need, such as an explanation of the bug you were chasing.
The menu also offers two summarize options. Those compress the chat to free up context space. They don’t change any files, so they won’t undo a broken app.
Checkpoints are saved with the session, so you can still use /rewind after closing Claude Code and resuming that session later.
What /rewind can’t undo
Checkpointing tracks edits that Claude makes with its own file editing tools. The docs list these gaps:
| What changed the file | Does /rewind put it back? |
|---|---|
| Claude’s file editing tools, in this session | Yes |
A shell command (for example rm, mv, a script or a code generator) on a file Claude had already edited in the session | Yes |
| A shell command on a file Claude never edited in the session | No. Use git |
| A subagent, on a file Claude hadn’t already edited in your conversation | No, except a skill forked to run in the foreground. Use git |
| You, in your editor, or another Claude Code session running at the same time | No, unless it touched a file this session also edited |
| A symlinked or hard-linked file | No. Claude Code skips it and warns Restored the code, but skipped N files |
| A checkpoint whose snapshots were deleted by the cleanup sweep | No. It fails with No files were restored |
Two of these cases need extra care in an app project:
- Deleted files. If Claude removed a file with a shell command such as
rm, and it had never edited that file in the session, rewinding won’t bring it back. - Database changes. Checkpoints cover files in your project folder, nothing else. A migration Claude ran against your live database, data it deleted, or a deploy it pushed is not a file in your project, so rewinding the code won’t undo it. For data, see AI agent deleted your database? How to recover it.
“Rewind not working” or “can’t rewind”
Match what you see to the cause:
The menu only offers Restore conversation and the summarize options. The two code options appear only when the selected checkpoint has tracked file changes to revert. If no file edits were captured after that point, go to the git section below.
A prompt shows “No code restore”. That label marks a message you sent mid-turn, while Claude was busy, and no checkpoint exists for it. Select the prompt that started that turn instead, then choose a code restore. This reverts every file edit Claude made during that turn, both before and after your message landed.
No files were restored. The error reference says this appears when, for each file in the checkpoint, the backup is missing or Claude Code couldn’t write to or delete the file. By default it clears out a session’s file snapshots roughly 30 days after that session last saved one, so an old session can still list checkpoints that no longer work. The cleanupPeriodDays setting changes how long that data is kept. It won’t bring back snapshots that are already gone.
Restored the code, but skipped N files. The error reference says Claude Code skips a path when it is a symlink, hard link or other non-regular file, when its directory changed since the checkpoint, or when its backup can’t be safely read. Files that pnpm hard-links into place, and config files that a dotfile manager links in, are examples of the first case. The skipped files keep their current contents. Edit them back by hand, or restore them with git. Turning on /debug before you restore writes the skipped paths to a debug log.
The rewound messages came back. Quit Claude Code straight after a rewind, before sending anything else, and the removed messages can show up again when you resume. Restored files aren’t affected. To remove the messages again, run /rewind, select the same prompt, choose Restore conversation, and send any prompt before quitting, since the rewound chat is only saved along with a new prompt.
“Can I undo a rewind?” The docs describe no redo for a code restore. If you might want the current state back, save it with git first (next section) and then rewind.
Recover the rest with git
Anthropic’s docs say checkpoints are for quick recovery inside a session and recommend git or another version control system for everything beyond that. If your project folder has a .git folder, these commands work in any terminal opened in the project folder. They are standard git, so the steps are the same no matter which tool made the edits.
See what changed
git status
git diff
git status lists changed, deleted and new files. git diff shows the exact lines that changed in files git already tracks. Read the list before undoing anything, so you know which files to keep.
Save the current state first
git stash push --include-untracked -m "before undoing Claude changes"
This puts every current change, including new files git doesn’t track yet, into a saved stash and returns your folder to the last commit. If you undo too much, git stash list shows the entry and git stash apply brings the changes back. A stash is a safety copy, so make one even when you’re sure.
Restore files from the last commit
If you’d rather pick individual files than stash everything, git restore puts a tracked file back to its state in the last commit:
git restore src/pages/Login.tsx
git restore .
The first line restores one file. The second restores every tracked file in the current folder and below. This throws away uncommitted edits to those files, so stash first if any of them matter.
git restore won’t remove new files that Claude created. git status lists them as untracked. Delete any you don’t need.
If Claude committed the bad changes
If Claude ran git commit as part of its work, the bad edits are in your history. git log --oneline shows recent commits. git revert <commit> adds a new commit that undoes one bad commit without deleting history. For commits that seem lost after a reset, and for finding the commit that broke the app with git bisect, the Cursor and Windsurf guide walks through git reflog and git bisect step by step. Those commands don’t depend on the editor.
Never committed? Try Local History
With no checkpoint and no git history, your editor may still have copies. VS Code keeps a Local History of files you saved in the editor, shown in the Timeline view of the Explorer, and each entry stores the whole file as it was when the entry was made. You can compare an entry with the current file and restore it. Entries come from saves made inside the editor, so edits Claude wrote from the terminal may not appear there.
Guardrails before the next session
- Commit before each session. Run
git add -A && git commit -m "checkpoint before Claude"before you start. Then any bad session can be undone in one step, whatever made the changes. - Use a branch for experiments.
git switch -c try-new-loginkeeps experiments away from the version you know works. - Add permission rules. Claude Code’s permissions docs describe allow, ask and deny rules, evaluated in that order: deny, then ask, then allow. An ask rule such as
Bash(git push *)makes Claude stop and ask before that command runs. The docs say a Bash rule matches the command text Claude writes and isn’t a security boundary around the program, so the same tool invoked in another form can still run. - Keep production credentials away from the agent. If your project folder holds keys for your live database or hosting account, Claude can use them to change things that no checkpoint or commit can bring back. Use a separate development database while you build.
- Raise the cleanup period if you resume old sessions. If you come back to sessions after weeks, a higher
cleanupPeriodDayskeeps their snapshots for longer. It also keeps session transcripts for longer, so weigh that before you change it.
Restored, but still broken?
Rewinding and git put files back. They don’t tell you which of the restored files still hold half of Claude’s earlier changes, or whether a database or deploy step changed alongside them. If you restore and the app still fails, compare git diff against your last commit that worked, and test the flows from the list you wrote at the start.
When the edits run through the whole codebase and rewind can’t reach them, a vetted senior engineer can untangle them and get you back to a working build. Fixed price, agreed upfront. For more on what to check before a Claude-built app goes live, see ChatGPT or Claude wrote your app? How to get it production-ready and Vibe coding cleanup.
FAQ
How do I undo the last change Claude Code made?
Run /rewind, or tap Esc twice with an empty prompt box. Pick the prompt you sent just before the change, then pick one of the two options that restore code.
Why didn’t /rewind restore a file Claude deleted with a shell command?
A file enters checkpoint tracking only after Claude edits it through its own edit tools during that session. A file touched only by a shell command was never tracked, so restore it from git.
Can I undo a rewind?
There’s no documented redo for a code restore. Stash or commit the current state before you rewind if you might want it back. Rewound chat messages can reappear if you quit before sending another prompt, but the restored files stay restored.
How long are Claude Code checkpoints kept?
Each session holds file snapshots for the 100 most recent checkpoints. By default, the cleanup sweep removes a session’s snapshots about 30 days after the session last saved one. The cleanupPeriodDays setting changes that period.
Do checkpoints replace git?
No. Anthropic’s docs describe checkpoints as quick recovery inside one session and point to git or another version control system for long-term history. Commit before each session so you have both.
Comments