Skip to content
Edith

Agent docs

TutorialBeta· About 10 minutes

Undo coding agent changes with Crew checkpoints

By the end of this tutorial you will know how to find the snapshot the agents engine took around an agent's turn, see exactly what that turn changed, and put your files back, all without touching your branches. You need Crew running and an agent working in a git repository. See Get Crew.

Work in a git repository

When an agent in a git repository starts working, and again when it stops, the engine records a checkpoint of the whole working tree, untracked files included. Checkpoints live in the same repository but never touch your index, your branches or your stash, so git status and git log look the same as before.

Start an agent in the repository from the Crew page with New agent (⌘N), or start a thread there from Threads.

Turn on checkpoints for threads

Threads save a checkpoint each turn when Save a checkpoint each turn is on:

  1. On the Crew page, open Filter (⇧⌘F) and choose Edit launch settings.
  2. In the Thread engine section, turn on Save a checkpoint each turn.

Revert a thread's turn

For a thread, you undo from the thread itself:

  1. Open the thread and press Diff (⌘D) in the thread toolbar. It shows the thread's changes, turn by turn.
  2. Pick the turn that went wrong and read what it changed.
  3. Press Revert to restore files to the checkpoint before that turn.

Rewind the conversation

To take the conversation back too, choose Edit from here on a message, then:

  • Revert and keep changes removes that message and everything after it from the conversation, and leaves your files alone.
  • Revert files too also puts the worktree back to the checkpoint from before that message, including edits you made yourself.

From the terminal

Terminal
ed crew thread rollback th_01 run_03ed crew thread rollback th_01 run_03 --keep-files

--keep-files only undoes the conversation and leaves your files alone.

Undo a terminal agent's turn

Checkpoints for agents in terminal panes are listed, compared and restored from a terminal. Run these in the repository folder, or pass --cwd.

Take a checkpoint before you start

Before you hand an agent something risky, or before you edit files yourself, take a checkpoint of your own. Your files and branches stay as they are:

Terminal
ed crew checkpoints create --label "before the refactor"

List the checkpoints

Let the agent take a turn, then list what the engine recorded:

Terminal
ed crew checkpoints ls --cwd ~/code/apped crew checkpoints ls --pane w1:p2 --limit 10ed crew checkpoints ls --thread th_01ed crew checkpoints show cp_01

The newest come first, 50 by default. --pane and --thread narrow the list to one agent. Each checkpoint has an id such as cp_01 and belongs to an agent pane or a thread. show prints one checkpoint's repository, commit, owner, status and changed files.

See what a turn changed

By default diff compares a checkpoint with the next one, which is exactly what that turn changed. Start with --stat for the list of files and line counts, then read the full diff:

Terminal
ed crew checkpoints diff cp_01 --stated crew checkpoints diff cp_01
Command What it compares
ed crew checkpoints diff cp_01 --to worktree The checkpoint with your files as they are now
ed crew checkpoints diff cp_01 --to cp_05 Two checkpoints
ed crew checkpoints diff cp_01 --path src/app.ts Only this path. Repeat for more
ed crew checkpoints diff cp_01 --authored-only Only the changes the agent made, not edits made around it
ed crew checkpoints diff --thread th_01 --from-run run_02 A thread's changes between runs

--ignore-whitespace hides whitespace changes in any of them.

Restore one file

When only one file went wrong, restore just that path. Everything else stays:

Terminal
ed crew checkpoints restore cp_01 --path Sources/App.swift

Restore the whole repository

To roll back a whole turn, restore the checkpoint from before it:

Terminal
ed crew checkpoints restore cp_01

Restoring puts the repository back the way the checkpoint had it:

  • Tracked files are rewritten.
  • Untracked files that did not exist in the checkpoint are removed.
  • Ignored files are left alone.

The engine refuses to restore while another agent works in the repository. Stop or wait for that agent, or pass --force if you are sure.

Undo a restore

The engine takes a safety checkpoint before every restore, so a restore can itself be undone. List the checkpoints again, find the one the restore took, and restore it:

Terminal
ed crew checkpoints ls --cwd ~/code/app --limit 5

Clean up old checkpoints

Checkpoints pile up in busy repositories. Deleting a thread also deletes its checkpoints. From a terminal, delete ones you no longer need, or keep only the newest:

Terminal
ed crew checkpoints rm cp_01 cp_02ed crew checkpoints prune --keep 200

prune keeps 2000 unless --keep says otherwise.

On a machine you added in Machines, add --machine to any of these commands and pass that machine's paths:

Terminal
ed crew checkpoints ls --machine box --cwd /srv/app