On this page

Command line

The BetterConfig CLI

Everything you do in the dashboard, from your terminal. Create projects, define typed keys, set values per environment, mint read tokens, and manage your team with one command, then script it or hand it to an AI agent.

$npm install -g @betterconfigdev/cli
@betterconfigdev/cli on npm

Overview

betterconfig is the official command line for BetterConfig. It talks to the same API as the dashboard, signed in as you, so every change respects your role, shows up in history under your name, and is typically live in your apps in under a minute.

For you

Flip a value, compare environments, or bootstrap a project without leaving your editor. Leave out the project or environment and an interactive picker asks for it.

For scripts and CI

--json on every command, stable exit codes, and no prompts without a terminal. Pipe export into import to copy whole environments.

For AI agents

Coding agents with a shell can run it directly, discover every command with commands --json, and preview writes with --dry-run.

New to BetterConfig? Start with the core concepts. Reading config from your app is the SDK's job, and chat-based agents like Claude or ChatGPT connect through the MCP server instead.

Install

The CLI is published on npm as @betterconfigdev/cli and needs Node.js 20.12 or later. Install it globally to get the betterconfig command:

npm install -g @betterconfigdev/cli

Or run it without installing:

npx @betterconfigdev/cli login

Check it worked with betterconfig --version. Every command takes --help with real examples. To upgrade, install again with @latest:

npm install -g @betterconfigdev/cli@latest

Quickstart

From zero to a value your app can read in five commands.

  1. 1

    Sign in through your browser.

    betterconfig login
  2. 2

    Create a project and link your app's folder to it.

    cd my-app
    betterconfig projects create my-app --link
    
    # Already have a project? Link this folder to it instead:
    betterconfig link my-app --env dev

    Linking writes a small .betterconfig.json, so commands in this folder know which project and environment you mean.

  3. 3

    Create a typed key with a starting value.

    betterconfig keys create checkout.enabled --type boolean --value dev=true
  4. 4

    Change it.

    betterconfig set checkout.enabled=false --env dev
  5. 5

    Read it back, exactly as your SDK will.

    betterconfig get checkout.enabled --env dev   # prints: false

Ready for production? Add an environment with betterconfig envs create prod, then mint a read token for your app with betterconfig tokens create web-prod --env prod.

Signing in

The browser flow

betterconfig login opens your browser to sign in to BetterConfig and approve the CLI. Once you approve, the browser hands the CLI a one-time code through a temporary callback on 127.0.0.1, and you're done. The sign-in URL is also printed to stderr in case the browser doesn't open, and the CLI waits up to 5 minutes for you.

Over SSH, in containers, and from agents

Pass --no-browserto print the URL instead of opening it. Open it in a browser, approve, and the waiting command finishes on its own. It's also how an AI agent signs in: it runs the command and hands you the link.

betterconfig login --no-browser
The last step of the sign-in redirects to 127.0.0.1on the machine running the CLI. If your browser is on a different machine, that final page won't load. Copy its full address from the address bar and paste it into the waiting terminal; the CLI finishes the sign-in from there.

Read-only logins

betterconfig login --read-onlyasks only for permission to read config. It's a good fit for agents and scripts that should look but never touch. betterconfig whoami shows which kind of login you have.

Where credentials live

Credentials are saved to ~/.config/betterconfig/credentials.json (or $XDG_CONFIG_HOME/betterconfig when that's set, and %APPDATA%\betterconfig on Windows). The file is readable only by you, and holds one login per API URL, so you can stay signed in to production and a local server at the same time. Point the CLI at another folder with BETTERCONFIG_CONFIG_DIR:

BETTERCONFIG_CONFIG_DIR=~/.config/betterconfig-work betterconfig login

Signing out

betterconfig logoutrevokes this machine's session on the server and deletes its stored credentials. To sign out everywhere at once, revoke BetterConfig CLI under Connected apps in the dashboard, or run betterconfig apps revoke betterconfig-cli. Every machine then needs a fresh login.

Choosing a server

The CLI talks to https://api-admin.betterconfig.dev by default. Point it elsewhere with --api-url or BETTERCONFIG_API_URL. The order is: the flag, then the environment variable, then the URL saved by link in this folder, then the default.

betterconfig login --api-url http://localhost:8787

Project & environment defaults

Most commands need a project, and many need an environment. You rarely have to type either. The CLI checks, in order:

OrderProjectEnvironment
1. Flag--project, -p--env, -e
2. Environment variableBETTERCONFIG_PROJECTBETTERCONFIG_ENV
3. Linked folderproject in the nearest .betterconfig.jsonenvironment in that file, when it links the same project
4. FallbackAn interactive pickerPicked automatically when the project has one environment, otherwise an interactive picker

betterconfig link writes .betterconfig.json in the current folder, and the CLI finds it from any subfolder by walking up. It holds slugs, not secrets, so you can commit it to share defaults with your team.

.betterconfig.json
{
  "project": "my-app",
  "environment": "dev"
}

Without a terminal, the pickers never appear. The command stops with exit code 2 and a hint naming the flag to pass. Two commands deliberately skip the defaults: keys delete and keys restore always need an explicit --env.

Values & types

Every key has a type, and values you pass on the command line are parsed by it. set retries=3 sends the number 3 when retries is a number, while set title=3sends the string "3" when titleis a string. Every value is checked against its key's type before anything is written.

Key typeWhat you typeExample
stringTaken as-is.banner.title=Spring sale
numberAny finite number.max_retries=5
booleantrue, false, yes, no, on, off, 1, or 0 (any case).checkout.enabled=off
arrays and objectsJSON. Quote it for your shell.'regions=["us","eu"]'

Pass --parse-json to parse every value as JSON, whatever its type. To set many values at once, pass --file values.json (a JSON object of keys to values) or --file - to read it from stdin.

The --type syntax

keys create --type and keys update --type accept:

--typeMeaning
stringText.
numberA number.
booleantrue or false.
jsonFree-form JSON.
string[], number[], boolean[]An array of that type.
'{"kind":"object","fields":{…}}'A full type definition, for objects with typed fields.
betterconfig keys create limits \
  --type '{"kind":"object","fields":{"maxBatch":{"kind":"number"}}}' \
  --value 'dev={"maxBatch":50}'

Key names use letters, digits, dots, underscores, and hyphens, start and end with a letter or digit, and run up to 120 characters: checkout.enabled, MAX_RETRIES, and api-v2.url all work. Changing a key's type is refused when existing values wouldn't fit, unless you reset those environments with --reset-env.

Command reference

Every command, grouped by area. Global options like --json and --api-url work on all of them (see Scripts & AI agents). Search by name, flag, or what you're trying to do.

43 commands

Account

Sign in, sign out, and check who you are.

Sign in through your browser and store credentials on this machine.

betterconfig login [--no-browser] [--read-only]

Options

--no-browser
Print the sign-in URL instead of opening a browser. The command waits until the sign-in is approved, and accepts the browser's final address pasted into the terminal when the browser is on another machine.
--read-only
Request read-only access (config:read only, no config:write).

The sign-in URL is always printed to stderr. The command stops waiting after 5 minutes.

Example
betterconfig login
betterconfig login --no-browser   # over SSH, or from an agent
betterconfig login --read-only

Revoke this machine's login on the server and delete its stored credentials.

betterconfig logout
Example
betterconfig logout

Show the signed-in account, the server, your access level (read + write or read-only), and the linked project.

betterconfig whoami
Example
betterconfig whoami --json

Folder defaults

Pin a default project and environment to a folder so you can skip the flags.

Projects

Alias: project.

projects list

alias: ls

List the projects you're a member of, with your role and which one this folder is linked to.

betterconfig projects list
Example
betterconfig projects list --json

Create a project. You become its owner.

betterconfig projects create [slug] [options]

Arguments

[slug]
URL-safe identifier, such as my-app: 2 to 40 lowercase letters, digits, and hyphens, not at the start or end. Prompts when omitted.

Options

-n, --name <name>
Display name. Defaults to the slug.
--env-name <name>
Name of the first environment. Defaults to dev.
--link
Link the current folder to the new project.
Example
betterconfig projects create my-app --name "My App"
betterconfig projects create my-app --env-name production --link

projects show

alias: get

Show a project's details, your role, its environments with their versions, and its key count.

betterconfig projects show [slug]

Arguments

[slug]
Project slug. Defaults to the linked project.
Example
betterconfig projects show my-app

projects update

alias: rename

Rename a project or change its slug. Owner only.

betterconfig projects update [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-n, --name <name>
New display name.
--slug <slug>
New slug. Existing SDK tokens keep working, but SDKs must use the new slug.
Example
betterconfig projects update --name "New Name"
betterconfig projects update -p old-slug --slug new-slug

Permanently delete a project with every environment, key, value, and SDK token. Owner only.

betterconfig projects delete <slug> [--yes]

Arguments

<slug>
Project slug. Always required, so a delete is never implicit.

Options

-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.
Example
betterconfig projects delete old-app --yes

Environments

Aliases: env, environments.

envs list

alias: ls

List a project's environments with their current versions.

betterconfig envs list [-p <slug>]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
Example
betterconfig envs list

Create an environment. Every existing key is added to it with its type's default value. Owner only.

betterconfig envs create <key> [options]

Arguments

<key>
Environment key: lowercase letters, digits, underscores, and hyphens.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-n, --name <name>
Display name. Defaults to the key.
Example
betterconfig envs create prod --name Production

Delete an environment and its values, and revoke tokens scoped to it. Owner only.

betterconfig envs delete <key> [options]

Arguments

<key>
Environment key.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.
Example
betterconfig envs delete staging --yes

Config values

Read and write values in one environment.

Print an environment's config values, exactly as SDKs read them. With a single key, prints just the value.

betterconfig get [keys...] [options]

Arguments

[keys...]
Only these keys. Defaults to every key. A key that isn't set exits with code 4.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Environment key. Defaults to BETTERCONFIG_ENV, then the linked environment.
Example
betterconfig get --env prod
betterconfig get checkout.enabled --env prod   # prints just the value
betterconfig get --env prod --json | jq .values

Set values of existing keys in one environment. Values are parsed by each key's type, and several keys in one call publish the environment once.

betterconfig set [key=value...] [options]

Arguments

[assignments...]
key=value pairs.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Environment key. Defaults to BETTERCONFIG_ENV, then the linked environment.
-f, --file <path>
Read a JSON object of { key: value } from a file, or - for stdin.
--parse-json
Parse every value as JSON instead of by the key's type.
--dry-run
Show what would change without writing.

Keys must exist first. Unchanged values are skipped. Changes are typically live in under a minute.

Example
betterconfig set checkout.enabled=true max_retries=5 --env prod
betterconfig set 'limits={"maxBatch":50}' --env dev
echo '{"banner.text":"Hi"}' | betterconfig set --file - --env dev
betterconfig set checkout.enabled=false --env prod --dry-run

Keys

Typed config keys. Alias: key.

keys list

alias: ls

List config keys with their types and the environments they're live in.

betterconfig keys list [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Include a value preview from this environment.
-s, --search <text>
Filter by key name or description.
Example
betterconfig keys list --search checkout --env prod

keys show

alias: get

Show a key's type, description, and its value and version in every environment.

betterconfig keys show <key> [-p <slug>]

Arguments

<key>
Config key name.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
Example
betterconfig keys show checkout.enabled

keys create

alias: add

Create a typed key in every environment. Environments without an initial value hold the type's default.

betterconfig keys create <key> --type <type> [options]

Arguments

<key>
Key name, such as checkout.enabled or MAX_RETRIES: letters, digits, dots, underscores, and hyphens, starting and ending with a letter or digit, up to 120 characters.

Options

-t, --type <type>
Required. string, number, boolean, json, string[], number[], boolean[], or a JSON type definition.
-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-d, --description <text>
What the key controls.
--value <env=value>
Initial value for an environment. Repeatable.
Example
betterconfig keys create checkout.enabled --type boolean --value dev=true --value prod=false
betterconfig keys create allowed_regions --type 'string[]' -d "Regions where checkout is on"
betterconfig keys create limits --type '{"kind":"object","fields":{"maxBatch":{"kind":"number"}}}'

Rename a key, change its type, or edit its description.

betterconfig keys update <key> [options]

Arguments

<key>
Config key name.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
--rename <new-key>
New key name. Code that reads the old name must be updated to match.
-t, --type <type>
New type. Refused when existing values don't fit, unless those environments are reset.
-d, --description <text>
New description.
--clear-description
Remove the description.
--reset-env <env>
With --type: reset this environment's value to the new type's default. Repeatable.
Example
betterconfig keys update checkout.enabled --description "Kill switch for checkout"
betterconfig keys update max_retries --type string --reset-env dev
betterconfig keys update old.name --rename new.name

keys delete

alias: rm

Remove a key from one environment, restorable with keys restore. Removing it from the last environment it's live in deletes it permanently.

betterconfig keys delete <key> --env <key> [options]

Arguments

<key>
Config key name.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Required. The environment to remove it from (no default, on purpose).
-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.

Only the permanent delete asks for confirmation, so only that case needs --yes in scripts.

Example
betterconfig keys delete legacy.banner --env staging

Bring back a key removed from an environment, with its last value there.

betterconfig keys restore <key> --env <key>

Arguments

<key>
Config key name.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Required. The environment to restore it in.
Example
betterconfig keys restore legacy.banner --env staging

Import and export

Move many keys at once, between files, environments, and projects.

Create and update many keys in one environment from a JSON or dotenv file.

betterconfig import <file> [options]

Arguments

<file>
Path to the file, or - for stdin.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Environment key. Defaults to BETTERCONFIG_ENV, then the linked environment.
--format <format>
json or dotenv. Detected from the file name when omitted.
--overwrite
Overwrite values of keys that already exist. By default they're skipped.
--dry-run
Show what would be created and updated without writing.
Example
betterconfig import config.json --env dev
betterconfig import .env --env dev --overwrite
betterconfig export --env prod | betterconfig import - --env staging --overwrite

Write an environment's live config as JSON or dotenv.

betterconfig export [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Environment key. Defaults to BETTERCONFIG_ENV, then the linked environment.
--format <format>
json (default) or dotenv.
-o, --out <path>
Write to a file instead of stdout.
Example
betterconfig export --env prod > prod.json
betterconfig export --env dev --format dotenv -o .env.betterconfig

History

Who changed what, and when. Alias: log.

history

alias: log

Recent value changes, newest first, with the previous value, the new value, and who made the change.

betterconfig history [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Only changes in this environment.
-k, --key <key>
Only changes to this key, filtered within the fetched page.
-n, --limit <n>
How many changes to fetch, 1 to 100. Defaults to 25.
--cursor <cursor>
Continue from a previous page's nextCursor.
Example
betterconfig history --env prod
betterconfig history --key checkout.enabled --limit 100 --json

Read tokens

Read-only tokens that SDKs and curl use to fetch config. Alias: token.

tokens list

alias: ls

List a project's read tokens with their prefix, scope, and when they were last used.

betterconfig tokens list [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
--all
Include revoked tokens.
Example
betterconfig tokens list --all

Create a read token. It's shown once, so store it right away. Owner only.

betterconfig tokens create <name> [options]

Arguments

<name>
A label, such as web-prod.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-e, --env <key>
Lock the token to one environment. Without it, the token reads every environment.
Example
betterconfig tokens create web-prod --env prod
BETTERCONFIG_TOKEN=$(betterconfig tokens create ci --json | jq -r .token)

Revoke a read token. Apps using it stop getting config. Owner only.

betterconfig tokens revoke <name-or-id> [options]

Arguments

<name-or-id>
Token name or id. When two active tokens share a name, revoke by id.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.
Example
betterconfig tokens revoke web-prod --yes

Members

Who can access a project. Alias: member.

members list

alias: ls

List members with their roles, plus pending invitations.

betterconfig members list [-p <slug>]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
Example
betterconfig members list

Invite people by email. They get an email to accept. Owner only.

betterconfig members invite <emails...> [options]

Arguments

<emails...>
One or more email addresses.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-r, --role <role>
editor or viewer. Defaults to viewer.
Example
betterconfig members invite ana@example.com sam@example.com --role editor

members set-role

alias: role

Change a member's role to editor or viewer. Owner only.

betterconfig members set-role <email> <role>

Arguments

<email>
The member's email.
<role>
editor or viewer. To make someone owner, use members transfer.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
Example
betterconfig members set-role sam@example.com viewer

Remove a member, or cancel a pending invitation sent to that email. Owner only.

betterconfig members remove <email> [options]

Arguments

<email>
The member's or invitee's email.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.
Example
betterconfig members remove sam@example.com --yes

Make another member the owner. You become an editor and can't undo it yourself. Owner only.

betterconfig members transfer <email> [options]

Arguments

<email>
The new owner's email.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.
Example
betterconfig members transfer ana@example.com --yes

Invites

Invitations sent to you. Alias: invitations. Running invites on its own lists them.

invites list

alias: ls

List projects you've been invited to, with the role offered and who sent it.

betterconfig invites [list]
Example
betterconfig invites

Accept an invitation and join the project.

betterconfig invites accept <project>

Arguments

<project>
The inviting project's slug.
Example
betterconfig invites accept acme-web

Decline an invitation.

betterconfig invites decline <project>

Arguments

<project>
The inviting project's slug.
Example
betterconfig invites decline acme-web

Usage and billing

Read-only views of your plan. Plan changes stay in the dashboard.

Show a project's SDK reads, environments, members, and storage against the owner's plan limits. Owner only.

betterconfig usage [-p <slug>]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
Example
betterconfig usage --json

Show your plan, its status and renewal date, owned projects, and SDK reads this month.

betterconfig billing

To change plans, run betterconfig open billing.

Example
betterconfig billing

Connected apps

AI agents and tools connected to your account over OAuth. Running apps on its own lists them.

apps list

alias: ls

List connected apps with their client id, access level, and last activity.

betterconfig apps [list]
Example
betterconfig apps

Disconnect an app. It can't refresh its access anymore and needs your approval to connect again.

betterconfig apps revoke <client-id> [--yes]

Arguments

<client-id>
The app's client id, from apps list.

Options

-y, --yes
Skip the confirmation prompt. Required when not running in a terminal.

Revoking betterconfig-cli signs out the CLI on every machine, including this one.

Example
betterconfig apps revoke <client-id> --yes

Tooling

Type generation, the dashboard, and escape hatches.

Generate a TypeScript declaration file so SDK config reads are fully typed.

betterconfig typegen [options]

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
-o, --out <path>
Output file. Defaults to betterconfig.d.ts.
--module <name>
Module to augment. Repeatable. Defaults to @betterconfigdev/react and its /server entry.
-t, --token <token>
Use a project read token instead of your login, for CI. Also read from BETTERCONFIG_TOKEN.
-e, --env <key>
With --token: infer types from this environment when the project has no published schema. Also read from BETTERCONFIG_ENV.
--base-url <url>
With --token: the read API origin. Also read from BETTERCONFIG_BASE_URL.
Example
betterconfig typegen --out src/betterconfig.d.ts
betterconfig typegen --project my-app --token "$BETTERCONFIG_TOKEN"   # CI, no login

Open the dashboard in your browser.

betterconfig open [page] [options]

Arguments

[page]
dashboard, project, keys, history, settings, billing, or apps. Defaults to project.

Options

-p, --project <slug>
Project slug. Defaults to BETTERCONFIG_PROJECT, then the linked project.
--print
Print the URL instead of opening it.

It uses the dashboard address the server reported when you logged in. If that's unknown, set BETTERCONFIG_WEB_URL.

Example
betterconfig open
betterconfig open billing
betterconfig open keys --print

Call any dashboard API endpoint as yourself and print the JSON response.

betterconfig api <path> [options]

Arguments

<path>
Path under /api, such as /projects. A leading /api is accepted too.

Options

-X, --method <method>
GET (default), POST, PUT, PATCH, or DELETE.
-d, --data <json>
JSON request body.
--input <file>
Read the JSON body from a file, or - for stdin.

A non-2xx response still prints its body, and the exit code follows the HTTP status.

Example
betterconfig api /projects
betterconfig api /projects/<id>/keys --json | jq '.keys[].key'
betterconfig api -X PATCH /projects/<id> -d '{"name":"Renamed"}'

List every command. With --json, prints a machine-readable catalog of every command, argument, and option.

betterconfig commands [--json]
Example
betterconfig commands --json | jq '.commands[].command'

Import & export

betterconfig import creates and updates many keys in one environment from a file. It understands three formats. Keys that already exist are skipped unless you pass --overwrite, and --dry-run shows what would be created and updated first.

JSON object

Every property becomes a key, with its type inferred from the value. This is exactly what export writes.

config.json
{
  "checkout.enabled": true,
  "api.timeoutMs": 5000,
  "banner.title": "Spring sale",
  "allowed_regions": ["us", "eu"],
  "theme": { "accent": "green", "radius": 8 }
}

JSON array of entries

For full control, list entries with a key, a value, and optionally a type (any --type string or a type definition) and a description. Without a type, it's inferred from the value.

keys.json
[
  {
    "key": "checkout.enabled",
    "type": "boolean",
    "value": true,
    "description": "Kill switch for checkout"
  },
  { "key": "allowed_regions", "type": "string[]", "value": ["us", "eu"] },
  {
    "key": "limits",
    "type": { "kind": "object", "fields": { "maxBatch": { "kind": "number" } } },
    "value": { "maxBatch": 50 }
  }
]

dotenv

KEY=value lines, with optional export prefixes, quotes, and comments. Files named like .env, .env.local, or prod.env are read as dotenv automatically. Anything else is read as JSON unless you pass --format dotenv.

.env
# Comments and blank lines are skipped
export API_TIMEOUT_MS=5000
BANNER_TITLE="Spring sale"
SUPPORT_EMAIL=help@example.com # trailing comments too
Every dotenv value imports as a string, so API_TIMEOUT_MSabove becomes the string "5000". Use JSON when you want numbers, booleans, or objects.

Large files and partial failures

Big files are sent in batches of 500 keys, with a short pause between batches. If some values don't match their key's type, the rest still import, the rejected keys are listed, and the command exits with code 1.

Export

betterconfig exportwrites an environment's live config as a flat, alphabetically sorted JSON object (the default) or as dotenv with --format dotenv, where non-string values are written as JSON. It prints to stdout, or to a file with --out. Because status messages go to stderr, you can pipe one environment straight into another:

# Preview, then copy prod into staging
betterconfig export --env prod | betterconfig import - --env staging --overwrite --dry-run
betterconfig export --env prod | betterconfig import - --env staging --overwrite

Type generation

betterconfig typegen writes a TypeScript declaration file that augments @betterconfigdev/react, so useConfigValue() autocompletes your keys and returns properly typed values. Commit the file, and regenerate it when keys change.

# On your machine, from your login
betterconfig typegen --out src/betterconfig.d.ts

# In CI, with a read token and no login
betterconfig typegen --project my-app --token "$BETTERCONFIG_TOKEN" --out src/betterconfig.d.ts
ModeHow it works
From your loginReads key definitions straight from the project, including descriptions. Uses the usual project defaults.
With --tokenFor CI. Uses a project read token (or BETTERCONFIG_TOKEN) and the project's published schema, so no login is needed. If the project has no published schema yet, add --env <key>to infer types from that environment's values.

The file goes to betterconfig.d.ts unless you pass --out, and augments both @betterconfigdev/react and @betterconfigdev/react/server unless you pass --module. Projects that install only the SDK can use its built-in betterconfig-typegen command, which works with a read token. See the SDK docs for using typed values in your app.

Scripts & AI agents

The CLI is built to be driven by code as much as by people. Results go to stdout and status messages go to stderr, so pipes and jq just work.

Global options

OptionWhat it does
--jsonPrint machine-readable JSON on stdout. Errors go to stderr as JSON too.
-q, --quietOnly print results, no status messages.
--no-inputNever prompt. Anything that would ask fails with a hint instead.
--api-url <url>API origin to talk to. Also read from BETTERCONFIG_API_URL.
-v, --versionPrint the CLI version.
-h, --helpShow help and examples for any command.

JSON output and errors

$ betterconfig get --env prod --json
{
  "project": "my-app",
  "environment": "prod",
  "version": 12,
  "values": {
    "checkout.enabled": true,
    "max_retries": 5
  }
}

Errors are a single line on stderr shaped like {"error":{"code","message","hint"}}, with status and details added when there are any. Branch on the exit code and the code, and show people the hint.

$ betterconfig get --project my-app --json
{"error":{"code":"environment_required","message":"No environment selected.","hint":"Pass --env <key> (one of: dev, prod), set BETTERCONFIG_ENV, or run `betterconfig link --env <key>`."}}
$ echo $?
2

No surprise prompts

  • Prompts only appear when both stdin and stderr are a terminal. With --json, --no-input, or the CI environment variable set, they're off too, and anything that would ask exits with code 2 and a hint naming the flag to pass.
  • Destructive commands need --yes when nobody can confirm: projects delete, envs delete, keys delete (when it removes a key for good), tokens revoke, members remove, members transfer, and apps revoke.
  • set and import take --dry-run to preview changes without writing.

For AI agents

Coding agents with terminal access, like Claude Code, Codex, or Cursor, can use the CLI as is. Sign in once with login --no-browser (add --read-only if the agent only needs to look), link the folder, and let the agent work:

# Read one value
betterconfig get checkout.enabled --env prod

# Preview a change, then make it
betterconfig set checkout.enabled=false --env prod --dry-run --json
betterconfig set checkout.enabled=false --env prod --json

# Destructive commands need --yes when nobody is there to confirm
betterconfig keys delete legacy.banner --env staging --yes --json

# Discover everything the CLI can do
betterconfig commands --json

betterconfig commands --jsonprints the full catalog of commands, arguments, and options, so an agent can learn the CLI in one call. Global options aren't in the catalog; they're listed above and in --help.

commands --json (trimmed)
{
  "version": "x.y.z",
  "commands": [
    {
      "command": "set",
      "aliases": [],
      "description": "Set values of existing keys in one environment; ...",
      "arguments": [
        { "name": "assignments", "required": false, "variadic": true, "description": "key=value pairs; ..." }
      ],
      "options": [
        { "flags": "-p, --project <slug>", "description": "project slug (default: ...)", "required": false },
        { "flags": "--dry-run", "description": "show what would change without writing", "required": false }
      ]
    }
  ]
}

For agents that live in a chat app rather than a terminal, connect the MCP server instead.

Environment variables

VariableEffect
BETTERCONFIG_API_URLAPI origin, same as --api-url. Defaults to https://api-admin.betterconfig.dev.
BETTERCONFIG_CONFIG_DIRFolder for credentials.json. Defaults to ~/.config/betterconfig.
BETTERCONFIG_PROJECTDefault project slug, same as --project.
BETTERCONFIG_ENVDefault environment key, same as --env.
BETTERCONFIG_TOKENRead token for typegen --token.
BETTERCONFIG_BASE_URLRead API origin for typegen --token.
BETTERCONFIG_WEB_URLDashboard origin for open, when it can't be detected.
CIWhen set to anything, prompts are turned off.
BETTERCONFIG_DEBUGWhen set, unexpected errors print a stack trace.

Exit codes & troubleshooting

Exit codes are stable, so scripts can react to the kind of failure without parsing messages.

CodeMeaningCommon causes and fixes
0Success.Nothing to do.
1General error.The API couldn't be reached (check your connection and --api-url), the server returned an error or rate limit (wait and retry), some values in a set or importwere rejected for not matching their key's type (the rest were applied), or you cancelled a prompt. Set BETTERCONFIG_DEBUG=1 to print a stack trace for unexpected errors.
2Usage error or confirmation needed.A flag or argument is missing or invalid, a value doesn't fit its type, or the CLI needed to ask something without a terminal. Read the hint: it names the flag to pass, such as --project, --env, or --yes.
3Not logged in.No login for this API URL, the login expired or was revoked, or the browser sign-in was denied or timed out. Run betterconfig login (with the same --api-url if you use one).
4Not found.The project, environment, key, token, member, invitation, or app doesn't exist, or you aren't a member of the project. Check the name with projects list, envs list, or keys list.
5Permission denied.Your role doesn't allow it (viewers read, editors change config, owners manage environments, tokens, members, and settings), you're writing with a --read-only login (run betterconfig login again without it), or the action is dashboard only.
6Plan limit reached.The change would exceed the project owner's plan. Check betterconfig usage, then upgrade with betterconfig open billing.
7Conflict.The name is taken (a project slug, environment key, or config key), or a type change would invalidate existing values. For type changes, set compatible values first or add --reset-env <env>.

Still stuck? Run the command again with --json to see the exact error code, or check what you're signed in as with betterconfig whoami.

Security model

The CLI holds real access to your config, so it's locked down the same way the dashboard is, and then some.

  • Browser sign-in, no API keys

    login runs OAuth 2.1 with PKCE. You sign in and approve on BetterConfig's own consent screen, and the code comes back to a one-shot server that only listens on 127.0.0.1, so nothing off your machine can deliver it.

  • Short-lived access tokens

    Access tokens last 15 minutes and refresh automatically. A revoked login can't refresh again, and any access token it still holds expires within those 15 minutes.

  • Only the CLI can use the dashboard API

    The BetterConfig CLI is the one app allowed to get tokens for the dashboard API. Other apps can't register their way in, and the API rejects tokens issued to anyone else.

  • MCP agents stay on /mcp

    AI agents connected over the MCP server get tokens for the MCP endpoint only. They can't call the dashboard API, even with your approval.

  • Your role still applies

    The CLI acts as you, project by project. Viewers read, editors change config, and owners manage environments, tokens, members, and settings.

  • Read-only logins can't write

    Log in with --read-only and the token only carries config:read. Every write is refused with exit code 5, no matter your role.

  • Money moves in the dashboard

    billing and usage are read-only. Plan changes and checkout only happen in the web dashboard, signed in with your browser session.

  • Every change is on the record

    Writes from the CLI land in project history under your name, so you can see what changed, when, and what it was before.

Credentials are stored owner-only on disk and scoped to one API URL each. Lost a laptop? Revoke BetterConfig CLI under Connected apps. No CLI login can refresh after that, so every session ends within 15 minutes.

Related

Docs

Projects, environments, versions, and the read API.

SDK

Read typed config in your React and Node apps.

MCP server

Let Claude, ChatGPT, and other agents manage config in chat.