Home › Neon Postgres › Neon serverless Postgres CLAUDE.md

Neon serverless Postgres CLAUDE.md

CLAUDE.md for apps on Neon serverless Postgres: pooled connections, the serverless driver, branches, and migrations.

Claude Code (CLAUDE.md)Neon Postgres

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: Neon Postgres

## Connections
- `DATABASE_URL` uses the pooled host (`...-pooler...neon.tech`) for the app; `DATABASE_URL_UNPOOLED` (direct) for migrations and long sessions. Both come from env, never hard-coded.
- Serverless/edge runtimes use `@neondatabase/serverless`: `neon(url)` for one-shot HTTP queries, `Pool`/`Client` over WebSockets when you need transactions or sessions.
- Long-running servers can use regular `pg`/`postgres`/`psycopg` with the pooled URL; keep pool sizes small.
- With an ORM (Drizzle `drizzle-orm/neon-http`, Prisma with the Neon adapter), follow its Neon setup instead of mixing drivers.
- Expect cold starts after scale-to-zero: set connect timeouts and one retry for the first query.

## Branches
- Never run experiments or destructive SQL on the `main`/production branch.
- Create a branch for risky work: `neonctl branches create --name <feature> --parent main`, then get its URL with `neonctl connection-string <feature>`. Delete it when done (ask first).
- Preview deployments get their own branch through the CI integration if configured.

## Migrations
- Use the repo's migration tool against the direct (unpooled) URL. Test on a branch first, then apply to main through CI.
- Follow zero-downtime rules: concurrent indexes, nullable columns first, batched backfills.

## Queries
Parameterized only. The serverless driver's tagged template (sql`...${id}...`) sends `id` as a parameter; building SQL by string concatenation does not.

More: all Neon Postgres rules · all Claude Code (CLAUDE.md) rules

Related rules

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Drizzle ORM rules

Cursor rules for Drizzle ORM with Postgres or SQLite: schema files, drizzle-kit migrations, and type-safe queries.

CursorDrizzle ORM

Firebase (modular SDK) rules

Cursor rules for Firebase web apps with the modular v11+ SDK, Firestore security rules, and emulator tests.

CursorFirebase

MongoDB Windsurf rules

Windsurf rules for MongoDB 8 apps with the Node.js driver: schema design, indexes, aggregation, and transactions.

WindsurfMongoDB

Mongoose (MongoDB ODM) rules

Cursor rules for Mongoose 8 with TypeScript: typed schemas, indexes, lean queries, validation, and transactions.

CursorMongoDB

PostgreSQL schema & SQL AGENTS.md

AGENTS.md for working on PostgreSQL 16+ schemas and SQL: safe migrations, indexes, constraints, and query plans.

AGENTS.mdPostgreSQL

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.