Sometimes the assistant changes a file in a way you did not want. Each tool has its own way back. This guide shows the undo option in Claude Code, Gemini CLI and Codex CLI, and what each one cannot undo.
In Claude Code and in Gemini CLI, the same shortcut opens the undo menu: press Esc twice when the message box is empty.
The undo features are for quick fixes during a session. They are not long-term backups. For work that matters, also keep a Git history (step 7). Git is a program that saves versions of the files in a folder.
1. Claude Code: open the rewind menu
Claude Code saves a checkpoint (a saved copy of your files) automatically before each prompt that starts a turn. A turn is one round of work: you send a message and Claude works until it stops. Claude Code keeps the saved files for the 100 most recent checkpoints in a session.
To go back, type this inside the session:
/rewindYou can also press Esc twice when the message box is empty.
2. Claude Code: pick a point and an action
The menu lists the prompts you sent. Pick the one you want to go back to. Then choose an action:
- Restore code and conversation: undo the file changes and the chat after that point.
- Restore conversation: go back in the chat, but keep the files as they are now.
- Restore code: undo the file changes, but keep the chat.
- Never mind: go back to the list without changes.
The two "Restore code" options appear only when Claude edited files after that point.
A message that you typed while Claude was still working can show No code restore. That message has no checkpoint of its own. Pick the prompt that started the turn instead.
3. Claude Code: know what rewind cannot undo
Rewind only undoes edits that Claude made with its own file tools. It does not undo:
- files changed by terminal commands that Claude ran, for example to delete, move or copy files. This includes
sed -i, a command that changes text inside a file. Since Claude Code 2.1.309, Claude runs it as a normal terminal command; - most edits made by subagents (helpers that Claude starts);
- changes you made yourself outside Claude Code.
For those, use Git (step 7).
There is one exception. If Claude already changed a file with its own tools, rewind also undoes later command changes to that same file.
4. Gemini CLI: open the rewind menu
Gemini CLI also has /rewind. It needs no setup. Type this inside the session:
/rewindYou can also press Esc twice.
Use the arrow keys to pick the message you want to go back to, and press Enter. The list shows how many files changed at each step. Then choose an action:
- Rewind conversation and revert code changes: undo the chat and the file changes.
- Rewind conversation: undo the chat, but keep the files.
- Revert code changes: undo the file changes, but keep the chat.
- Do nothing (esc): cancel.
If no files changed after that point, Gemini hides the options that revert code.
Rewind only undoes changes made by Gemini's edit tools. It does not undo edits you made yourself, or changes from shell commands you ran with !. If you revert only the files, tell Gemini that the files changed, because it still remembers the old chat.
5. Gemini CLI: checkpoints with /restore (optional)
Gemini CLI has a second undo tool: checkpoints. They are off by default. When you turn them on, Gemini saves a snapshot of your project before each file change that you approve. The snapshots stay on your computer, separate from your own Git history.
To turn checkpoints on, open the file ~/.gemini/settings.json (~ is your home folder) and add this. If the file already has settings, put the general part inside the existing outer braces:
{
"general": {
"checkpointing": {
"enabled": true
}
}
}Restart Gemini CLI after you save the file.
To see the saved checkpoints, type this inside the session:
/restoreTo go back to one, add its name from the list:
/restore <checkpoint_file>This puts the files back, restores the conversation and shows the original change again. You can then run it, change it or ignore it.
6. Codex CLI: check the changes with /diff
Codex CLI has no rewind command. To see what Codex changed, type this inside the session:
/diffYou see the Git diff (a list of the changed lines), including new files that Git does not track yet. Check the changes before you keep them.
7. Codex CLI (and any tool): make a Git checkpoint
OpenAI's advice for Codex is to make Git checkpoints before and after a task, so you can undo changes. This works with every assistant.
In the terminal, go to the project folder. If the folder is not a Git project yet, run this once:
git initSave everything as it is now. First mark all files for saving:
git add -AThen save them as a commit (a saved version):
git commit -m "checkpoint before AI changes"If you do not like what the assistant changed later, this command puts all files in the current folder back to the last commit:
git restore --source=HEAD --staged --worktree .It needs Git 2.23 or newer. Be careful:
- It throws away every change since the last commit, your own changes too. Commit anything you want to keep first.
- It does not remove new files that the assistant made. Delete those yourself.
If you see an error
No files were restoredin Claude Code: the saved files for that checkpoint are gone. Claude Code deletes them about 30 days after the session last saved one. Use Git instead.- Claude Code says
Restored the code, but skipped N files: rewind does not restore symlinked or hard-linked files (files that point to another file). Ask Claude to reverse the edit, or edit the file yourself. /restorein Gemini CLI shows no checkpoints: checkpoints were off when the change happened. Use/rewind(step 4). Turn checkpoints on (step 5) for later changes.- Gemini CLI says the
--checkpointingoption is unknown: Gemini removed that option in version 0.11.0. Use the settings file instead (step 5). - Git says
not a git repository: you are not in a Git project. Go to the right folder withcd, or rungit initin the project folder first.
Sources
- code.claude.com/docs/en/checkpointing
- github.com/anthropics/claude-code/blob/main/CHANGELOG.md
- github.com/google-gemini/gemini-cli/blob/main/docs/cli/rewind.md
- github.com/google-gemini/gemini-cli/blob/main/docs/reference/commands.md
- github.com/google-gemini/gemini-cli/blob/main/docs/cli/checkpointing.md
- github.com/google-gemini/gemini-cli/blob/main/docs/reference/configuration.md
- learn.chatgpt.com/docs/codex/cli
- learn.chatgpt.com/docs/developer-commands?surface=cli
- git-scm.com/docs/git-init
- git-scm.com/docs/git-add
- git-scm.com/docs/git-commit
- git-scm.com/docs/git-restore