Git Undo/Redo: Never Lose Work to an AI Agent Again

AI coding agents are powerful. They can refactor entire modules, add features across multiple files, and fix bugs you didn't even know existed. But that power comes with a risk: when the agent makes a wrong turn, it can overwrite your work in ways that are hard to recover from.

That's why AI agent git undo capabilities aren't optional — they're essential. If you're letting an AI agent edit your codebase, you need a reliable way to undo AI changes instantly.

The Problem with Uncontrolled Agents

Most coding agents operate in a simple loop: read code, decide what to change, write the changes. The problem is that "write the changes" can mean modifying dozens of files in a single turn. If the agent misunderstands your intent or goes down the wrong path, you're left with a mess.

Manual git recovery works, but it's slow. You need to figure out which commit was the last good state, cherry-pick changes, and hope you don't lose the parts you wanted to keep. That's not a workflow — it's damage control.

How Git Checkpoints Solve This

muxd takes a different approach with automatic git checkpoints. Every time the agent completes a turn — any turn where it modifies files — it creates a git commit capturing that exact state. These checkpoints are invisible during normal work but available the instant you need them.

The workflow is simple:

This isn't just a "nice to have" — it fundamentally changes how you interact with an AI agent. You can let the agent try ambitious refactors knowing you're one command away from reverting everything.

Why This Beats Manual Git

You might think "I'll just commit before letting the agent work." That works in theory, but in practice:

  1. You'll forget. When you're deep in a flow state, the last thing you want is manual checkpoint discipline.
  2. Granularity matters. A single agent session might involve 10 tool calls across 5 files. You want per-turn rollback, not per-session.
  3. Redo is just as important as undo. Sometimes the agent's first attempt was actually better. Without redo, you're doing git reflog gymnastics.

Automatic git checkpoints handle all three problems. Every agent turn is a checkpoint. Every checkpoint is reversible. No discipline required.

Real-World Scenario

Here's a common situation: you ask the agent to refactor a function, and it decides to also "improve" three related files you didn't ask about. With checkpoints:

  1. Run /undo to revert the entire turn
  2. Give the agent more specific instructions
  3. Let it try again with a tighter scope

Without checkpoints, you're manually diffing files and trying to reconstruct what changed. That's time you should be spending on actual work.

How It Works Under the Hood

The checkpoint system uses standard git — no custom storage, no proprietary format. Each checkpoint is a real commit on your current branch. The /undo command does a git reset to the previous checkpoint, and /redo re-applies it. Your normal git history stays clean because these checkpoints can be squashed when you're done.

Read the full undo/redo documentation for details on how muxd manages checkpoints, or get started with the installation guide.

Stay in Control

Letting an AI agent edit your code shouldn't feel like a gamble. With automatic git checkpoints, every change is reversible, every experiment is safe, and you never lose work to an agent that went off-script. That's not just a feature — it's the baseline for responsible AI-assisted development.