Skip to content
Luna
Esc
↑↓navigate↵open⌘Jpreview
On this page

The luna CLI

How every luna command picks the organisation, project and environment it acts on, the settings it reads and the exit codes it ends with.

The luna CLI deploys your app, runs it while you develop and manages everything around it from the terminal. Run luna whoami to see what commands act on in the current folder.

luna whoami

Commands

Command Does
luna deploy Deploys the app in this folder to an environment
luna dev Deploys to your own environment on every save and prints its log lines
luna secrets Sets, removes and lists an environment’s secrets
luna domains Adds, verifies and removes domains of your own
luna env Creates, lists, selects and deletes environments
luna tenants Adds, lists and deletes the tenants of an environment
luna generate Writes a typed Swift client for your luna types
luna sdk Writes out the TypeScript, Python or Swift SDK
luna fork Copies a luna to a new key or environment
luna export Writes an environment’s lunas to an archive
luna import Creates lunas from an archive
luna restore Rewinds lunas to an earlier moment
luna logs Reads and follows an environment’s logs
luna traces Reads an environment’s traces
luna status Shows an environment, or one luna type, at a glance
luna indexes Shows an environment’s indexes and reads their rows
luna data Reads and changes the rows of a luna’s tables
luna files Lists, reads and writes a luna’s files
luna sandboxes Lists, stops and deletes your lunas’ sandboxes
luna tokens Makes, rotates and revokes API tokens
luna keys Makes, rotates and revokes publishable keys and secret tokens
luna signup Makes an account in your browser and logs this machine in
luna login Logs this machine in through your browser
luna logout Forgets this machine’s login
luna whoami Shows who you are and what commands act on here
luna orgs Creates and selects organisations and manages their members
luna projects Creates, selects and deletes projects
luna audit Reads the organisation’s record of changes
luna usage Shows what was used and what it cost
luna billing Shows the plan, credit, spending limits and a month of usage
luna upgrade Replaces this CLI with the version Luna runs
luna version Prints this CLI’s version

How a command picks what it acts on

You rarely name an organisation, project or environment. Each command finds them in this order, and the first one found wins.

What Found in
Organisation --org, then LUNA_ORG, then the organisation in the folder’s organisation/project, then the one luna orgs use chose, then your only organisation
Project --project, then LUNA_PROJECT, then the folder’s env file
Environment --env, then LUNA_ENV, then the folder’s env file, then production
Tenant --tenant, then the environment’s own tenant
Credentials --token, then LUNA_TOKEN, then this machine’s login

luna dev has no default environment. It stops when the folder names none.

A project is named as organisation/project, or by its name alone. A name alone belongs to the organisation in LUNA_ORG, or else the one luna orgs use chose.

With --token or LUNA_TOKEN, the organisation this machine chose is not used. In a script, name the project as organisation/project or set LUNA_ORG.

The folder’s env file

The CLI reads .env.local, then .env, from the app’s folder. When neither is there, it looks in each folder above, and stops at the root of the repository.

The app’s folder is the one with luna.config.ts. Run from a folder whose luna folder holds it, the CLI uses that luna folder. Pass --dir to point at another folder.

The CLI reads only LUNA_PROJECT and LUNA_ENV from the file. A variable set in your shell wins over the file, and a flag wins over both. A LUNA_TOKEN in the file is for your app’s own code, and the CLI never reads it.

Command Writes to .env.local
luna projects create, luna projects use LUNA_PROJECT
luna env create, luna env use LUNA_ENV, and LUNA_URL and LUNA_KEY once the environment has been deployed to

Options for where a command acts

Commands about an environment take these options. Commands about an organisation take --org and --token instead.

Option Type Default Does
--dir <DIR> path . The app’s folder. Its env file names the project and environment.
--project <PROJECT> text LUNA_PROJECT The project, by name or as organisation/project.
--env <ENV> text LUNA_ENV, then production The environment, by name.
--tenant <TENANT> text The environment’s own A tenant added to the environment, by name. default names the environment’s own.
--token <TOKEN> text LUNA_TOKEN, then your login An API token or account key to act with.

Moments and lengths

Options that take a moment, such as --at, --to and the --since of luna logs, read it in three ways.

Written as Means
2h ago or 2h That long before now
2026-11-09T10:00:00Z That time, in RFC 3339
1793491200000 That many milliseconds since the Unix epoch

A length, such as the --since of luna status, is a number and a unit: 90s, 15m, 2h or 3d. Units also take words, such as 30 minutes.

Environment variables

Variable Does
LUNA_TOKEN Acts with this API token or account key instead of this machine’s login
LUNA_ORG The organisation
LUNA_PROJECT The project
LUNA_ENV The environment
LUNA_NODE The Node.js that loads your app. node by default
LUNA_PYTHON The Python that loads your Python lunas. python3 by default
LUNA_SDK The TypeScript SDK’s folder. By default, the luna package in the node_modules of the app’s folder or a folder above it
LUNA_PYTHON_SDK The Python SDK’s folder, for loading Python lunas
LUNA_NO_BROWSER luna login and luna signup print the address to open, and leave the browser alone. Any value but empty or 0
LUNA_NO_VERSION_CHECK Set to 1 to turn off the warning when this CLI’s version differs from Luna’s

Output and errors

Every command prints its answer on standard output and its messages on standard error. Commands that take --json print the answer as JSON instead of a table.

When a command fails with --json, it prints one JSON object on standard error, with an error object of four fields.

Field Holds
message What went wrong, as the CLI would print it
exitCode The exit code the command ends with
status The HTTP status Luna answered with, or null
code Luna’s error code, or null

Exit codes

Code Means
0 Done
1 Failed for any reason not below
2 The command is written wrongly, such as an unknown option or a missing argument
3 Not logged in, or Luna refused the login or token
4 The login or token is not allowed to do this
5 Not found
6 The command asks before a change, and no terminal can answer. Pass --yes

Good to know

  • Commands that delete or rewind something ask first at a terminal. --yes skips the question. Without a terminal and without --yes, they change nothing and end with exit code 6.
  • luna deploy asks before a change its preflight flags. Without a terminal and without --yes, it deploys nothing and ends with exit code 6.
  • Every command that reaches Luna warns on standard error when this CLI’s version differs from Luna’s. luna upgrade installs Luna’s version.
  • luna login keeps the login in ~/.luna/credentials.json, which only your user can read.

Examples

Act on another environment once

luna status --env staging

Act on a project from a script

LUNA_TOKEN=<API_TOKEN> luna status --project <ORGANISATION>/<PROJECT> --env production

Get errors as JSON

luna env delete pr-42 --yes --json

Was this page helpful?