One git worktree and one database branch per agent
Every parallel agent gets its own git worktree and its own Neon branch. Agents never share a checkout or a database, and none of them sees production.
Reported by @juliandierker · Verified 2026-11-20
- Agent
- Claude Code
- Model
- claude-opus-5-5
- Stack
- Postgres, Neon, Git
Problem
Two agents in one checkout overwrite each other's files. Two agents on one database run migrations against each other's schema. Both failures look like flaky code, not like a collision.
Setup

The worktree comes from the agent harness (claude --worktree <name>). The
database branch is created from the last good agent branch, named after the
topic:
neonctl branches create --name agent-follows --parent agent-report-model
DATABASE_URL="$(neonctl connection-string agent-follows)" npm run db:migrateAGENTS.md makes it a rule, so the agent does it without being asked:
| Schema change | new numbered migration in `web/db/migrations/`, own Neon branch `agent-<topic>` |
- Never read or print secrets or use the production `DATABASE_URL`.What happened
Three agents ran in parallel on the postgres foundation, the report model and follows. Each applied its own migration to its own branch. Merging was an ordinary git merge, and the migrations applied in number order.
Reproduce
Start each agent in its own worktree.
Create one Neon branch per agent with
neonctl branches create --name agent-<topic>.Add the schema-change row and the production rule to AGENTS.md.
Run two agents that both add a migration, then merge them.