Based on Neon and Anthropic official docs, checked
How to set up Neon Postgres with Claude Code
Neon scores 5/5 on our Claude Code fit scale: it ships an official plugin with an MCP server for branching and queries. Neon is serverless Postgres with one feature that changes how you work: database branching. Every branch is an isolated copy of your data, so you can test a migration on a throwaway copy instead of praying it works on the shared staging database. This guide creates a Neon project, connects it to your app with Claude Code, runs your first query, and makes a dev branch. By the end you will have a working DATABASE_URL, a table you created yourself, and a safe place to test schema changes.
1. Create a Neon account and project
Sign up at neon.com and open the Neon Console. Go to the Projects page, click New Project, fill in the project settings, and click Create Project.
Your project is created with a ready-to-use database named neondb. Neon also creates a default branch for you: it is named production when you create the project in the Console, or main when you create it with the CLI or API. That branch is where your app connects by default.
2. Install the official Neon plugin in Claude Code
The Neon plugin lives in Anthropic's official marketplace, claude-plugins-official, which Claude Code adds automatically the first time you start an interactive session. Install it with one command inside Claude Code.
The plugin installs Neon's agent skills together with the MCP server, so Claude can create projects and branches, run SQL, and plan migrations for you. If you prefer the CLI route, run npx neon@latest init in your project directory instead: it installs the agent tooling and links a Neon project.
/plugin install neon@claude-plugins-official # CLI alternative, run in your project directory npx neon@latest init3. Copy your connection string
In the Neon Console, click Connect in the navigation. A modal opens where you pick a branch, a compute, a database, and a role, and Neon builds the connection string for you.
Save it as DATABASE_URL in a .env file. Most frameworks read the connection string from that variable, so paste it exactly as shown. The string includes your role, password, host, and database name, plus sslmode=require, so never commit the .env file to git.
DATABASE_URL="postgresql://[user]:[password]@[neon_hostname]/[dbname]?sslmode=require&channel_binding=require"4. Install a driver and run your first query
Neon speaks the standard Postgres wire protocol, so any Postgres client works, including pg, psql, Prisma, and Drizzle. For serverless or edge runtimes, Neon also ships its own low-latency driver, @neondatabase/serverless, which connects over HTTP or WebSockets instead of TCP.
Install the serverless driver and run a query against your database. The neon() function sends each query as an HTTP request, which is the fastest option for single queries. Use the driver over HTTP by default, and reach for the Pool or Client form only when you need interactive transactions.
npm install @neondatabase/serverless import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL); const rows = await sql`SELECT version();`; console.log(rows);5. Create your first table
You can create tables from code or from the Neon Console. The Console has a built-in SQL Editor: open Postgres database, then SQL Editor, pick your branch, and run the statements.
This example creates a small todos table and inserts one row. Run it, then select the rows back to confirm the round trip works before you wire the table into your app.
CREATE TABLE todos ( id SERIAL PRIMARY KEY, task TEXT NOT NULL, done BOOLEAN NOT NULL DEFAULT FALSE ); INSERT INTO todos (task) VALUES ('Ship the Neon setup'); SELECT * FROM todos;6. Make a dev branch before risky changes
A Neon branch is a copy-on-write clone of its parent, so creating one copies no data and takes about a second no matter how large the database is. Changes on a branch never touch the parent, which makes branches the safe place to test migrations and destructive queries.
In the Console, open Branches and click New Branch, name it, pick the parent branch, and create it. Each branch gets its own connection string, so point your local app at the branch while you test. You can do the same from the terminal with the Neon CLI.
neon branches create --name my_test_branch --parent production neon connection-string my_test_branch
Pooled or direct connections
Neon gives you pooled connection details by default in the Connect modal, which adds a -pooler segment to the hostname. The pooler supports a higher number of concurrent connections, so it fits most apps, especially serverless ones that open many short connections.
If a tool or migration needs a direct connection, open the Connect modal and turn the Connection pooling toggle off to get direct details instead. Both strings point at the same database, only the route changes.
Run migrations on a branch first
Never run a migration straight against your main branch when you can test it on a copy first. The Neon MCP server has a two-step flow for this: prepare_database_migration applies your schema change on a temporary branch and returns a migration ID, and complete_database_migration applies it to the real branch once you are happy with the result.
The same habit works without MCP. Create a branch from the CLI, apply the migration there, run your app and tests against the branch connection string, and only then apply the same migration to production. If the migration fails on the branch, delete the branch and try again: nothing on the parent was ever touched.
What the Neon MCP server can do for you
Once the plugin or the MCP server is connected, Claude can manage your Neon projects through tools grouped by category: projects, branches, endpoints, snapshots, schema, querying, and docs. Ask it to create a branch, run a query, compare two schemas, or prepare a migration on a temporary branch and report back before anything touches your real data.
Keep the guardrails on. Neon recommends MCP for development and testing only, not production: never connect an MCP agent to a production database, avoid exposing production or personal data, and always review the actions Claude wants to take. For extra safety, connect with ?readonly=true on the MCP URL to disable write operations.
Troubleshooting
Three problems cover most failed Neon connections. Work through them in order before changing drivers.
- "Endpoint ID is not specified": your Postgres client or TLS stack does not support Server Name Indication (SNI), which Neon uses to route connections. Upgrading the client usually fixes it.
- Connection works locally but not from a deploy: check that the deployed environment has the same DATABASE_URL, including the sslmode=require parameter, and that the value was not truncated when you pasted it.
- MCP tools fail with an auth error: the cached OAuth credentials may be stale. Remove the ~/.mcp-auth directory, restart your client, and sign in again.
Tips
- Give every developer their own long-lived branch, so connection strings stay stable and nobody steps on each other's test data.
- Use a branch per pull request for preview deploys, then delete the branch when the pull request closes.
- Keep DATABASE_URL in env vars, never in source files, and use a restricted Postgres role for app traffic instead of the owner role.
- Ask Claude to run inspect_database checks, such as table sizes or unused indexes, before you guess why a query is slow.
Next steps
How to add a Supabase database with Claude Code
How to add Stripe payments with Claude Code
How to add Clerk authentication with Claude Code
How to deploy to Vercel with Claude Code
Frequently asked questions
Use the pooled string for your app in most cases: it is the default in the Connect modal and supports more concurrent connections. Switch the pooling toggle off for a direct string only when a specific tool or workflow needs one.
Sources
- https://neon.com/docs/connect/connect-from-any-app · checked 2026-11-15
- https://neon.com/docs/serverless/serverless-driver · checked 2026-11-15
- https://neon.com/docs/ai/neon-mcp-server · checked 2026-11-15
- https://neon.com/docs/get-started/workflow-primer · checked 2026-11-15
- https://code.claude.com/docs/en/discover-plugins · checked 2026-11-15