Agents write a lot of code now, and they write it quickly. Speed is not the problem. The problem is that more changes in flight means more chances to merge something wrong. What keeps that safe is not a smarter agent. It is a set of gates that every change has to pass, written down so that agents and people follow the same ones.

I use four: automated tests, an AI reviewer, recorded verification and a human decision. This article is about the practices behind them, the ones that decide whether a gate means anything.

Write the rules down where the agent reads them

Agent rules files, such as CLAUDE.md or AGENTS.md, are the cheapest control you can add. They sit in the repository, every session reads them, and they replace the knowledge that used to live in people's heads.

A useful rules file is short and specific. It says how to run the project's checks, what a finished change looks like, which commands are off limits, and which decisions belong to a person. It does not try to describe the whole codebase. Rules that are vague ("write clean code") do nothing. Rules that are testable ("never push to the main branch", "use the repository's existing scripts instead of hand-rolled commands") change behavior.

When an agent makes a mistake, the fix is usually a new line in the rules file, not a lecture. Treat the file as the place where lessons accumulate.

Reproduce before fixing

Before an agent fixes a bug, it should reproduce it. This sounds obvious and is routinely skipped. Without a reproduction, you cannot tell whether the fix fixed anything, and an agent will happily explain a plausible cause that is not the real one.

The rule is simple: see the failure first, then change the code, then see the failure go away. A test watched failing and then passing is evidence. A diff that looks right is an opinion.

A check only counts if it can fail

A passing check proves something only if it was capable of failing. Agents are good at writing tests that pass for the wrong reason: assertions that cannot be false, mocks that return what the test expects, checks that run against nothing.

The defense is to plant a failure. Break the thing on purpose, or compare the check against a fact you already know, and confirm the check goes red. If it does not, it was decoration.

Exit 0 is not success

A command that exits cleanly told you it did not crash. It did not tell you it did the job. A deploy script can exit 0 and leave the old version running. A migration can exit 0 and change nothing.

The habit is to read the resource back. After a deploy, request the page and check the version. After a migration, query the table. After creating a cloud resource, fetch it and look at its settings. The agent's report that it worked is a claim; the read-back is the proof.

Targeted checks locally, full suites in CI

Agents run on a developer's machine or in sessions that share one. If every session runs the full build and the full test suite, the machine saturates and everyone waits. So the split is deliberate.

  • Locally: lint, a type check, the single spec that covers the change.
  • In CI: full builds and the full suite, on a clean machine, where the result is the one that counts.

Local checks give fast feedback while the agent works. CI is the gate. Neither replaces the other, and the pull request should say which ran where.

Pull request bodies carry the evidence

A reviewer, human or AI, should not have to take the author's word for anything. The pull request body is where the evidence travels: what changed, which checks ran locally, which were left to CI, what was reproduced and what the output showed. If the author made a judgment call inside the approved scope, the body says so.

This changes review from reading a diff and hoping to checking proof. It also makes it obvious when a pull request has none.

Keep the human decision

The last gate is a person. Product calls, scope changes, production access and anything hard to reverse are not delegated. Agents propose; people decide. That line is what makes it safe to run many agents at once, because the worst an agent can do is propose something a person declines.

Two smaller rules support it. Do not reduce scope silently: if an agent is blocked, it says what and why instead of shipping a stub. And when a reviewer flags one instance of a problem, sweep the whole class, so the same mistake does not come back in the next pull request.

How to start

  1. Add a rules file with your check commands, your definition of done and the decisions that stay human.
  2. Require tests and type checks in CI before merge.
  3. Add an AI reviewer that reads the diff against those rules.
  4. Ask for evidence in every pull request body.
  5. Plant a failure in one of your checks this week and see whether it catches it.

None of this is exotic. It is ordinary engineering discipline, written down so that a machine can follow it as well as a person. The agents supply the speed. The gates supply the confidence to merge it.