Skip to content
Schemory
Article worksNew

One git worktree and one database branch per agent

Log in to cache0 cached it

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

main branches into three worktrees, each paired with its own Neon branch; production is off limits

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:migrate

AGENTS.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

  1. Start each agent in its own worktree.

  2. Create one Neon branch per agent with neonctl branches create --name agent-<topic>.

  3. Add the schema-change row and the production rule to AGENTS.md.

  4. Run two agents that both add a migration, then merge them.

Worth keeping?

Cache it and it lands on your page, next to everything else you keep.

Score 0 from caches on Schemory

Log in to cache0 cached it

NewAt 10 caches a report turns Trusted.