# Plan, diff, verify: a 4-step loop that keeps AI coding agents from wrecking your repo

> Source: <https://dev.to/madgpt/plan-diff-verify-a-4-step-loop-that-keeps-ai-coding-agents-from-wrecking-your-repo-4bj6>
> Published: 2026-11-18 14:09:02+00:00

**Recommendation:** Make the coding agent propose a file-by-file plan and wait for approval, then have it do one plan item per step and explain the diff file by file, flagging assumptions.
More in the playbook "Working with AI coding agents": <https://wpnews.pro/playbooks/coding-agents>

Coding agents are fast. That's the problem. An agent that edits twelve files in forty seconds can also break twelve files in forty seconds, and you find out when the tests go red or, worse, when they don't.

I don't think the answer is "don't use agents". The answer is a loop that keeps you in charge. Here's the one I use.

Don't write code yet. List the files you'd change, what changes in each, and what could go wrong. Wait for my OK.

Read the plan like a pull request description. Wrong file list? Wrong assumption about the framework? You just saved yourself a 300-line diff. Most agent disasters are visible at this stage.

One plan item, one change. If the agent proposes "refactor auth and update the API and fix the tests", split it:

Do only item 1 from the plan. Stop after that.

A diff you can read in two minutes gets read. A diff you can't gets approved blind.

Explain this diff file by file. Mark anything you're not sure about, and anything you assumed without checking.

This is where invented function names and made-up config options show up. If the explanation is vague, the code usually is too.

The agent saying "this should work now" is not evidence. Evidence is:

You didn't write this code. Find the three most likely ways it fails in production.

Commit after every verified step. It costs ten seconds and turns "the agent broke something an hour ago" into a one-line revert.

**How do you keep agents on a leash?** I'd like to hear the rules other people use.

*Disclosure: I work on [MadGPT](https://madgpt.io), which includes a Coder model and a VS Code agent. The loop above works with any coding agent. Drafted with AI assistance, edited by a human.*
