Field Guides / Set up coding agents with review gates
Setup guide · last checked December 2, 2026
Set up coding agents with review gates.
Let agents write the code, and let tests, CI and a few written rules decide what merges.
For small software teams starting to use coding agents. It is how I run my own repositories, where agents write most of the code and I review what matters. It works with any agent that reads files in your repo and opens pull requests, and the examples use GitHub because most teams do.
Step 1
What changes
Writing code stops being the slow part. Reviewing it, and knowing it works, takes its place.
- More code, less stability. Google’s 2025 DORA report, from a survey of nearly 5,000 technology professionals, found AI adoption now improves software delivery throughput but still increases delivery instability (DORA 2025).
- Feeling faster isn’t being faster. In a randomized trial with experienced open-source developers on their own repositories, people took 19% longer with AI tools allowed, yet afterwards believed AI had sped them up by 20% (METR, July 2025). Measure it (Step 8).
- Tests become the contract. You can’t read every line an agent writes as closely as your own. The tests and checks are what tell you a change does what it says, so they are the first thing to invest in.
- Small changes win. DORA found AI’s benefits depend on teams working in small batches: fewer lines per change, and work that finishes quickly (DORA 2025).
Step 2
Put the rules in the repo
An agent starts each session knowing nothing about your project. A rules file it reads every time is how it learns.
Most agents read a Markdown file at the root of the repo. AGENTS.md is an open format used by over 60,000 open-source projects, and GitHub Copilot reads it, with the nearest file in the directory tree taking precedence (GitHub Docs). Some tools use their own name, such as CLAUDE.md for Claude Code (Claude Code docs).
- Put in: how to install, build and test; the one command that verifies a change; the conventions a linter can’t enforce; the folders and files an agent must not change without asking; and where the longer docs live.
- Leave out: secrets, long history, anything a linter or formatter already enforces, and anything that is only true this week.
- Keep it short. It loads into every session. Anthropic’s docs say the more specific and concise the instructions, the more consistently Claude follows them (Claude Code docs). I keep mine an index that points to detail in
docs/.
Step 3
One task, one branch, one pull request
Size each task so a person can review the result in one sitting.
- Write the task like a ticket: what is wrong or wanted, what done looks like, and how to check it. A vague task gets a large, vague pull request.
- One branch and one pull request per task. If a task grows, split it and finish the first part.
- Run sessions in parallel, apart. Two agents in one folder will trip over each other’s edits. Git’s
worktreecommand gives each session its own working folder on its own branch, attached to the same repository (Git docs).
Step 4
Make CI the gate
Nothing reaches the main branch except through a pull request whose checks passed.
- Require the checks. Branch protection can require status checks to pass before merging. In “strict” mode the branch must also be up to date with the base branch, so the checks ran against what will actually merge (GitHub Docs). A merge queue gives the same assurance without each author updating their branch by hand (GitHub Docs).
- One verify command. The same command runs on the agent’s machine and in CI: tests, type checks, linters, the build. If it passes locally and fails in CI, fix that first.
- Never skip a test to get green. Say so in the rules file. In my experience, an agent stuck on a failing test will sometimes skip it or weaken it instead of fixing the code.
- A failing main branch stops the line. Fix or revert before anything else merges.
Step 5
Decide what an agent may merge
Not every change needs a person, and some always do. Write the line down before the first pull request.
| Class | Examples | Who merges |
|---|---|---|
| Routine | Tests, docs, a bug fix with a failing test, a refactor with no change in behaviour, patch-level dependency updates. | The agent, once every required check passes. |
| Sensitive | Sign-in and permissions, payments, data migrations or deletion, CI and deployment config, public-facing copy, major dependency upgrades, and the agent’s own rules and permissions. | A person, after reading the diff. |
| Decision | A new feature outside the product’s scope, pricing, anything users can’t undo. | Nobody builds it until a person decides. |
An example split, not a standard. Start stricter than you think you need, and loosen a class once its record earns it.
- Enforce it where you can. A
CODEOWNERSfile names who owns which paths, and with required reviews turned on, a pull request can’t merge without a code owner’s approval (GitHub Docs). - When unsure, use the stricter class. And put the agent’s own rules and permissions in the sensitive class, so it can’t loosen them itself.
Step 6
Memory and handoffs
Sessions end. The work has to survive them.
- Lasting facts go in the repo. Anything every future session needs belongs in the rules file or
docs/, reviewed like code. - Work in progress goes in the pull request or ticket: what changed, what the agent checked and how, and what is left. The next session, or a person, starts from there.
- Prune it. Memory that is out of date is worse than none: the agent will act on it. When a rule changes, change the file in the same pull request.
Step 7
Secrets and permissions
An agent can do whatever its tokens allow. Give it less.
- Fine-grained tokens. GitHub recommends fine-grained personal access tokens, which you can restrict to specific repositories and permissions (GitHub Docs). Give agent tokens an expiry date.
- Least privilege in CI. Limit the permissions of the token your workflows get to the minimum each job needs (GitHub Docs).
- Block secrets at the push. Push protection blocks pushes that contain secrets before they reach the repository (GitHub Docs). Keep real credentials out of the agent’s environment unless a task needs them.
- Limit what it can run. OWASP lists excessive agency, meaning more functionality, permissions or autonomy than the task needs, as a top risk for AI applications (OWASP LLM06:2025). Most agents support allow and deny rules for commands and files; Claude Code, for example, checks deny rules first (Claude Code docs).
- Treat what it reads as untrusted. An issue, a comment or a web page can carry instructions that steer the model (OWASP LLM01:2025). Don’t let text from strangers direct an agent that holds write access.
- Check new dependencies. In a study of 576,000 generated code samples, models recommended packages that don’t exist: at least 5.2% for commercial models and 21.7% for open-source ones (USENIX Security 2025). Someone can register that name. Make sure every new dependency is real and the one you meant.
Step 8
Measure cost and quality
Decide with numbers, not with how fast it feels.
- Quality: DORA’s delivery metrics include change lead time, deployment frequency, change fail rate and how long recovery takes (DORA). Track at least the change fail rate and how often you revert an agent’s change.
- Cost: divide what you spend on agents by the changes that merged. For scale, Anthropic reports Claude Code averages about $13 per developer per active day across enterprise deployments, and below $30 for 90% of users (Claude Code docs). Your own number is the one that matters.
- Review time: watch how long pull requests wait for a person. If it grows, tasks are too big or the risk classes are too strict.
Setup checklist
Twelve things to be able to say before agents merge anything on their own.
- Rules. A rules file in the repo says how to build, test and verify, and what the agent must not touch.
- Verify. One command runs every check, and it passes on the main branch today.
- Tests. A bug fix starts with a test that fails before the fix.
- Tasks. Each task fits one branch and one pull request a person can review in one sitting.
- Parallel. Parallel sessions each work in their own branch and working folder.
- Gate. The main branch takes changes only through pull requests whose required checks passed on an up-to-date branch.
- Classes. Written risk classes say which changes an agent may merge and which wait for a person.
- Owners. Sensitive paths have named owners whose review is required.
- Handoffs. Every session leaves what changed, what it checked and what is left in the pull request or ticket.
- Tokens. Agent tokens reach only the repositories and permissions they need, and they expire.
- Secrets. Pushes that contain credentials are blocked before they reach the repository.
- Measure. Cost per merged change and the change fail rate are reviewed every month.
On paper: the printable checklist has these twelve lines with space to sign each one off.
Honest limits
What this setup won’t do, so nobody is surprised.
- Gates catch only what they test. In Veracode’s 2025 tests, AI-generated code introduced risky security flaws in 45% of tests (Veracode). Without security checks in CI, those flaws pass a green build.
- Review is still work. Agents move the effort from writing to reviewing. A team that can’t keep up with review should slow the agents down, not skim.
- It needs an owner. Rules files, tokens and risk classes drift. Someone has to read the numbers from Step 8 and change the setup.
- Results vary. The studies above measured particular tools, people and code at a point in time (METR). Try it on a small part of your work before you change everything.
If you’d like this set up on your repository, with the rules, CI review and a walkthrough on your own code, that is my Agent Workflow Setup.
Sources and method
Written by Matthew Bonham with AI drafting assistance. Every fact on this page links to its source, and the sources below were last checked on December 2, 2026. The steps, risk classes and checklist are my recommendations from my own work, not a standard or any vendor’s guidance.
- Research: DORA, 2025 State of AI-assisted Software Development; DORA’s software delivery metrics; METR, early-2025 AI and experienced open-source developers; Spracklen et al., package hallucinations (USENIX Security 2025); Veracode 2025 GenAI Code Security Report.
- Rules files and agents: AGENTS.md; GitHub Copilot repository instructions; Claude Code memory; Claude Code permissions; Claude Code costs; git worktree.
- Gates and access: GitHub protected branches; GitHub code owners; GitHub token permissions in Actions; GitHub personal access tokens; GitHub push protection; OWASP LLM06:2025 Excessive Agency; OWASP LLM01:2025 Prompt Injection.
No affiliation with any project, vendor or agency named here is implied. Spot an error or an out-of-date detail? Tell me.