Lesson 2 of 5 in Autonomy you can trust · 12m
Rehearse with dry runs, undo with snapshots
After this lesson you can have the agent stage a multi-file change and show you the whole diff before anything touches disk, take back a single write after it has landed, and know which changes only git can undo.
Undo before, undo after
Raising autonomy is safe only when mistakes are cheap. There are two ways to make them cheap, and you want both.
-
Undo before means rehearsal. The agent does the work against a copy, you look at the result, and only then does it become real. It catches a wrong plan before it costs anything.
-
Undo after means a way back. The change has landed, you've spotted a problem, and you put the old version back without reconstructing it by hand.
Behind both sits a third layer that covers everything they miss: git. A clean commit before the agent starts is the one undo that works for every kind of change, by every kind of tool, in every agent.
A good habit has all three in order: commit a checkpoint, rehearse the risky part, let it land, and keep the per-write undo for small corrections.
What rehearsal is good for, and what it isn't
Rehearsal pays off when a change spans several files and the risk is in the shape of the whole change: a config format migration, a rename that crosses module boundaries, an API change with many call sites. Reading the edits one card at a time, you see trees. Reading one diff at the end, you see whether the forest is right.
Rehearsal does not test anything. A staged change exists only in the agent's working state. Your test runner, your build and every other shell command still read the real files on disk, so they can't see it. If you need to know whether the change works, the place to try it is a separate worktree, not a rehearsal.
What a per-write undo covers
TRMNLY saves a file's previous contents just before the agent's own file tools write to it. That covers write_file, edit_file and apply_patch, and a dry-run apply. It does not cover:
-
files changed by a shell command, such as sed -i, a code generator, or npm install rewriting a lockfile;
-
edits made by Claude Code, Codex or Gemini running as a CLI agent, which use their own tools;
-
anything outside a file: a commit, a push, a database row, a request to an outside service.
The store is bounded: up to 200 snapshots and 50 MB in all, oldest dropped first. A single file bigger than half that isn't captured, and the tool's result says there is no undo snapshot for it. For anything in that list, git is your undo.
A worked example
You're moving a project from a hand-rolled config.json to a typed config.ts, which touches the loader, four call sites and two tests.
-
Checkpoint. git status is clean, or you commit what's there.
-
Rehearse. You ask the agent to stage the whole change in a dry run and show you the combined diff without applying it.
-
Read the diff. One call site is converted wrong: it reads config.port where the new type calls it config.server.port. You tell the agent, and it fixes the staged copy. The second diff is right.
-
Apply. You approve the apply. All seven files land together.
-
Verify. You run the tests. One fails because of a fixture file the agent also changed. You undo that one write from its snapshot and keep the rest.
-
Fall back if needed. Had the whole approach been wrong, you'd have reset to the checkpoint commit and started over in a minute.
Go further
- Safety and approvals — the dry run mode and the Snapshots list, step by step
- Agent safety — the multi-file approval gate and the destructive verb prompt
- Review the diff — reading an agent's change before you keep it
- One worktree per agent — where to try a change for real
- Next lesson: Secrets without leaks