All pages

Autonomy you can trust · Lesson 1.2 · 12 min

Rehearse with dry runs, undo with snapshots

Preview a change before it lands and take back a write after it has.

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.

Time: 12 minutes · Works on: macOS app. The cloud workspace has the snapshot tools too.

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.

  1. Checkpoint. git status is clean, or you commit what's there.
  2. Rehearse. You ask the agent to stage the whole change in a dry run and show you the combined diff without applying it.
  3. 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.
  4. Apply. You approve the apply. All seven files land together.
  5. 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.
  6. Fall back if needed. Had the whole approach been wrong, you'd have reset to the checkpoint commit and started over in a minute.

Do it in TRMNLY

  1. Commit a checkpoint. In a pane, run git status and commit or stash anything you care about. For larger jobs, do the work in its own worktree (see Worktrees), so throwing it away is one removal.
  2. Start a rehearsal. Ask the sidebar agent: "Use dry_run_begin, then make the change with write_file and edit_file. When you're done, show me dry_run_diff and stop." After dry_run_begin, those two tools stage their changes in memory instead of writing to disk, and read_file reads the staged versions. dry_run_begin and dry_run_diff need no approval.
  3. Expect a few refusals. While a rehearsal is open, apply_patch, git_discard and ast_rename refuse to run, because they would write straight to disk. The agent should use write_file and edit_file instead. Shell commands, searches and directory listings still see the real disk.
  4. Read the whole diff. dry_run_diff returns one unified diff of every staged file against what's on disk. Ask for changes until it's right.
  5. Decide. Tell the agent to call dry_run_apply to write everything, or dry_run_discard to drop it. Apply is approval-gated, so on Approve you get a card for it. It snapshots each file's previous contents as it writes, so the next step still works afterwards. Discard leaves the disk exactly as it was.
  6. Undo one write from the transcript. After the agent writes files, a Snapshots list appears in the transcript naming each one. Click the restore arrow beside a file. TRMNLY asks first, naming the file and the write it will undo. A file the agent created is deleted instead. The button beside it compares the prior contents with the current file.
  7. Undo from the gear menu. The gear menu has Undo last write: followed by the file's name, for this chat's most recent write, and Browse file snapshots…, which opens a File snapshots window where each row has a Revert button.
  8. Let the agent undo itself. Ask: "List your write snapshots and revert the one for fixtures/config.json." It uses list_write_snapshots and revert_write_snapshot. The revert is approval-gated because it overwrites the current file. With no id, it undoes the most recent write.
  9. Rehearse commands, not files, with Mode. The other kind of dry run is the project setting. In the gear menu, choose Project agent settings… and set Mode to Dry run (echo commands). Shell commands come back as echoes, so you can see what the agent would run. File writes are not staged in this mode: they still ask and still happen. Use it to check a deploy or cleanup script's commands, then set Mode back to Full access.
  10. Use git for the rest. For shell-made changes and CLI agent edits, ask the agent to show git_diff before you commit, and keep the checkpoint until you've verified. If you ask the agent to git reset --hard back to it, that trips the destructive command prompt the first time in a session, so you'll be asked before it runs.

Check yourself

  • You staged a change across at least two files with dry_run_begin, read dry_run_diff, and then discarded it, and git status shows nothing changed.
  • You restored one file from the Snapshots list and saw the prompt name the write first.
  • You can name three kinds of change a write snapshot can't undo.
  • You can explain the difference between the dry_run_* tools and Dry run (echo commands) mode.

Go further