Instructions for agents
Everything on this site is a set of habits a careful engineer picks up over time. A coding agent has none of them, but it follows written rules well. This page is the AGENTS.md we recommend, so an agent can make schema changes on its own and tell you clearly what it did and what it left for you to decide.
Two files: AGENTS.md, the instructions, and check-database, a script the instructions tell the agent to run before it finishes.
Why agents need it written down
Asked to "add a currency to invoices", an agent with no instructions does what most of the internet does: writes 0042_add_currency.sql with an alter table, maybe edits the table's file too, and calls it done. Every habit on this site is invisible from the code alone:
- that the table's file must never contain an
alter, and is changed by a rework; - that
@tagfiles look like ordinary SQL and must never be touched; - that adding an argument with
create or replace functionmakes a second function and breaks every caller; - that a
sqitch.planconflict is resolved by regenerating, not by keeping both sides; - that some decisions, like a table rewrite or dropping a column, are not the agent's to make.
The file writes those down, in the order an agent needs them: where things are, which workflow fits the task, the rules, how to check, when to stop, and what to report.
Install it
- Add the instructions. Save AGENTS.md at the root of your repository. Codex and most other agents read
AGENTS.mdon their own. If you already have one, paste it in as a section. For Claude Code, add a line toCLAUDE.mdthat imports it:@AGENTS.md
- Add the check. Save check-database as
scripts/check-databaseand make it executable. Run it yourself once to see it pass. - Fill in the details. Replace the guide URL placeholder, and change
masterif your main branch has another name. If your services are not written in Haskell, delete the hasql-check line. - Give the agent the tools. sqitch, sqiff, sqint, create-migration, psql and a PostgreSQL it may create scratch databases on, with
PG*variables pointing at it. With Nix:nix shell nixpkgs#sqitchPg nixpkgs#postgresql_18 \ github:kronor-io/sqiff github:kronor-io/sqint github:kronor-io/sqitch-with-templates
What the file says
| Section | What it gives the agent |
|---|---|
| Where things are | The layout, and the instruction to read an object's definition instead of reconstructing it from migrations. |
| Choose the workflow | A table from task to command: create an object, change a table, change a function or view, the multi-release recipes. Where a rule goes: constraints and types first, then views, functions and statecharts. Commands are given with every flag, because create-migration prompts when one is missing and sqitch opens an editor without -n. |
| Model a process | When rows go through a process, a statechart, never a status column, enum or flags. The signs that a task is a process, how to change a chart, and that late and duplicate events are left to the chart rather than turned into errors. |
| Code that talks to the database | The runtime rules from practices: every write at SERIALIZABLE through one retrying function, no calls to other systems while a transaction is open, idempotency keys inserted before they are read, and queues claimed with skip locked. |
| Rules | The nevers and alwayses from the layout, functions and shipping safely, stated without exceptions. |
| Merging and rebasing | The regenerate-don't-merge procedure from git and review, and why a stale snapshot matters. |
| Check before you finish | One command, and what to do with sqint's findings: fix BLOCKs, never write a lint:ignore itself. |
| Stop and ask | The judgement calls: rewrites, data loss, renames, backfills of unknown size, conflicts in lines already on the main branch. |
| Report | What changed, every hazard and what was done about it, which release each part belongs to, and every check with its result. |
Two choices are deliberate. The agent may not suppress a lint finding: a lint:ignore records a human's decision, and an agent writing one defeats the point. And it reports the hazards it accepted instead of silently accepting them, so the reviewer reads them first.
The check script
An agent is only as careful as the check it runs at the end. scripts/check-database puts the important checks behind one command, so the instructions can say "run this" rather than describe a procedure:
$ scripts/check-database
== sqint: deploy scripts changed since master
== pgfmt: SQL files changed since master
== the plan only grows
== snapshots are not edited
== fresh database: deploy the whole plan
Deploying changes to db:pg:check_database_scratch
+ base_schemas ................................................. ok
…
+ migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
== revert this branch's 2 changes and deploy them again
- migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
+ migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
== database checks passed
It reverts the branch's changes by counting them back from the end of the plan (sqitch rebase --onto @HEAD^2), not by name, because a reworked change's name is ambiguous. It leaves out sqint's dynamic pass, which needs the base branch deployed first; CI runs that. Run it in CI too, so the agent's check and the merge check are the same.
Guardrails outside the file
Instructions are followed most of the time. For the things that must never happen, do not rely on them alone.
- No production credentials. The agent's environment should reach a local or scratch PostgreSQL and nothing else. Keep production targets out of
sqitch.conf; let your deploy pipeline hold them. - The pre-commit hooks from shipping safely catch edited snapshots and rewritten plan lines whoever makes them.
- Review stays human. The agent's report is written for the reviewer: hazards first, then the checks. A pull request that changes the schema still needs a person to accept its costs.
The file
AGENTS.md (download)
Loading agents/AGENTS.md…