# CLI

Source: https://openpanel.sh/docs/cli

OpenPanel from a terminal and in CI, with everything the API offers.

`openpanel` runs the operations of the [API](/docs/api) from a terminal: projects, services and their settings, deploys and rollbacks, variables and secrets, domains, servers, project access and API keys. Every command takes `--json` and then prints the API's own JSON, for scripts and AI agents.

## Install [#install]

```sh
npm install -g https://cdn.openpanel.sh/cli/0.1.0/openpanel-cli-0.1.0.tgz
```

It needs Node.js 20 or newer. `npx -y https://cdn.openpanel.sh/cli/0.1.0/openpanel-cli-0.1.0.tgz <command>` runs it without installing.

OpenPanel serves the package itself, one file per version, with its SHA-256 beside it at
[cdn.openpanel.sh/cli/0.1.0/SHA256SUMS](https://cdn.openpanel.sh/cli/0.1.0/SHA256SUMS). It is not on npm's registry: a
package called `openpanel-cli` there would not be OpenPanel's. To check the file before installing:

```sh
curl -fsSLO https://cdn.openpanel.sh/cli/0.1.0/openpanel-cli-0.1.0.tgz
curl -fsSL https://cdn.openpanel.sh/cli/0.1.0/SHA256SUMS | shasum -a 256 -c
npm install -g ./openpanel-cli-0.1.0.tgz
```

## Sign in [#sign-in]

```sh
openpanel login
```

The CLI shows a code and opens `openpanel.sh/cli`, where you type the code and choose **Sign in the CLI**. The CLI then acts as you, in every organization you belong to. On a machine without a browser, such as a server or a CI job, use an API key instead: set it as `OPENPANEL_TOKEN`. See [Sign in](/docs/cli/sign-in).

`openpanel whoami` shows who the CLI acts as, and `openpanel logout` signs it out: it ends the CLI's session and forgets its token.

## Work in a project [#work-in-a-project]

Commands take `--project` (the project's slug, name or id) and `--service` (the service's name or id). To leave them out, link a folder once:

```sh
openpanel link --project shop --service web
```

This writes `.openpanel.json` in the folder. Commands run in that folder, or in any folder below it, use that project and service. See [Link and deploy](/docs/cli/deploy).

## Your first deploy [#your-first-deploy]

With a [server connected](/docs/servers), a project and a service from a public image take three commands:

```sh
openpanel projects create shop
openpanel services create web --project shop --image nginx:1.27 --port http:80 --public --server my-server
openpanel deploy web --project shop --wait
```

A public service with an HTTP port gets an opnl.app address at once; `openpanel domains --project shop` shows it. Every command is on the [command reference](/docs/cli/commands).

## Options for every command [#options-for-every-command]

| Option | |
|---|---|
| `--json` | Print the API's JSON instead of tables |
| `-p, --project <project>` | The project, by slug, name or id |
| `-s, --service <service>` | The service, by name or id |
| `--org <slug or id>` | Another of your organizations, for this command only |
| `-y, --yes` | Confirm a destructive step without being asked; needed when no one is at a terminal |
| `--url <address>` | Another OpenPanel than `https://openpanel.sh` |
| `-h, --help` | The usage of the command's group, such as every `projects` command |
| `-v, --version` | The CLI's version |

`openpanel help` lists the command groups, and `openpanel help <group>` shows one group's commands.

## Environment [#environment]

| Variable | |
|---|---|
| `OPENPANEL_TOKEN` | An API key (`opk_…`) or CLI token (`opc_…`) to use instead of the saved sign-in |
| `OPENPANEL_URL` | The OpenPanel to talk to; `--url` wins over it |
| `OPENPANEL_ORG` | The organization to work in, by slug or id; `--org` wins over it |
| `OPENPANEL_CONFIG_DIR` | Where the sign-in is kept. By default `~/.config/openpanel` (or `$XDG_CONFIG_HOME/openpanel`), and `%APPDATA%\openpanel` on Windows |

## Exit codes [#exit-codes]

| Code | Meaning |
|---|---|
| `0` | Done |
| `1` | Failed. The CLI prints the API's sentence, such as "This API key's scope is deploy; this needs admin." |
| `2` | Used wrongly: an unknown command or option, a missing argument, or a destructive step with no `--yes` and no one at a terminal to ask |

With `--json`, a failure is printed on standard error as `{"error":{"message":"…","code":"…","status":403}}`.

<Cards>
<Card href="/docs/cli/sign-in" title="Sign in" description="Through the browser with a code, or with an API key." />

<Card href="/docs/cli/deploy" title="Link and deploy" description="Tie a folder to a service and deploy it." />

<Card href="/docs/cli/commands" title="Command reference" description="Every command, grouped by what it works on." />

<Card href="/docs/cli/ci" title="Use in CI" description="GitHub Actions and GitLab CI with an API key." />
</Cards>