Products Marketplace Blog About Contact Sign in Download
lac agent Undo: How I Recover When the AI Gets It Wrong

lac agent Undo: How I Recover When the AI Gets It Wrong

Agentic coding is fast — until the AI rewrites the wrong file and you're staring at a mess. lac agent's undo/redo and diff preview are the safety net I didn't know I needed until I actually needed it.

The moment you realize you needed an undo button

A few weeks ago I asked lac agent to refactor the auth middleware in a Node project. It did — fast. It also decided, on its own, to "clean up" a config file I hadn't touched in six months. The config worked fine. The "cleaned up" version did not.

Before I found the undo workflow, my recovery plan was: open Git, stare at the diff, figure out which hunks to reset, get it wrong, try again. It wasn't catastrophic but it was annoying and slow. Now I just type /undo and move on.

That's what this post is about — the undo/redo system inside lac-cli's agent, which I think is one of the most underrated parts of the whole tool.

What lac agent actually touches when it works

When you run lac agent and give it a task, it doesn't operate in a sandbox. It reads your real files, writes to your real files, and makes real changes. That's what makes it useful — it can actually do the work. But it also means a bad instruction or an overeager AI response can leave you with changes you didn't want across multiple files at once.

The agent tracks every file operation it makes during a session. Reads, writes, creations — all of it is logged internally. That log is what powers undo.

The diff preview before anything gets written

The part I use most isn't actually undo — it's the diff preview that happens before undo is even necessary.

When lac agent is about to write a file, it can show you a diff of exactly what it's going to change. You see the before and after side by side, and you decide whether to let it proceed. This is especially useful when the task is broad — "update all the service files to use the new logger format" — and you want to spot-check before committing to all of it.

If the diff looks wrong — maybe it changed a function signature you didn't ask it to touch — you reject that step. The agent doesn't write anything. You give it a correction and it tries again.

Combined with PlanMode, where the agent lays out the full plan before touching anything, this creates a pretty solid two-layer review: approve the plan, then review each diff as it executes. Most of the time you won't catch anything. But the times you do, it saves real time.

Using /undo when something already went through

Sometimes you approve a change, the agent writes it, and then five minutes later you realize it broke something downstream. Or you just changed your mind about the approach.

Inside an active lac agent session, type:

/undo

The agent reverts the last file write. It shows you what it reversed — the filename and a summary of what was restored. If you need to go back further, you can keep calling /undo to step back through the session history one change at a time.

Changed your mind about undoing? /redo reapplies it.

This is not a Git operation. It doesn't touch your commit history or staging area at all. It's the agent's own internal session history. Which means it works even if you haven't committed anything, and it doesn't interfere with whatever Git workflow you're already running.

Task tracking ties into this too

The agent also keeps a running task list for a session — what it's been asked to do, what it's completed, what's pending. This becomes useful alongside undo because you can see the sequence of operations clearly.

If I'm debugging a weird state — "wait, did it actually update that file or did I undo that?" — the task log tells me. No guessing about what state the project is in mid-session.

When I use this vs. just relying on Git

I still commit frequently. That's not going away. But /undo fills a different gap — it's for the short feedback loop inside a single working session, before things are commit-worthy.

The typical flow looks like this: I'm working on something, I give the agent a task, it writes three files, I look at one of them and something feels off. I don't want to reset my whole working directory. I just want to roll back that one thing, correct my instruction, and let it try again. That's exactly what /undo is for.

Git is for "I'm done with this chunk of work." Agent undo is for "wait, not like that."

A word on the /multi undo behavior

If you're using /multi mode — where tasks are split across 2 to 4 parallel agents — undo works differently. Instead of stepping back one change at a time, /undo in a /multi session reverts the entire session at once. All agents, all their writes, rolled back together.

That makes sense given the parallel nature of it. You can't really step through interleaved writes from four agents and expect a clean sequential undo. So it's all or nothing. Worth knowing before you start a big multi-agent run — make sure you've committed a clean state first, because the rollback is a full reset of that session.

Getting started

If you haven't installed lac-cli yet:

pip install lac-cli

Then launch the agent from your project root:

lac agent

Give it a task, watch the diffs, and if anything looks wrong — /undo. It's a small thing but it makes agentic coding feel a lot less risky. The speed is still there. You just have a net underneath.

We use cookies to keep you signed in and to serve ads via Google AdSense. By continuing to use this site you agree to our Privacy Policy.