Home › Articles

Undo an AI agent's changes in Claude Code, Cursor and Codex

Updated 2026-11-10

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 CodeCursorCodex
How to undo/rewind or Esc twice on an empty promptClick a checkpoint in the chat timeline, Restore Checkpoint on an earlier request, or the + button when hovering a messageApp/IDE review pane: Revert all, per file, per hunk. CLI: /diff, then git
When snapshots are takenBefore every prompt that starts a turnAutomatically before significant changesNo separate snapshots; it works from your Git repository
Rolls back the chat too?Your choice: code, conversation, or bothNo, files only; messages stayEsc twice edits the previous message and forks the chat (files untouched per the docs)
MissesFiles only Bash changed, most subagent edits, outside changes, symlinks and hard linksTerminal-command changes, subagent changes, your own edits (staff forum reply)Anything outside Git: ignored files, untracked files deleted before you snapshotted them
Needs git?NoNoYes (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:

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

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:

  1. Click any checkpoint in the chat timeline to preview your files at that point, then restore; or
  2. 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:

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:

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

  1. 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.
  2. Small wrong turn in Claude Code or Cursor: use /rewind → Restore code, or Restore Checkpoint.
  3. Then check git anyway: git status (or /diff in Codex). Anything still changed was made by a shell command, a subagent or you, and needs git restore or the snapshot.
  4. In the Codex app, review the Last turn scope before Revert all.
  5. 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

Official docs, checked 2026-11-10.

Get the free rules sampler + new tips by email

Confirm your email and we'll send you straight to the sampler download. Then one short email every two weeks covering tool format changes (Cursor, Claude Code, Codex, Windsurf, Copilot), new rules and kit updates. No spam.

We store only your email, with our email provider Resend. See the privacy policy.

Unsubscribe anytime from any email. Rather skip email? Get the sampler on GitHub or download the zip directly.