The problem with AI that writes files
Every agentic coding tool has the same trust problem. You ask it to do something, it starts touching files, and at some point you get that feeling — wait, what exactly did it just change?
With a human engineer you'd do a PR review. With a script you'd read the diff. With an AI agent running in your terminal, most tools just... make the changes and leave you to figure out git diff after the fact. If you forgot to commit first, you're in a bad spot.
This is the thing that kept me from fully trusting agentic tools for real work. I'd use them for throwaway code or isolated new files, but the moment an agent was touching existing logic I'd get nervous. Too much surface area, not enough visibility.
lac agent handles this differently, and it's the reason I actually run it on production codebases now.
How undo works in lac agent
Every file write that lac agent makes is tracked internally. Before applying any change to a file, the agent snapshots the previous state. That snapshot lives in the session until you explicitly clear it or start a new one.
When something looks wrong — maybe the agent refactored a function in a way you didn't intend, or it edited the wrong config file — you just tell it to undo:
undo
That's it. The agent walks back the last edit, restores the file to its previous state, and confirms what it reversed. No git required. No manual copy-pasting from a backup. It just goes back.
You can also redo if you undid too aggressively:
redo
The history is linear and per-session, so it behaves like a proper editor undo stack — not some vague "revert to last checkpoint" that might dump you somewhere unexpected.
The diff preview is the part that actually matters
Undo is useful for recovery. But the diff preview is what makes you confident enough to let the agent move fast in the first place.
Before lac agent commits a file change, it shows you a diff. You see exactly what's being removed (in red) and what's being added (in green), inline, right in your terminal. Same format as git diff — so there's no learning curve, you already know how to read it.
You confirm, and it writes. You reject, and it doesn't. The agent waits.
This sounds like it would slow everything down, and it does add one keystroke per file change. But in practice it changes how you work. Instead of running the agent in short cautious bursts, you can give it a bigger task and just watch the diffs roll in. Each one takes two seconds to scan. You approve the ones that look right, catch the ones that don't. It's closer to reviewing a PR than nervously babysitting a script.
A real example
Yesterday I was refactoring some route handlers in a Node project. I asked the agent to extract the auth middleware into its own file and update all the imports across the codebase.
It touched seven files. For six of them the diffs were clean — straightforward import path updates, nothing surprising. On the seventh it had rewritten a route handler body that I hadn't asked it to touch. I have no idea why it decided to do that. But it was obvious immediately from the diff, so I rejected that one change and told it to only update the import. Done.
Without the diff preview I would have run the agent, assumed everything was fine, and discovered the rewritten handler the next time I ran the tests. With the diff preview I caught it in real time, in the same flow, without breaking stride.
When things go wrong anyway
Sometimes you approve something that turns out to be wrong. Maybe the diff looked fine but the logic was subtly broken. That's what undo is for.
You don't have to remember which file the agent touched or dig through git history. Just:
undo
It reverses the last applied change. Run it again to go back further. The agent tells you what it's restoring each time so you always know where you are in the stack.
If you undid something you actually wanted, redo puts it back. The stack survives as long as your session is open.
This pairs well with PlanMode
If you've been using lac agent's PlanMode, the undo system is the natural complement to it. PlanMode stops the agent from touching any files until you've reviewed and approved its plan. Diff preview and undo handle everything after you give the green light.
The full flow looks like this: describe the task, let the agent plan, approve the plan, watch the diffs, approve each file write, undo anything that went sideways. At every stage you have a clear exit ramp. That's the kind of safety net that makes it reasonable to use an agentic tool on code that actually matters.
Getting started
If you don't have lac-cli yet, install it with:
pip install lac-cli
or grab the shell installer:
curl -fsSL https://lacai.io/install.sh | bash
Then run lac agent in any project directory. The diff preview is on by default — you don't have to configure anything. Just start using it and pay attention to what shows up before each file write.
If you've been keeping the agent on a short leash because you didn't trust it with real files, give the undo stack a proper workout. Let it take on a bigger task than you normally would, catch anything odd in the diffs, and undo whatever doesn't look right. Once you've done that a few times the whole thing stops feeling risky and starts feeling like a fast, reviewable pair programmer.