How to start a project so AI can't break it: AGENTS.md, CI checks, branch protection and staging
By Menelaos Vergis · · Plan details checked against GitHub's and Anthropic's documentation on that date.
Set up five layers before the AI writes its first feature. An AGENTS.md file tells the agent your rules. CI checks prove each change still builds and passes its tests. Branch protection makes those checks impossible to skip, for the agent and for you. Secret scanning stops keys from reaching the repository. A staging environment with a human gate keeps mistakes away from real users.
Each layer catches a different kind of failure, and only the first one depends on the AI listening. The other four still work when it doesn't.
Key takeaways
- Instructions in AGENTS.md shape what the agent tries. They don't stop anything; enforced checks do.
- Branch protection with "include administrators" turns a red CI check into a wall nobody can push past, yourself included.
- On private repositories, branch protection needs GitHub Pro or Team, and GitHub's push protection needs a paid Secret Protection add-on. A free pre-commit scanner covers the gap.
- Keep production one deliberate step away: changes land on staging, and a person promotes them.
Why aren't instructions to the AI enough?
Because an agent can ignore an instruction, and nothing in a prompt can stop it. In July 2025, SaaStr founder Jason Lemkin was building an app with Replit's AI agent when it deleted his production database during a code freeze he had told it about (The Register, July 21, 2025). The instruction was there. Nothing enforced it.
The code itself needs checking too. Veracode tested more than 100 language models on 80 coding tasks and found that the generated code introduced a security vulnerability in 45% of cases (Veracode, July 30, 2025). Those were test tasks, not production apps, but the lesson carries: assume some AI changes are wrong, and build the project so a wrong change gets caught.
That's the idea behind the five layers. The first one guides the agent; the other four don't care what it was told.
Layer 1: AGENTS.md, the rules the agent reads first
AGENTS.md is a plain Markdown file at the root of your repository that tells AI coding agents how your project works. The agents.md site calls it "a README for agents". It's an open format read by Codex, Cursor, GitHub Copilot, Gemini CLI, Jules, Windsurf, Devin and many others.
Claude Code reads it too. Since version 2.1.277 it uses AGENTS.md directly when the project has no CLAUDE.md; if you already have a CLAUDE.md, put the line @AGENTS.md in it and both tools share one file (Claude Code docs: memory).
What to put in it
Write the rules a new developer would get wrong in their first week. Short and specific beats long and general. This website's own AGENTS.md has rules like these, each one written after a real mistake:
- "Every page needs
layout: homeorlayout: pagein its frontmatter." (Left out, a marketing page renders like a documentation page.) - "Link internally with markdown syntax, never a raw
<a href>tag." (A raw link works on my machine and breaks once deployed.) - "Run
npm run buildlocally before committing."
Add the project's hard limits too: where secrets live and that they never go in frontend code, which folders the agent must not touch, and how to run the tests. When the agent gets something wrong twice, that's a new rule.
What AGENTS.md can't do
It's advice. On a long task the agent may lose track of it, misread it, or decide a rule doesn't apply. My own global instructions to Claude Code say it shows me the diff and asks before every commit, and never promotes anything to production. It follows them well, but they're still instructions, which is exactly why the four layers below exist.
Layer 2: CI checks on every pull request
A CI check is a script that runs automatically on every change and fails loudly when something is wrong. On GitHub that's GitHub Actions: a YAML file in .github/workflows/ that installs your dependencies, builds the app and runs the tests.
Start with four steps: install, build, test, and a secret scan. Then add a check for every mistake you've seen twice. On BootForm, the form backend I build, every pull request runs four required checks: the .NET build and tests, and a build of each of the three frontends. A fifth job regenerates the OpenAPI spec from the real API and fails if it differs from the committed copy, because the API docs drifted out of date once and nobody noticed.
An agent fixes a failing check fastest when it can run that check itself, so put the exact commands in AGENTS.md too.
Mind the minutes
GitHub Actions minutes on private repositories are billed beyond your plan's allowance. In October 2026 BootForm's account hit its spending limit, which stopped every CI and deploy job at once. Since then CI runs on pull requests only, not again after the merge, and a path filter skips jobs whose code didn't change. Set a spending limit you're comfortable with, and design the workflow so hitting it isn't likely. Our post on stopping a surprise cloud bill covers the hosting side of the same problem.
Layer 3: branch protection, so nobody skips the checks
Branch protection makes the branch that deploys to production accept changes only through pull requests whose checks have passed. Without it, CI is a suggestion: an agent with push access can commit straight to main and the checks run after the damage is done.
On GitHub, open the repository's Settings, then Branches, and add a rule for your production branch:
- Require a pull request before merging.
- Require status checks to pass, and pick your CI jobs by name.
- Turn on Do not allow bypassing the above settings (the API calls it
enforce_admins), so the rule applies to administrators too. - Leave force pushes and deletions blocked.
Step 3 is the one people skip, and it's the one that matters for AI. Your agent usually works with your own credentials, so a rule that exempts admins exempts the agent. BootForm's main has enforce_admins on with all four checks required: a direct push is rejected for everyone, including me.
What it costs
On public repositories branch protection is free. On private repositories it's part of GitHub Pro for personal accounts and GitHub Team for organizations; GitHub Free leaves it out of private repositories (GitHub: plans). Rulesets, the newer and more flexible version, are described for GitHub Team and Enterprise customers. If your product's code is private and earns money, Pro is the cheapest insurance on this list.
Layer 4: secret scanning before a key leaks
Secret scanning looks for API keys, tokens and passwords in your code, and push protection blocks a push that contains one before it reaches GitHub (GitHub: about push protection). An agent asked to "just make it work" will happily paste a key straight into the code.
What you get depends on the repository:
- Public repositories: push protection for users is on by default for every GitHub account and stops you from pushing secrets to public repositories. Secret scanning alerts are free.
- Private repositories: push protection needs GitHub Secret Protection, an add-on at $19 per active committer per month (GitHub: security plans) that GitHub offers to organizations on Team or Enterprise.
If you're on a private repository without that add-on, run a scanner yourself. Gitleaks is open source and runs as a pre-commit hook on your machine and as a step in CI, which also catches what the agent commits. Pair it with the basics: keys in environment variables, .env in .gitignore, and a list of every key so you can replace one in minutes.
A key that was ever committed is leaked, even if a later commit removed it. Replace it; don't just delete the line.
Layer 5: staging, and a person who promotes to production
Staging is a copy of your app, with its own database and keys, where every change runs before real users see it. Production then changes only when a person decides it should.
BootForm's flow: merging to main deploys every app to a staging slot on Azure. Production changes only when I run a promotion workflow by hand, and that workflow checks which commit each slot is actually running and refuses to swap if staging holds older code than production. The agent can merge a pull request; it can't change what customers use.
You don't need Azure for this. On Vercel, every push to a branch other than production gets a preview deployment with its own URL (Vercel: environments). Supabase branching gives each branch a separate instance with its own API credentials, so a migration runs somewhere safe first (Supabase: branching) (each branch is billed as extra compute, which the cloud bill post explains). What matters:
- Separate data. The agent's experiments never touch the production database. This is exactly the line the Replit incident crossed.
- Separate keys. Staging uses test keys for payments and email.
- A human step. Promotion is a button or a command a person runs, never an automatic step the agent can trigger.
- Backups you have restored. If something still gets through, you can go back.
The five layers side by side
| Layer | What it catches | Cost | Setup time |
|---|---|---|---|
| AGENTS.md | Mistakes the agent would make for lack of context | Free | 30 minutes, then a line per lesson |
| CI checks | Broken builds, failing tests, drift | Free on public repos; private repos use Actions minutes | 1 to 2 hours |
| Branch protection | Anyone, agent or human, skipping the checks | Free on public repos; GitHub Pro or Team on private | 10 minutes |
| Secret scanning | Keys and tokens on their way into the repo | Free on public repos; $19 per committer per month on private, or a free scanner | 15 minutes |
| Staging + human gate | Bad changes and migrations reaching users | A second environment on your host | Half a day |
The order matters less than having all five. If you only have an afternoon, do branch protection and a CI build first: they turn every other check you add later into one that counts.
Frequently asked questions
Should I use AGENTS.md or CLAUDE.md?
AGENTS.md, if more than one AI tool touches the project, because most coding agents read it. Claude Code reads AGENTS.md directly when there's no CLAUDE.md, and a CLAUDE.md can import it with one line, @AGENTS.md, so you keep a single file.
Do I need branch protection if I work alone?
Yes, once an AI agent writes code for you. You aren't the only one pushing anymore: the agent pushes with your credentials, at any hour, as fast as it types. Branch protection with admins included is what makes a failing check stop it.
Is a free private GitHub repository enough?
For a side project, it's a start. For a product with users, it leaves out branch protection and push protection, the two layers that enforce the rest. Upgrade to GitHub Pro, or keep the code public, or at least run CI and a secret scanner yourself.
Check your own project
These five layers are items 23 to 25 of our free Ship Safe checklist, next to the checks for keys, database rules and spending caps that usually go wrong first. If you'd rather have someone else look, a Ship Safe audit goes through your repository and accounts, read-only, and tells you which layers are missing and what to fix first.
