Major update to our Free Plan: now with 1 GB of Postgres storage per project, 100 projects included
/APIs & SDKs/Setup and context/env

Neon CLI command: env

Manage a branch's Neon environment variables locally

The env command manages a branch's Neon environment variables locally. neon link and neon checkout pull env variables automatically by default.

Subcommands: pull

neon env pull

Writes the branch's Neon environment variables to a local .env file.

neon env pull works with or without a neon.ts configuration file. Without one, it writes everything the branch has: the core variables (DATABASE_URL, DATABASE_URL_UNPOOLED, NEON_BRANCH), credentials for each service provisioned on the branch, and the default AI Gateway credential. With a neon.ts, it writes the core variables plus credentials for each service you declare (Managed Better Auth, Data API, AI Gateway, Object Storage, Realtime).

When your neon.ts declares functions, neon env pull also writes each one's invocation URL as NEON_FUNCTION_<SLUG>_BASE_URL (for example, NEON_FUNCTION_DISCORD_BASE_URL). The URL is derived from the branch, so the function doesn't have to be deployed yet; the value is the address it will answer at once you deploy it to that branch. Scoping the pull with --service functions instead writes URLs only for functions that are already deployed, so a declared-but-undeployed function appears in the default neon.ts pull but not with --service functions.

Unset function env vars don't block a pull. If a declared function reads a process.env.* value that isn't set, neon env pull (and the pull that neon link and neon checkout run) skips that value and writes everything else instead of failing. The commands that actually build or run your functions still require every declared value: neon deploy, neon dev, and neon-env run.

neon env pull [options]
OptionDescriptionTypeDefaultRequired
--configPath to a neon.ts policy (defaults to the neon.ts next to .neon, or in cwd without one)string—No
--env, -earray—No
--fileTarget .env file to write, relative to cwd. Defaults to an existing .env, otherwise .env.local, in the project directory (next to .neon, or cwd without one). Only Neon variables are updated; other lines are preserved.string—No
--service, -s, --servicesPull only these services' variables: postgres, auth, data-api, functions, object-storage, ai-gateway, realtime. Repeat the flag or comma-separate. Overrides neon.ts, and prunes only within the services you name. Combines with --env as a union.array—No
--branchBranch ID or namestring—No
--project-idProject IDstring—No

Write the linked branch's Neon variables into .env.local (or .env if present):

neon env pull

Pull a specific branch into a specific file:

neon env pull --branch preview --file .env.preview

Pull only the variables for the services you name, ignoring neon.ts. Repeat --service or comma-separate the values (postgres, auth, data-api, functions, object-storage, ai-gateway, realtime):

neon env pull --service ai-gateway --service postgres

Use a specific neon.ts policy instead of the one in the project directory (next to the nearest .neon, or the current directory when there's no .neon):

neon env pull --config ./config/neon.ts
Was this page helpful?
Edit on GitHub

On this page

Copy neon init command