Undo an AI agent's changes in Claude Code, Cursor and Codex
In short: Claude Code has /rewind (or Esc twice), Cursor has
Restore Checkpoint, and Codex relies on Git: the desktop app's review pane can revert the whole diff,
a file or a hunk, and the CLI has /diff plus your own git commands. The first two only undo edits the agent
made with its file-editing tools. Anything a shell command, a subagent or you changed needs git, so take a git
snapshot before a big task.
This page compares the built-in undo in each tool, checked against official docs on 2026-11-10, and ends with a
small git script for the cases none of them cover. We ran that script and parsed the JSON below; we did not run
/rewind, Restore Checkpoint or the Codex app's Revert on this page's behalf.
Side by side
| Claude Code | Cursor | Codex | |
|---|---|---|---|
| How to undo | /rewind or Esc twice on an empty prompt | Click a checkpoint in the chat timeline, Restore Checkpoint on an earlier request, or the + button when hovering a message | App/IDE review pane: Revert all, per file, per hunk. CLI: /diff, then git |
| When snapshots are taken | Before every prompt that starts a turn | Automatically before significant changes | No separate snapshots; it works from your Git repository |
| Rolls back the chat too? | Your choice: code, conversation, or both | No, files only; messages stay | Esc twice edits the previous message and forks the chat (files untouched per the docs) |
| Misses | Files only Bash changed, most subagent edits, outside changes, symlinks and hard links | Terminal-command changes, subagent changes, your own edits (staff forum reply) | Anything outside Git: ignored files, untracked files deleted before you snapshotted them |
| Needs git? | No | No | Yes (the review pane requires a Git repository) |
Claude Code: /rewind and checkpoints
Claude Code captures the state of your code before each prompt you send that starts a turn. It keeps file snapshots
for the 100 most recent checkpoints in a session and saves checkpoints with the conversation, so /rewind
still works after you resume a session.
Run /rewind, or press Esc twice when the prompt input is empty (if the input has text,
double Esc clears it instead and saves it to history). Pick a prompt from the list, then an action:
- Restore code and conversation: revert both to that point.
- Restore conversation: rewind the chat but keep the current code.
- Restore code: revert the files but keep the chat.
- Summarize from here / Summarize up to here: compress part of the conversation to free context. These do not change files.
- Never mind: back out.
The two code options only appear when the selected checkpoint has tracked file changes to revert. After you restore
the conversation, your original prompt is put back in the input so you can edit and re-send it. If you want to try a
different approach while keeping the original session intact, the docs point to /branch or
claude --continue --fork-session instead (see how to fork a
session in Claude Code, Codex and Cursor).
What /rewind does not restore
- Bash-only changes. Once Claude has edited a file with its file-editing tools,
/rewindalso undoes later Bash changes to that file. A file that only Bash commands changed is not tracked and stays as it is. Ased -ior a codegen script on a file Claude never edited is a git job. - Subagent edits. Usually not captured. A foreground forked skill (
context: forkwithbackground: false) edits during your own turn, so its edits are restored. Any other subagent, including a background fork (the default) and a background/code-review --fix, keeps its edits to files Claude had not already edited in your conversation. - Outside changes. Your own edits outside Claude Code and edits from other concurrent sessions are normally not captured, unless they touch the same files as the current session.
- Messages typed mid-turn. A message you sent while Claude was working can show No code restore. Select the prompt that started that turn instead; that reverts the whole turn's file edits.
- Symlinks and hard links. Skipped with a
Restored the code, but skipped N fileswarning. That includes dotfile-manager symlinks and files pnpm hard-links into place. Turn on/debugbefore restoring to get each skipped path in the debug log.
Settings that matter
Checkpointing is on by default (fileCheckpointingEnabled, shown in /config as
“Rewind code (checkpoints)”). The environment variable CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING
turns it off for one session, and whichever of the two turns it off, the other cannot turn it back on. In a
claude -p run or an Agent SDK session the setting is ignored: the SDK uses its
enableFileCheckpointing option, and a bare -p run needs
CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING=true.
Snapshots are deleted in Claude Code's retention sweep, by default about 30 days after the session last saved one.
Rewinding to a checkpoint whose snapshots are gone can fail with No files were restored. To keep them longer,
raise cleanupPeriodDays (default 30, minimum 1; 0 fails validation). It also controls how long
session transcripts are kept, so pick a number you are comfortable with:
{
"fileCheckpointingEnabled": true,
"cleanupPeriodDays": 90
}
Cursor: Restore Checkpoint
Cursor's Agent creates checkpoints automatically before making significant changes, capturing the state of all modified files. To go back:
- Click any checkpoint in the chat timeline to preview your files at that point, then restore; or
- Use the Restore Checkpoint button on a previous request (the help page puts it in the bottom right when you hover the message), or the + button when hovering over a message.
Restoring reverts files only. It does not remove messages from the conversation, so tell the agent what changed before you continue, or start a new chat. Checkpoints are stored locally and separate from Git, and Cursor's docs say to use them only for undoing Agent changes and to use Git for permanent version control.
The gap is the same shape as Claude Code's. On a 31 October 2026 forum report that Restore Checkpoint left changes in
place, Cursor staff replied that it only undoes edits the agent made with its file-editing tools. Changes made by
running terminal commands (like a Python or sed script), through subagents, or by you stay put, and they
called committing before an agent session “the most reliable way to roll back.”
If you came here from a plan that went wrong, Cursor's plan-mode help says to revert and refine the plan rather than patching with follow-ups; see Plan mode in Claude Code, Cursor and Codex.
Codex: Git is the undo
The Codex CLI guide says to create Git checkpoints before and after a task so you can revert changes. The official command reference we checked on 2026-11-10 has no undo or rewind command for files. What it does have:
/diffshows staged changes, unstaged changes and files Git is not tracking yet, so you can see new files Codex created (plaingit diffdoes not list untracked files)./reviewruns a reviewer on uncommitted changes, a base branch or a commit. It reports findings; it does not change your working tree.Esctwice with an empty composer edits your previous message and forks the chat from that point./forkclones the chat. The docs describe both as conversation actions; neither is documented to restore files, so check/diffafterwards.
In the ChatGPT desktop app, the review pane can stage, unstage or revert at three levels: the entire diff (Revert all), one file, or one hunk. Two details from the docs matter for undo:
- The pane needs a project inside a Git repository; if yours is not one, the app prompts you to create it.
- It reflects your whole repository, not just Codex's edits: your own changes and any other uncommitted work are in the same diff. Revert all on the default Unstaged view can discard your work too. Switch to the Last turn scope to see only the assistant's latest changes before you revert anything.
A git snapshot for everything the buttons miss
A commit before each agent task is the simplest safety net. If you have half-finished work you do not want to commit,
this script saves the whole working tree (tracked, modified and untracked files, but not .gitignore'd ones)
to a ref under refs/checkpoints/. It does not touch your branch, index, stash or files:
#!/usr/bin/env bash
# agent-checkpoint.sh: snapshot the whole working tree (tracked, modified and
# untracked files, minus .gitignore'd ones) to a git ref, without touching your
# working tree, index, branch or stash. Run it before you hand a task to an agent.
#
# ./agent-checkpoint.sh # save refs/checkpoints/<timestamp>
# git for-each-ref refs/checkpoints # list checkpoints
# git diff refs/checkpoints/<name> # what changed since the checkpoint
# git restore --source=refs/checkpoints/<name> --worktree -- .
# # put tracked + snapshotted files back
# comm -13 <(git ls-tree -r --name-only refs/checkpoints/<name> | sort) \
# <(git ls-files -co --exclude-standard | sort)
# # files created since (not in the checkpoint); delete by hand
# Ignored files (.env, build output) are NOT saved. Delete old refs with git update-ref -d.
set -euo pipefail
git rev-parse --is-inside-work-tree >/dev/null
cd "$(git rev-parse --show-toplevel)"
name="${1:-$(date +%Y%m%d-%H%M%S)}"
tmp_index="$(mktemp)"
trap 'rm -f "$tmp_index"' EXIT
rm -f "$tmp_index"
if git rev-parse --verify -q HEAD >/dev/null; then
GIT_INDEX_FILE="$tmp_index" git read-tree HEAD
parent=(-p HEAD)
else
parent=()
fi
GIT_INDEX_FILE="$tmp_index" git add -A
tree="$(GIT_INDEX_FILE="$tmp_index" git write-tree)"
commit="$(git commit-tree "$tree" "${parent[@]}" -m "agent checkpoint $name")"
git update-ref "refs/checkpoints/$name" "$commit"
echo "saved refs/checkpoints/$name ($commit)"
Run it from anywhere in the repo before you hand over a task, for example ./agent-checkpoint.sh before-auth-refactor.
To roll back, run the git restore line from the repo root, then use the comm line to list files
that were created after the checkpoint and delete the ones you do not want. Do not reach for git clean here:
it would also delete files that were untracked when you took the snapshot. We tested this in throwaway repos (modified,
untracked and ignored files, a repo with no commits yet, running from a subfolder).
Two limits to know. Ignored files such as .env, local databases and build output are not saved, so back
those up separately if an agent could touch them (and see
how to stop agents reading your .env file). And no file snapshot
undoes side effects outside the repo: a database migration, a git push, a deploy or an API call. For those,
keep the agent asking before it runs commands; see
which commands to allow and which to keep prompting for.
A five-minute routine
- Before a big task, commit or run the snapshot script. If you run several agents at once, give each its own checkout instead (parallel agents with git worktrees), so one agent's undo cannot hit another's work.
- Small wrong turn in Claude Code or Cursor: use
/rewind→ Restore code, or Restore Checkpoint. - Then check git anyway:
git status(or/diffin Codex). Anything still changed was made by a shell command, a subagent or you, and needsgit restoreor the snapshot. - In the Codex app, review the Last turn scope before Revert all.
- After an undo in Cursor or a Codex fork, tell the agent what you reverted. The files went back; its memory of the abandoned attempt may not have.
FAQ
How do I undo Claude Code's changes?
Run /rewind, or press Esc twice with an empty prompt, pick the prompt you want to go back to, and choose Restore code (files only), Restore conversation (chat only) or Restore code and conversation. Claude Code takes a checkpoint before every prompt that starts a turn and keeps the 100 most recent in a session. It only restores edits made with its file-editing tools, so files changed only by Bash commands, most subagent edits and changes from outside the session need git.
Does Cursor's Restore Checkpoint undo terminal commands?
No. Cursor's docs say checkpoints capture files Agent modifies and that restoring reverts files only, not the conversation. In a Cursor forum reply on 2 November 2026, Cursor staff said Restore Checkpoint only undoes edits the agent made with its file-editing tools: changes from terminal commands (such as a Python or sed script), from subagents, and your own edits stay in place.
Does Codex have an undo or /rewind command?
The official Codex command reference checked on 10 November 2026 lists no undo or rewind command for files. Pressing Esc twice with an empty composer edits your previous message and forks the chat from that point; the docs describe that as a conversation action, not a file restore. In the ChatGPT desktop app the review pane can Revert all, one file or one hunk, and it requires a Git repository. In the CLI, use /diff and git.
Are checkpoints a replacement for git?
No, and all three vendors say so. Claude Code calls checkpoints session-level recovery and says to keep using version control; Cursor says checkpoints are stored locally, separate from Git, and only for undoing Agent changes; Codex tells you to create Git checkpoints before and after a task. Commit or snapshot before a big agent task, and use checkpoints for quick in-session rollbacks.
Why did /rewind say No files were restored?
Claude Code deletes a session's file snapshots in its retention sweep, by default about 30 days after the session last saved one, and rewinding to a checkpoint whose snapshots are gone can fail with that message. Raise cleanupPeriodDays to keep them longer. Restores also skip symlinked and hard-linked files with a "Restored the code, but skipped N files" warning.
Sources
- Claude Code docs: Checkpointing (/rewind, limitations)
- Claude Code docs: All settings (fileCheckpointingEnabled, cleanupPeriodDays)
- Cursor docs: Agent overview (Checkpoints)
- Cursor help: Agent troubleshooting (How do I undo Agent changes?)
- Cursor forum: staff reply on what Restore Checkpoint does not undo (2026-11-02)
- Codex docs (ChatGPT Learn): Developer commands (/diff, /fork, Esc twice)
- Codex docs (ChatGPT Learn): Codex CLI (Git checkpoints)
- Codex docs (ChatGPT Learn): Code review (review pane, Revert all / file / hunk)