Skip to main content
Neon Postgres Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Neon CLI command: set-context

The set context command sets a background context for your CLI sessions, so you don't have to specify the project ID in every command. The context is saved to a default .neon file in the current direc...

The set-context command sets a background context for your CLI sessions, so you don't have to specify the project ID in every command. The context is saved to a default .neon file in the current directory, or to a named context file of your choice, and stays in place until you reset it or remove the file.

Bash
neon set-context [options]

To save the context to a file other than the default .neon file, add the global --context-file <your_context_file> option. You can switch contexts by providing different files.

Option Description Type Default Required
--branch-id Branch ID string — No
--org-id Organization ID string — No
--project-id Project ID string — No

Set at least one of these options.

Set the context to the default .neon file:

Bash
neon set-context --project-id patient-frost-50125040 --org-id org-bright-sky-12345678

List all branches for this project with branches list, without including --project-id or --org-id, even if you belong to multiple organizations or have multiple projects:

Bash
neon branches list
title="Output"
┌──────────────────────────┬─────────────┬─────────┬──────────────────────┬──────────────────────┐
│ Id                       │ Name        │ Default │ Created At           │ Updated At           │
├──────────────────────────┼─────────────┼─────────┼──────────────────────┼──────────────────────┤
│ br-raspy-meadow-26349337 │ development │ false   │ 2023-11-28T19:19:11Z │ 2023-12-01T00:18:21Z │
├──────────────────────────┼─────────────┼─────────┼──────────────────────┼──────────────────────┤
│ br-curly-bar-82389180    │ main        │ true    │ 2023-10-23T12:49:41Z │ 2023-12-01T00:18:21Z │
└──────────────────────────┴─────────────┴─────────┴──────────────────────┴──────────────────────┘

Set the context to the context file of your choice:

Bash
neon set-context --project-id plain-waterfall-84865553 --context-file Documents/MyContext

List all branches with branches list. The context file provides the project:

Bash
neon branches list --context-file Documents/MyContext
title="Output"
┌─────────────────────────────┬─────────────┬─────────┬──────────────────────┬──────────────────────┐
│ Id                          │ Name        │ Default │ Created At           │ Updated At           │
├─────────────────────────────┼─────────────┼─────────┼──────────────────────┼──────────────────────┤
│ br-soft-base-86343042       │ development │ false   │ 2023-11-21T18:41:47Z │ 2023-12-01T00:00:14Z │
├─────────────────────────────┼─────────────┼─────────┼──────────────────────┼──────────────────────┤
│ br-young-bush-89857627      │ main        │ true    │ 2023-11-21T18:00:10Z │ 2023-12-01T03:33:53Z │
├─────────────────────────────┼─────────────┼─────────┼──────────────────────┼──────────────────────┤
│ br-billowing-union-41102466 │ staging     │ false   │ 2023-11-21T18:44:22Z │ 2023-12-01T08:32:40Z │
└─────────────────────────────┴─────────────┴─────────┴──────────────────────┴──────────────────────┘

Use --set-context to set the project context at creation time:

Bash
neon projects create --name MyLatest --set-context

This creates a hidden .neon file by default with the following context:

JSON
{
  "projectId": "quiet-water-76237589"
}

Commands that would normally require --project-id now default to this context.

To clear the current context, either:

  1. Run the set-context command with no options:

    Bash
    neon set-context
  2. Delete the .neon file (or your custom --context-file):

    Bash
    rm .neon
    # Or for a custom context file:
    rm your_context_file

The first time a .neon file is created in a directory, the CLI adds .neon to .gitignore in that same folder:

  • If no .gitignore exists, the CLI creates one with a single .neon line.
  • If .gitignore already exists, the CLI appends .neon only if it is not already listed.

This keeps local project settings out of git by default. If you want to commit .neon and share context with your team, remove the entry from .gitignore. The CLI will not re-add it when updating an existing .neon file.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu