How to undo what a coding agent changed

Short answer

Claude Code can rewind the files it edited, Gemini CLI can restore a checkpoint if you switched checkpointing on, Codex's documentation points you to git, and Clixad's /undo takes back your message and names the files that changed without reverting them.

No agent's undo reaches what a command did outside the files it tracks: a migration, an install, a push. A branch or a worktree per task, with a commit before you start, is the undo that covers everything an agent writes, whichever agent wrote it.

What each agent can take back

Undo in four agents, from each vendor's documentation, read 2 December 2026, and from Clixad's source.
AgentHowWhat comes backWhat does not
Claude Code/rewind, or Esc twice on an empty promptFiles Claude edited, the conversation, or bothFiles only a shell command changed
Gemini CLI/restore, once checkpointing is switched onThe project's files as they were before an approved editAnything, if checkpointing was off
CodexGit, as its CLI page advisesWhat you committedWhat you did not
Clixad/undoYour last message, back in the input boxFiles, and the credits the turn used

Claude Code keeps checkpoints: "A checkpoint is a restore point for the files Claude edits." and "Every prompt you send that starts a turn creates a new checkpoint." You "Run /rewind, or press Esc twice when the prompt input is empty, to open the rewind menu", and choose to restore the code, the conversation or both. The documentation is direct about the gap: "A file that only Bash commands changed isn't tracked and stays as it is. To revert it, use version control, such as Git." It also warns that "restoring code can discard changes you or another session made to that file after the selected checkpoint."

Gemini CLI can do something similar, but its checkpointing is off until you switch it on in settings.json. Then a checkpoint is made when "you approve a tool that modifies the file system (like write_file or replace)", stored as "A commit is made in a special, shadow Git repository located in your home directory", and /restore lists the checkpoints and restores one. It does not touch your own repository's history.

Codex's CLI page gives the advice that holds for every agent: "Create Git checkpoints before and after a task so you can revert changes."

Clixad's /undo takes your last message back into the input box, so you can change it and send it again, and cuts the conversation before it. It does not restore files. It says so every time, names the files the agent wrote or edited for that message, and counts the commands it ran. The credits the turn used stay spent. If you come from Claude Code, where Anthropic lists /undo as another name for /rewind, that difference matters.

What no undo reaches

Every agent's undo works on files, and only on files it was tracking. A command runs in the world outside them. None of these come back through an agent's undo, and most do not come back through git either:

  • A database migration that ran, or rows a script deleted.
  • Packages installed globally, or a system setting changed.
  • Files outside the project, which neither the agent's checkpoints nor your repository know about.
  • Anything sent over the network: a push, a deploy, a message, a call to a paid API.
  • A file that was never committed and that a command deleted. Git cannot give back what it never had.

That is the reason to read a command before you approve it, and the reason modes that skip approvals belong in a container. Permission modes in coding agents compares what each agent asks about.

A git routine around an agent task

Git is the undo that covers everything an agent writes into a repository, whichever agent wrote it. Five habits make it work.

  1. Start from a clean tree. Run git status. Commit what you have, or put it aside with git stash, which git describes as for when "you want to record the current state of the working directory and the index, but want to go back to a clean working directory."
  2. Give the task its own branch. git switch -c agent/fix-date-parsing. Throwing the attempt away is then git switch main and git branch -D agent/fix-date-parsing.
  3. Or its own directory. "A git repository can support multiple working trees, allowing you to check out more than one branch at a time." git worktree add -b agent/fix-date-parsing ../repo-fix gives the agent a separate checkout to work in, while yours stays as it was. git worktree remove ../repo-fix clears it away.
  4. Commit as you go. After each step that works, git add -A and git commit -m "checkpoint: parser handles ISO dates". Each commit is a point you can return to, and unlike a session's checkpoints it is still there next week.
  5. Review before you keep it. git diff --stat shows which files changed, git diff how. git restore path/to/file takes back the changes to one file you have not staged, and git clean -n lists new untracked files the agent created, before git clean -f removes them.

Undo in Clixad, step by step

  • Take back what you asked: /undo. The message comes back into the input box as you typed it, and the saved session is cut to match, so resuming it later starts from the same place.
  • Take back the files: git, using the list of files /undo prints.
  • Stop before it goes further: Esc stops a turn at once, and n in a permission dialog refuses one step and lets the agent find another way.
  • Change nothing until you have seen a plan: plan mode, with Shift+Tab.

Our docs on /undo cover the details, including what happens when the message was refused before any work was done.

FAQ

How do I undo changes made by Claude Code?

Run /rewind, or press Esc twice on an empty prompt, and choose to restore the code, the conversation or both. Claude Code's checkpoints cover files Claude edited, not files that only a shell command changed; for those, use git.

Does Codex have an undo?

Its CLI page advises creating git checkpoints before and after a task so you can revert changes. Commit before you start, and the commit is the undo.

Does Clixad's /undo revert files?

No. It takes your last message back into the input box and cuts the conversation before it. The files the agent changed stay changed, and it names them so you can revert them with git.

Is git enough to undo what an agent did?

For files in the repository, yes, if you committed before the task. It does not reach a database a migration changed, packages installed outside the project, anything sent over the network, or an untracked file a command deleted.

What is a git worktree, and why use one for an agent?

A second working directory attached to the same repository, on its own branch. The agent works there while your own checkout stays as it was, and removing the worktree throws the attempt away.

Sources

  1. Anthropic, Checkpointing, for "A checkpoint is a restore point for the files Claude edits.", "Every prompt you send that starts a turn creates a new checkpoint.", the rewind menu and its options, /undo as an alias of /rewind, the sentence on Bash commands, and the warning about other changes. Read 2 December 2026.
  2. Google, Checkpointing, for checkpointing being off by default, when a checkpoint is made, the shadow Git repository and /restore. Read 2 December 2026.
  3. OpenAI, Codex CLI, for "Create Git checkpoints before and after a task so you can revert changes." Read 2 December 2026.
  4. Git, git-worktree, for "A git repository can support multiple working trees, allowing you to check out more than one branch at a time." Git, git-stash, for when to use it. Both read 2 December 2026.
  5. What Clixad's /undo does and says: the source of the command line tool at github.com/clixad/cli, and our docs.