Agent Skill · Neon

neon-postgres-branches

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, or branch creation via Neon CLI or Neon MCP. Triggers include "Neon branch", "test migrations safely", "branch production data", "schema-only branch", "reset branch" and "sensitive data testing".

Provider: Neon Path in repo: skills/neon-postgres-branches/SKILL.md

Skill body

Neon Postgres Branching

The outcome of this skill should be a created Neon branch (or a clear, actionable next step if creation cannot proceed). Choose the correct branch type, then execute branch creation via MCP or CLI.

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

Always support both Neon CLI and Neon MCP server. Prefer the tool the user already has installed and authenticated.

MCP link: https://neon.com/docs/ai/neon-mcp-server.md CLI link: https://neon.com/docs/reference/cli-quickstart

Selection order

  1. Check MCP first in MCP-enabled environments:
    • If Neon MCP tools are available and authenticated (for example, listing projects works), use MCP.
  2. If MCP is unavailable or not authenticated, check CLI:
    • Run neonctl --version to confirm CLI is installed.
    • Run neonctl projects list to confirm auth/context.
  3. If CLI is missing, direct installation via quickstart.
  4. If CLI is installed but not authenticated, guide the user through neonctl auth (or API key auth), then continue.
  5. If both MCP and CLI paths are unsuccessful, use the Neon REST API:
    • https://neon.com/docs/guides/branching-neon-api.md

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. Use MCP if already available/authenticated; otherwise verify CLI with neonctl --version.
  2. Ensure project context is set (neonctl set-context --project-id <your-project-id>) or include --project-id on commands.
  3. Create branch:
neonctl branches create \
  --name <branch-name> \
  --parent <parent-branch-id-or-name> \
  --expires-at 2026-12-15T18:02:16Z
  1. Optionally fetch a connection string for the new branch:
neonctl 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. Use MCP if already available/authenticated; otherwise verify CLI with neonctl --version.
  2. Create schema-only branch:
neonctl 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:

neonctl 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:
    • https://console.neon.tech/app/projects?modal=feedback
  2. Recommend opening a support conversation in the Neon Discord:
    • https://discord.gg/92vNTzKDGp

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

When to recommend it

Hard constraints and blockers

CLI usage

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

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

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

neonctl set-context --project-id <project-id>

Console and API usage

Notes and Caveats

Useful Workflow Patterns

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

Post-creation environment update prompt

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

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 @neondatabase/config
// neon.ts
import { defineConfig } from "@neondatabase/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 neonctl branches create, the TTL and compute profile live in version control and apply to every matching branch.

Because neonctl 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 neonctl deploy (alias for neonctl config apply) to apply changes to a branch that already exists.

Branching in CI/CD

Common CI/CD use cases for Neon branches:

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 available/authenticated tool path first (MCP, otherwise CLI with neonctl --version).
  4. Provide commands:
    • neonctl branches create --name migration-test --parent main --expires-at 2026-12-15T18:02:16Z
    • neonctl 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 available/authenticated tool path first (MCP, otherwise CLI with neonctl --version).
  4. Provide command:
    • neonctl 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:
    • https://console.neon.tech/app/projects?modal=feedback
    • https://discord.gg/92vNTzKDGp

Further reading