agentleFS
neondatabaseneondatabase/agent-skills/skills/neon-postgres-branches/SKILL.md

neon-postgres-branches

Skill108 starsChanged 17 days agoApache-2.0View on GitHub

Choose and create the right Neon branch type for testing and development. Use when users ask about Neon branching, migration testing with real data, isolated test environments, schema-only branch workflows for sensitive data, resetting a branch from its parent, branch expiration and CI/CD branch lifecycles, or branch creation via Neon CLI or Neon MCP. Triggers include "Neon branch", "test migrations safely", "branch production data", "schema-only branch", "reset branch", "branch per PR" and "sensitive data testing".

  • Reads credentials
  • Installs packages

We split this skill into the rules it gives an agent

39 rules. About 0 are common, 28 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈28

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    FIRST: Use the parent neon skill for a Neon overview, getting started with Neon, Neon development best practices, and more.

    line 17
  2. Very specific:

    If the neon skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:

    line 19
  3. Distinctive:

    Use this decision rule first:

    line 34
  4. Distinctive:

    If the user wants to test complex migrations, performance, or behavior against production-like data, choose a normal branch.

    line 36
  5. Distinctive:

    If the user needs to avoid copying sensitive data, choose a schema-only branch.

    line 37
  6. Distinctive:

    If the request is ambiguous, ask one clarifying question: "Do you need realistic data for testing, or only schema structure because the …

    line 39
  7. Distinctive:

    Check the CLI first:

    line 51
  8. Very specific:

    Run neon --version to confirm the CLI is installed.

    line 52
  9. Very specific:

    Run neon projects list to confirm auth/context.

    line 53
  10. Distinctive:

    If the CLI is missing, direct installation via quickstart.

    line 54
  11. Very specific:

    If the CLI is installed but not authenticated, guide the user through neon auth (or API key auth), then continue.

    line 55
  12. Distinctive:

    If neither path is successful, use the Neon REST API:

    line 57
  13. Very specific:

    Use branch tools (for example, create_branch) to create the branch.

    line 63
  14. Distinctive:

    Use this when the user needs realistic testing conditions.

    line 69
  15. Very specific:

    Ensure project context is set (neon set-context --project-id <your-project-id>) or include --project-id on commands.

    line 77
  16. Distinctive:

    Use this when users must not copy production rows into the test branch.

    line 95
  17. Distinctive:

    Create the schema-only branch:

    line 102
  18. Very specific:

    If multiple projects exist, include --project-id:

    line 112
  19. Distinctive:

    Ask them to share feedback in the Neon Console:

    line 127
  20. Distinctive:

    Use this when a child branch has drifted and the user wants a clean refresh from the parent branch's latest schema and data.

    line 134
  21. Distinctive:

    Does not merge; local changes on the child branch are lost.

    line 141
  22. Distinctive:

    Only child branches can be reset (root branches and schema-only root branches cannot be reset from parent).

    line 152
  23. Distinctive:

    If the target branch has children, reset is blocked until those child branches are removed.

    line 153
  24. Distinctive:

    After a parent branch is restored from snapshot, reset-from-parent may be unavailable for up to 24 hours.

    line 154
  25. Distinctive:

    If project context is not already set, include the project ID:

    line 163
  26. Very specific:

    API: Use the restore endpoint for the branch and set source_branch_id to the parent branch ID.

    line 180
  27. Distinctive:

    If a user is unsure, default recommendation is:

    line 188
  28. Distinctive:

    If the user asks for process recommendations (not just a single command), suggest these:

    line 194
  29. Distinctive:

    One branch per PR: Create branch when PR opens, delete when merged/closed, keep migration tests isolated.

    line 196
  30. Distinctive:

    One branch per test run: Create branch at pipeline start, run migrations/tests, delete at end for deterministic CI.

    line 197
  31. Distinctive:

    PII-aware branching: If production has sensitive data, derive dev/PR branches from an anonymized branch or use schema-only branches.

    line 199
  32. Distinctive:

    After branch creation, ask whether the user wants to update local environment credentials to point at the new branch.

    line 204
  33. Very specific:

    Ask: "Do you want me to update your .env DATABASE_URL to this new branch connection string?"

    line 206
  34. Distinctive:

    If yes, write the new branch connection string to the requested env file/key.

    line 207
  35. Distinctive:

    If no, leave credentials unchanged and share the connection string for manual use.

    line 208
  36. Distinctive:

    Never overwrite an existing env key without explicit confirmation.

    line 209
  37. Distinctive:

    Migration testing in CI: Run risky schema changes against a branch with production-like data before merge.

    line 254
  38. Distinctive:

    Schema diff visibility: Use the schema-diff GitHub Action to auto-comment a DB-layer diff on the PR.

    line 255
  39. Very specific:

    Check the tool path first (CLI with neon --version.

    line 267

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

FIRST: Use the parent neon skill for a Neon overview, getting started with Neon, Neon development best practices, and more.

If the neon skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:

neon skills -s neon -y

Lakebase Postgres Branching

Outcome: a created Neon branch — or a clear, actionable next step if creation cannot proceed. Choose the correct branch type, then execute branch creation with the CLI (or MCP where the CLI isn't usable).

  • Normal branch for realistic migration and query testing with real data.
  • Schema-only branch (Beta) for sensitive data workflows where structure is needed without copying rows.

Branch Type Decision

Use this decision rule first:

  1. If the user wants to test complex migrations, performance, or behavior against production-like data, choose a normal branch.
  2. If the user needs to avoid copying sensitive data, choose a schema-only branch.

If the request is ambiguous, ask one clarifying question: "Do you need realistic data for testing, or only schema structure because the data is sensitive?"

Tool Selection: CLI or MCP

Support both the Neon CLI and the Neon MCP server, but default to the CLI. Use MCP only when the CLI is unavailable or blocked in your environment, cannot be authenticated, or the user explicitly asks for MCP.

Selection order

  1. Check the CLI first:
    • Run neon --version to confirm the CLI is installed.
    • Run neon projects list to confirm auth/context.
  2. If the CLI is missing, direct installation via quickstart.
  3. If the CLI is installed but not authenticated, guide the user through neon auth (or API key auth), then continue.
  4. Switch to MCP when the CLI cannot be used — no CLI access in the environment, execution blocked, or authentication not possible — or when the user explicitly asks for MCP. Confirm Neon MCP tools are available and authenticated (for example, listing projects works), then follow the MCP branch flow below.
  5. If neither path is successful, use the Neon REST API:

MCP branch flow

  1. Choose normal vs schema-only based on data sensitivity and migration-testing goals.
  2. Use branch tools (for example, create_branch) to create the branch.
  3. Validate with read tools (for example, describe_branch).
  4. For migration workflows, prefer branch-based migration flows before applying to main.

Create a Normal Branch (Preferred for Real-Data Migration Testing)

Use this when the user needs realistic testing conditions. Real production-like data can expose edge cases your seed or data migration scripts miss, which helps catch migration issues before going live.

Link: https://neon.com/docs/introduction/branching.md

Steps

  1. Settle the tool path first (see Selection order): verify the CLI with neon --version, and fall back to MCP only if the CLI isn't usable.
  2. Ensure project context is set (neon set-context --project-id <your-project-id>) or include --project-id on commands.
  3. Create the branch:

    neon branches create \
      --name <branch-name> \
      --parent <parent-branch-id-or-name> \
      --expires-at 2026-12-15T18:02:16Z
  4. Optionally fetch a connection string for the new branch:

    neon connection-string <branch-name>

Create a Schema-Only Branch (Beta, Sensitive Data)

Use this when users must not copy production rows into the test branch.

Link: https://neon.com/docs/guides/branching-schema-only.md

Steps

  1. Settle the tool path first (see Selection order): verify the CLI with neon --version, and fall back to MCP only if the CLI isn't usable.
  2. Create the schema-only branch:

    neon branches create \
      --name <schema-only-branch-name> \
      --parent <parent-branch-id-or-name> \
      --schema-only \
      --expires-at 2026-12-15T18:02:16Z

    If multiple projects exist, include --project-id:

    neon branches create \
      --name <schema-only-branch-name> \
      --parent <parent-branch-id-or-name> \
      --schema-only \
      --project-id <your-project-id> \
      --expires-at 2026-12-15T18:02:16Z

Beta Support Guidance (Mandatory)

Schema-only branching is in Beta. If users report unexpected behavior, errors, or missing capabilities:

  1. Ask them to share feedback in the Neon Console:
  2. Recommend opening a support conversation in the Neon Discord:

Reset from Parent

Use this when a child branch has drifted and the user wants a clean refresh from the parent branch's latest schema and data.

Link: https://neon.com/docs/guides/reset-from-parent.md

What it does

  • Fully replaces the child branch schema and data with the parent's latest state.
  • Does not merge; local changes on the child branch are lost.
  • Keeps the same connection details, but active connections are briefly interrupted during reset.

When to recommend it

  • Development or staging branch is too far behind production.
  • User wants to start a new feature from a clean parent-aligned state.
  • Team wants to refresh staging from production for consistent testing baselines.

Hard constraints and blockers

  • Only child branches can be reset (root branches and schema-only root branches cannot be reset from parent).
  • If the target branch has children, reset is blocked until those child branches are removed.
  • After a parent branch is restored from snapshot, reset-from-parent may be unavailable for up to 24 hours.
  • Reset-from-parent always uses the current parent state; use Instant restore for point-in-time recovery needs.

CLI usage

neon branches reset <id|name> --parent --preserve-under-name <backup-branch-name>

If project context is not already set, include the project ID:

neon branches reset <id|name> --parent --preserve-under-name <backup-branch-name> --project-id <project-id>

--preserve-under-name keeps the pre-reset state as a backup branch for rollback, but adds one extra branch to clean up later.

Optional context setup to avoid repeating --project-id:

neon set-context --project-id <project-id>

Console and API usage

  • Console: Open the target child branch, then select Reset from parent from Actions.
  • API: Use the restore endpoint for the branch and set source_branch_id to the parent branch ID.

Notes and Caveats

  • Schema-only branches are for structure-only cloning and sensitive/compliant data controls.
  • Schema-only branches are independent root branches (no parent branch and no shared history), so reset-from-parent does not apply.
  • For migration testing that depends on real-world row shapes, volumes, and edge cases, prefer normal branches.
  • Root branch allowances and per-branch storage limits can cap how many schema-only branches users can create.
  • If a user is unsure, default recommendation is:
    • Normal branch for migration validation.
    • Schema-only branch for compliance and privacy constraints.

Useful Workflow Patterns

If the user asks for process recommendations (not just a single command), suggest these:

  • One branch per PR: Create branch when PR opens, delete when merged/closed, keep migration tests isolated.
  • One branch per test run: Create branch at pipeline start, run migrations/tests, delete at end for deterministic CI.
  • One branch per developer: Isolated dev environments with production-like shape; avoid team collisions on shared test data.
  • PII-aware branching: If production has sensitive data, derive dev/PR branches from an anonymized branch or use schema-only branches.
  • Ephemeral lifecycle hygiene: Set branch expiration and automate cleanup so old branches do not accumulate avoidable storage/history cost.

Post-creation environment update prompt

After branch creation, ask whether the user wants to update local environment credentials to point at the new branch.

  • Ask: "Do you want me to update your .env DATABASE_URL to this new branch connection string?"
  • If yes, write the new branch connection string to the requested env file/key.
  • If no, leave credentials unchanged and share the connection string for manual use.
  • Never overwrite an existing env key without explicit confirmation.

Neon Infrastructure as Code (neon.ts)

Beyond creating branches imperatively (CLI / MCP / API above), you can program what configuration new branches receive declaratively in neon.ts — Neon's infrastructure-as-code file (see the neon skill for the full reference). The branch property is a function of the branch being evaluated that returns its settings, so every branch born from your project gets a consistent lifecycle and compute profile without per-branch flags.

npm i @neon/config
// neon.ts
import { defineConfig } from "@neon/config/v1";

export default defineConfig({
  branch: (branch) => {
    if (branch.exists) return {}; // never reconcile existing branches
    if (branch.isDefault) return { protected: true };
    if (branch.name.startsWith("preview/") || branch.name.startsWith("dev")) {
      return {
        parent: "main",
        ttl: "7d", // ephemeral: auto-expire 7 days after creation (max 30d)
        postgres: {
          computeSettings: {
            autoscalingLimitMinCu: 0.25, // scale to zero
            autoscalingLimitMaxCu: 1, // keep throwaway branches cheap
            suspendTimeout: "5m",
          },
        },
      };
    }
    return {};
  },
});

The closure receives a read-only descriptor of the target branch — name, exists, isDefault, parentId, and more — and returns the tuning to apply: parent, ttl (auto-expiry), protected, and postgres.computeSettings. This is the declarative complement to the Ephemeral lifecycle hygiene and per-PR / per-test patterns above: instead of remembering --expires-at on every neon branches create, the TTL and compute profile live in version control and apply to every matching branch.

Because neon checkout applies this policy when it creates a branch, a fresh preview/* or dev-* branch comes up already expiring and scaled-to-zero. Checking out an existing branch doesn't reconcile it — run neon deploy (alias for neon config apply) to apply changes to a branch that already exists.

Branching in CI/CD

Common CI/CD use cases for Neon branches:

  • Per-PR preview deployments: Branch on PR open, deploy the preview against it, delete on close. Each PR gets an isolated database branch. Injecting the branch's DATABASE_URL into the deployed app is hosting-provider-specific — see preview-branches-with-cloudflare, preview-branches-with-vercel, or preview-branches-with-fly for tested patterns.
  • Migration testing in CI: Run risky schema changes against a branch with production-like data before merge.
  • Schema diff visibility: Use the schema-diff GitHub Action to auto-comment a DB-layer diff on the PR.

Examples

Example 1: Migration testing with realistic data

User input: "I need to test a risky migration against production-like data."

Agent output shape:

  1. Recommend a normal branch and explain why.
  2. Share docs link: https://neon.com/docs/introduction/branching
  3. Check the tool path first (CLI with neon --version; MCP only if the CLI isn't usable).
  4. Provide commands:
    • neon branches create --name migration-test --parent main --expires-at 2026-12-15T18:02:16Z
    • neon connection-string migration-test

Example 2: Sensitive data development workflow

User input: "We cannot copy production data because of compliance."

Agent output shape:

  1. Recommend schema-only branch and explain why.
  2. Share docs link: https://neon.com/docs/guides/branching-schema-only
  3. Check the tool path first (CLI with neon --version; MCP only if the CLI isn't usable).
  4. Provide command:
    • neon branches create --name compliance-dev --parent main --schema-only --project-id <your-project-id> --expires-at 2026-12-15T18:02:16Z
  5. Mention Beta support path:

Further Reading

Download now (ZIP)

Trending

Surging: 3 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Aug 30: 0 new projectsWeek of Sep 6: 0 new projectsWeek of Sep 13: 0 new projectsWeek of Sep 20: 0 new projectsWeek of Sep 27: 2 new projectsWeek of Oct 4: 1 new projectWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projects
Aug 2026Sep 2026Oct 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 3 in all, so this is a hint, not a trend.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.