---
title: Command line
description: Get the peal command line, sign in or use an API key, choose the workspace, and read its answers as JSON.
sidebar:
  icon: terminal
---

With `peal`, you work with a Peal instance from a terminal. You sign in once, in a browser, and every command then acts with your role in each of your workspaces. A script or an agent that nobody attends runs it with a workspace's [API key](#api-key) instead, and reads its answers as [JSON](#json).

From the command line you can:

- write and discard drafts, and upload and import media;
- schedule, publish, move and cancel posts, and follow up on those that went out;
- read analytics, billing, members and invitations, and invite people;
- save a copy of your data.

You connect channels and change roles in the web app.

## Get it [#install]

There are no released builds yet. You build it from a clone of the repository, with Bun installed:

```sh
bun install --frozen-lockfile
bun nx run peal-cli:build
packages/peal-cli/dist/peal --help
```

`packages/peal-cli/dist/peal` is a single file with Bun inside. Copy it anywhere on your `PATH`.

## Choose the instance [#instance]

Point `peal` at the address you open Peal at, such as `https://peal.example.com`. Give it with `--api-url` or `PEAL_API_URL`, and the flag wins if you set both. Without either, `peal` uses `http://localhost:3000`, a server running from source. It never sends an API key there unless you name that address yourself ([Run it with an API key](#api-key)).

```sh
export PEAL_API_URL=https://peal.example.com
peal health
```

> **Your credentials only go over HTTPS**
>
> `peal` sends your sign-in or an API key over HTTPS, or to this machine
> (`localhost`), and nowhere else. Over plain HTTP, anything on the way could
> read them, so the command is refused before it sends anything, and `peal
> doctor` says so. For a self-hosted server without TLS on a network you trust,
> pass `--insecure-http`, or set `PEAL_INSECURE_HTTP=true`.

`peal health` tells you whether the instance answers, so a script can wait for it. It exits with one of these codes:

| Exit code | When                                                            |
| --------- | --------------------------------------------------------------- |
| 0         | The instance answers                                            |
| 1         | It's unreachable (after 5 seconds), or it answers with an error |

`peal health --json` prints what it measured, such as `{"healthy": true, "milliseconds": 12, "url": "https://peal.example.com"}`. To check the rest of your setup, run [`peal doctor`](#doctor).

## Sign in [#login]

To sign in, run:

```sh
peal login
```

It prints an address and a code of eight letters and digits:

```text
To sign in to https://peal.example.com, open https://peal.example.com/device in a browser and enter the code WDJB-MJHT.
Or open https://peal.example.com/device?user_code=WDJBMJHT, where the code is filled in.
Waiting for you to approve the sign-in (the code works for 10m)…
```

1. **Open the address**

    Sign in to Peal there if you haven't yet.

2. **Check the code and allow**

    Check that the code matches the one in your terminal, then click **Allow**.

3. **Go back to the terminal**

    `peal login` tells you where it saved the sign-in.

The code works for 10 minutes. If you click **Deny**, the sign-in is refused and `peal login` stops.

> **Approve only a code you asked for yourself**
>
> Whoever started the sign-in gets your access.

`peal` asks to do what your role allows in your workspaces, to schedule and publish posts, and to stay signed in. It saves the sign-in for that instance in `credentials.json`, which only you can read. The file goes in the first of these folders that's set:

| Folder                  | Used when                |
| ----------------------- | ------------------------ |
| `PEAL_CONFIG_DIR`       | It's set                 |
| `$XDG_CONFIG_HOME/peal` | `XDG_CONFIG_HOME` is set |
| `%APPDATA%\peal`        | On Windows               |
| `~/.config/peal`        | Otherwise                |

Each instance has its own sign-in, keyed by its address, so you can be signed in to several. `peal` renews its access by itself, and it never prints its tokens.

**Two-step verification**

When your account has [two-step verification](/guides/workspace/account#two-step) on, the browser asks for the code from your authenticator app, or a recovery code, as you sign in there. The command stays the same.

A workspace can [require it](/guides/workspace#require-two-step). If yours does and your account doesn't have it on, every command is refused, and says why. Turn it on in the web app's account settings, then run the command again with the same sign-in. `peal doctor` names such a workspace.

No command manages two-step verification. With `PEAL_API_KEY` nothing changes, because keys aren't concerned.

**A sign-in made before publishing was asked for**

A sign-in made before `peal` asked for publishing doesn't hold it. The commands that put posts out tell you so, and ask you to run `peal login` again and approve it.

## Who am I [#whoami]

To see who you're signed in as, run:

```sh
peal whoami
```

```text
Signed in to https://peal.example.com as Sam Example <sam@example.com>.
Workspaces:
  Studio (owner)    studio   7c9e6679-7425-40de-944b-e07fc1f90ae7
  Clients (editor)  clients  3f2b8a41-5d6c-4e7f-8a9b-0c1d2e3f4a5b
```

Each workspace comes with its slug and its id, and `--workspace` takes either.

A key isn't a person. With an [API key](#api-key), `peal whoami` tells you which key it is instead, through `GET /api/v1/credential`. You get its name, its workspace's name and id, its permissions and when it expires, but never the key:

```text
The API key in PEAL_API_KEY is "nightly" (peal_AbCd…), of the workspace Studio (7c9e6679-7425-40de-944b-e07fc1f90ae7), on https://peal.example.com.
Permissions: channel:read, post:read, post:create.
It never expires.
```

When the sign-in stops working, because it was revoked or your account was banned, `peal whoami` says so and asks you to run `peal login` again. Before you've signed in at all, it tells you you're not signed in.

## Sign out [#logout]

To sign out, run:

```sh
peal logout
```

`peal logout` tells the instance to revoke the sign-in, then forgets it. It forgets it even when the instance doesn't answer within 5 seconds.

## Run it with an API key [#api-key]

For a run nobody attends, such as a scheduled job or an agent on a server, set `PEAL_API_KEY` to a workspace's [API key](/guides/workspace#api-keys). The key acts in its own workspace, so the run needs nothing else:

```sh
export PEAL_API_URL=https://peal.example.com
export PEAL_API_KEY=peal_…
peal doctor
peal drafts list --json
```

`peal` reads the key from the environment only. There's no flag for it, because a flag lands in your shell's history and in the list of processes. `peal` never prints it. While `PEAL_API_KEY` is set, it wins over a saved sign-in, and a blank value counts as no key.

With a key, `--api-url` or `PEAL_API_URL` must name the instance the key was made on. A key goes to no default address, so without either the command stops with `api_url_required` and sends nothing.

A key acts in the workspace it belongs to, so you don't need `--workspace` or `PEAL_WORKSPACE`. `peal whoami` and `peal doctor` say which workspace that is. If you name one, give its id, not its slug, because a key can't look workspaces up. A slug stops the command with `workspace_id_required`, and the instance refuses another workspace's id (`forbidden`). A blank `PEAL_WORKSPACE` names no workspace.

With the key alone, each command first asks the instance whose key it is, and that request counts toward the [rate limit](/developers/conventions/rate-limits#rate-limits). Setting `PEAL_WORKSPACE` to the key's workspace id, which `peal whoami` prints, saves one request per command.

A partner key belongs to no workspace. Name one of its partner's workspaces by its id, or the command stops with `workspace_id_required`.

The key does what its permissions allow, and no more. Without `post:schedule`, for example, it can write drafts but not schedule them. A refusal comes in the server's words, with the permission the key lacks.

The key fails in two other ways:

- What only a person does is refused before any request (`person_required`): `peal login`, `peal account export` and `peal account apps`, `peal members list`, and every `peal invitations` command.
- A key the server no longer accepts (revoked, expired or another server's) is reported as such (`api_key_refused`), not as a sign-in to renew.

## Check the setup [#doctor]

`peal doctor` checks what a run would use, and changes nothing. Run it first, before a script or an agent does anything else:

```sh
peal doctor
peal doctor --workspace studio --json
```

```text
ok  api-url        https://peal.example.com, from PEAL_API_URL.
ok  health         The server answers.
ok  ready          The server and its database both answer.
ok  changelog      The API's latest release is of 2026-11-09: The API as the SDKs' release 0.3.0 calls it: 49 operations. Later entries list what each release adds to it.
ok  credential     The sign-in saved for https://peal.example.com. PEAL_API_KEY is not set.
ok  access         Signed in as Sam Example <sam@example.com>, in 2 workspaces: Studio (studio, 7c9e6679-7425-40de-944b-e07fc1f90ae7, owner); Clients (clients, 3f2b8a41-5d6c-4e7f-8a9b-0c1d2e3f4a5b, editor).
ok  publish-scope  The sign-in has workspace:publish: it can schedule and publish, where your role allows it.
ok  workspace      Commands act in Studio (studio, 7c9e6679-7425-40de-944b-e07fc1f90ae7, owner), from --workspace.
ok  mcp            MCP clients connect to https://peal.example.com/api/mcp: peal mcp shows how.
```

It runs these checks, in this order:

| Check           | What it looks at                                                                                                                                                                                                               |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `api-url`       | The instance's address, and whether it came from `--api-url`, `PEAL_API_URL` or the default. It fails for plain HTTP beyond this machine, unless `--insecure-http` allows it, and for the default while `PEAL_API_KEY` is set. |
| `health`        | That the server answers within 5 seconds.                                                                                                                                                                                      |
| `ready`         | That the server reaches its database.                                                                                                                                                                                          |
| `changelog`     | That it answers `GET /api/changelog` with the API's latest release ([Changelog](/developers/conventions/versioning#changelog)). A server that doesn't is older, or isn't a Peal server.                                        |
| `credential`    | Which credential a run uses: the key in `PEAL_API_KEY`, or the saved sign-in. It's never printed.                                                                                                                              |
| `access`        | That the credential works: who's signed in and where, or, for a key, that it can read the workspace's channels.                                                                                                                |
| `publish-scope` | Whether the sign-in can schedule and publish. It's skipped for a key, which has permissions rather than a scope. A sign-in without it is `ok`: it writes drafts, and that isn't something to work around.                      |
| `workspace`     | Which workspace commands act in, and where that choice came from.                                                                                                                                                              |
| `mcp`           | The address MCP clients connect to.                                                                                                                                                                                            |

Each check is `ok`, `failing` or `skipped`. A check is skipped when it can't be made, for example when the server doesn't answer, or when it doesn't apply. A failing check tells you what to do, on a line that starts with `To do:`. If any check fails, `peal doctor` exits with 1.

With `--json`, it prints `{"checks": [{"name", "status", "detail", "fix"}], "ok"}` on stdout, with `fix` only where there's something to do. When a check fails, it also prints the [failure](#json) `checks_failed` on stderr, with the names of the failing checks in `failed`.

## Connect an MCP client [#mcp]

To get what an MCP client needs, run:

```sh
peal mcp
```

It prints the instance's MCP endpoint and a configuration most MCP clients accept. It also warns you when the instance doesn't let MCP clients register themselves. [Connect an MCP client](/developers/mcp) explains the rest.

## Choose the workspace [#workspace]

Every command below acts in one workspace. Name it with `--workspace` (or `-w`), by its slug or its id, or set `PEAL_WORKSPACE` once for the commands that follow:

```sh
export PEAL_WORKSPACE=studio
peal drafts list
peal drafts list --workspace clients
```

If you belong to one workspace only, `peal` takes it. If you belong to several and name none, it lists their slugs and stops. With an [API key](#api-key), `peal` takes the key's own workspace, and you name one only by its id.

Each command does what your role allows there, as the web app does. A viewer reads. An editor writes, schedules, publishes and follows up. An owner or an admin also invites.

When the instance refuses, `peal` says why (your role, the post's status, the plan) and exits with 1. The refusal ends with the request's id and the error's code, such as `Request 019a7b2f-9a04-7b61-8c3d-2e5f7a1b4c68 (forbidden).` Quote that id when you ask for help ([Requests and answers](/developers/conventions#requests)).

## Output for scripts [#json]

With `--json`, a command prints the API's answer as one JSON document on stdout, and nothing else there. Instants are in ISO 8601, in UTC. Every command that reads or changes something through the API takes it, and so do `peal health` and `peal doctor`. `peal login`, `peal logout` and `peal mcp` don't.

```sh
peal post "Spring catalogue is out" --channel <channel-id> --now --json
peal posts show <post-id> --json
```

What the document holds depends on the command:

- Most print the answer of the endpoint they call, as the [API reference](/reference) describes it: a post, a page with `items` and `nextCursor`, or an array.
- A command whose endpoint answers without a body, such as `peal drafts discard`, `peal invitations revoke` or `peal webhooks delete`, prints `null`.
- `peal billing --json` holds the two answers it reads, under `billing` and `standing`.
- `peal health --json` and `peal doctor --json` print documents of their own ([Choose the instance](#instance), [Check the setup](#doctor)).

### Failures [#json-failures]

Under `--json`, a failure is one JSON document too. It goes to stderr, the exit code is 1, and stdout stays empty:

```json
{
  "error": {
    "code": "forbidden",
    "message": "This API key does not have the permission post:schedule. An owner or an admin of the workspace gives it to the key, or creates a key that has it.",
    "permission": "post:schedule",
    "reason": "missingPermission",
    "requestId": "019a7b2f-9a04-7b61-8c3d-2e5f7a1b4c68"
  }
}
```

When the API refuses, `error` is the error as the server sent it: its `code`, its `message`, the `requestId` and its own fields. [Error codes](/developers/conventions/errors#error-codes) lists every code. Branch on `code`, never on `message`.

The command line has codes of its own for what stops it before, or instead of, an answer from the API:

| Code                      | When                                                                                                                                                   |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `invalid_usage`           | The arguments can't be read: an unknown flag, or a missing argument.                                                                                   |
| `unreachable`             | No answer came from the instance: a refused connection, an unknown host, or a timeout.                                                                 |
| `unhealthy`               | `peal health` got an answer that isn't a healthy one.                                                                                                  |
| `unexpected_answer`       | The instance answered something the API's contract doesn't describe. It may be older, or not a Peal server.                                            |
| `not_signed_in`           | No sign-in is saved for the instance, and `PEAL_API_KEY` isn't set.                                                                                    |
| `sign_in_expired`         | The saved sign-in no longer works. Run `peal login` again.                                                                                             |
| `api_key_refused`         | The instance refused the key in `PEAL_API_KEY`: it's revoked, expired, or another server's.                                                            |
| `person_required`         | The command is for a person who's signed in, and `PEAL_API_KEY` is set.                                                                                |
| `api_url_required`        | `PEAL_API_KEY` is set, and neither `--api-url` nor `PEAL_API_URL` names the instance.                                                                  |
| `workspace_id_required`   | With an API key, the workspace is named by something other than its id. Or a partner key, or an application's token bound to no workspace, names none. |
| `workspace_required`      | You belong to several workspaces and named none.                                                                                                       |
| `workspace_unknown`       | You belong to no workspace with that slug or id.                                                                                                       |
| `no_workspace`            | You don't belong to any workspace yet.                                                                                                                 |
| `credential_store_failed` | The sign-in couldn't be read from, or saved to, `credentials.json`.                                                                                    |
| `checks_failed`           | `peal doctor` found failing checks, named in `failed`.                                                                                                 |
| `refused`, `failed`       | Anything else the command line refuses or fails at, with the reason in `message`.                                                                      |

An answer with an error status that carries no API error gets the API's general code for that status, such as `internal_error`, and the `requestId` when the server gave one.

An agent that runs commands rather than MCP tools works the same way ([Posting from an AI agent](/developers/agents#cli)).
