neondatabase/website/neon-realtime
Claude Code and agent skill by neondatabase/website
- community
Checking that the SKILL.md file is still in the repository.
Neon Realtime makes any SQL query live. Build realtime, reactive apps and agents on Lakebase Postgres with live SQL queries and reactivity primitives. Use when app UI or agent state must update live from database rows (dashboards, feeds, collaboration, multi-user or multi-device sync), for optimistic mutations, or to replace polling or other realtime sync systems. Triggers include "live query", "subscribe", "sync engine", "useLiveQuery", "TanStack DB", "optimistic updates", "@neon/realtime". For push that doesn't come from database rows (presence, typing, LLM streams), use neon-functions.
Install
npx vskill@latest install neondatabase/website/neon-realtimeSKILL.md
The same SKILL.md was published earlier as neondatabase/website/neon-realtime.
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 Realtime
Neon's Realtime makes any SQL query live. Subscribe in realtime to your Lakebase Postgres database. Develop apps and agents with end-to-end reactivity using type-safe live queries and optimistic mutations.
Realtime is new and in beta, so its APIs aren't in your training data. Start from the core pattern below, and read each section's reference file before writing that code.
How It Works
Realtime's layers compose: a live query engine inside Postgres, the Live SQL API (a WebSocket API), lower-level client SDKs (seal(), subscribe()), and reactivity primitives such as useLiveQuery.
- In trusted backend code, define a live query (any read-only SQL, including joins, aggregates, ordering and limits), seal it with
NEON_REALTIME_SECRETand expose it from an authenticated endpoint or server function. The client can't read or change a sealed query's SQL or parameters. - The client subscribes with the sealed query. It receives the full initial result, then each committed transaction's changes as one batch. Results stay consistent, but delivery of every change event isn't guaranteed.
- Writes go through your own API, which returns each write's
txidforawaitTxId().
Core Pattern
The guides' chat app, with messages authorized through channel_members. The backend seals the query and returns each write's txid:
The React frontend subscribes and sends optimistic messages:
Choose the Stack
A live query replaces fetching app data from an API or another sync system. Reuse existing query code, and use the highest layer that fits rather than wiring changes into app state by hand.
| Use | For | |
|---|---|---|
drizzleAdapter() from @neon/realtime-drizzle, or kyselyAdapter() from @neon/realtime-kysely | Queries written in Drizzle or Kysely | |
rawSql from @neon/realtime/server | Any other ORM, or none | |
useLiveQuery from @neon/realtime-react | React. Binds one sealed query to a component's state | |
realtimeCollectionOptions from @neon/realtime-tanstack | Many views over the same data, or an app on TanStack DB. Oversync one broader query into a collection, then derive local live queries from it | |
client.subscribe() from @neon/realtime/client | Other frameworks | |
realtime.subscribe() from @neon/realtime/server | Agents and workers, in trusted backend code |
Migrating from Electric: Realtime is a drop-in replacement for Electric's role in your stack. Live SQL queries replace shapes, and realtimeCollectionOptions() replaces electricCollectionOptions().
Setup
- New app:
neon bootstrap my-app --template realtime-react, thenneon deployinmy-app. - Existing app: follow the Next.js example. Its setup declares Realtime with
neon config add realtimeand runsneon deploy, and Adapt the example to your app covers raw SQL withcreateRealtime()and no adapter, and apps with their own auth or none. - Enable it on the linked branch with `neon realtime enable --allowed-origin <app origin>`, or declare `preview: { realtime: true }` in
neon.ts(neon config add realtime) and runneon deploy. Child branches inherit it. It's unavailable on Claimable projects until claimed, or outside the supported regions. - Tables need a stable replica identity; a primary key is enough. Leave row-level security off on every table a live query reads: Realtime rejects those subscriptions with
unsupported query: row security. For per-user data, authorize in the sealed query instead (see below). - Environment:
neon env pull --service postgres --service realtimewritesDATABASE_URL,NEON_REALTIME_URLandNEON_REALTIME_SECRET. Expose only the URL to the browser, under your framework's public prefix (likeVITE_).urloptions takeNEON_REALTIME_URL;dbtakes the database name fromDATABASE_URL. - Install
@neon/realtimeand the packages chosen above. Use these SDKs, not the still-evolving WebSocket protocol.
Define and Seal Queries
Read references/queries.md before writing query or sealing code, including Kysely and server functions.
- Read-only and deterministic. A raw query is a single
SELECTwith no;and$1placeholders. It can't callnow()orgen_random_uuid(), so pass such values as parameters, wrapping every value except strings, numbers, booleans, bigints and null in apgParamhelper (pgParam.timestamptz(date)). - Authorize in the query. Check the session before sealing, and join through your membership tables so revoked access drops out. Any web framework auth works, including Managed Better Auth, but not RLS yet. See Authorization.
- A sealed query is a bearer token. Keep it out of URLs, logs and persistent storage, and never fill its parameters from unchecked input.
- Check a query before wiring it in: `neon realtime subscribe "SELECT ..."` prints the initial result, then each transaction's changes, until you stop it. With
--output json, each change prints a full snapshot. SetdebugModeoncreateRealtimefor full database errors (development only). - Sealed queries expire. Pass
refreshQueryto the bindings or callrenew(), sealing the same query and parameters, or the subscription errors. New parameters need a new sealed query and subscription. In Next.js, renew from a Route Handler, because server actions run one at a time.
Subscribe
Read references/reactivity.md before writing React or TanStack DB code. Read references/subscribing.md before subscribing directly with client.subscribe(sealed) (getSnapshot, onChange, onStateChange), or from agents and workers, which add url to createRealtime and await realtime.subscribe(query) to seal in-process.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpublic/docs/ai/skills/neon-realtime/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/neondatabase/website/neon-realtime)