# CLI reference

> Every jsflow command, the output and exit-code contract, and the environment variables.

`jsflow` is a command line for your account: apps, keys, usage, logs and rooms. It has no dependencies and needs Node 20 or newer. It is built to be driven by people and by coding agents.

```sh
npm install -g jsflow-cli
jsflow whoami      # reuses a login or token the CLI already has; shows who, the account and the scopes
jsflow login       # only if whoami says you are not logged in: a person approves the code
jsflow apps list
```

## The contract

This is frozen at 1.0. After that it only grows.

- **Output.** JSON on stdout when it is not a terminal, or with `--json`; text on a terminal. Streams (`records --follow`) are JSON lines. Progress and instructions for a person go to stderr, never stdout.
- **Errors.** On stderr as JSON: `{"err","message","hint","url"?,"scope"?}`. The `err` is one of the [error codes](https://jsflow.com/docs/reference/errors.md).
- **No prompts**, ever. Unknown flags fail.
- **Destructive commands** need `--confirm <id>`, the id of the thing being changed. Without it they print the plan and exit 4. `--dry-run` on any write prints the request and changes nothing.
- **Retries are safe.** Every POST sends an idempotency key, so repeating a create never creates two. `--retry <n>` waits out `Retry-After` on rate limits.
- **Secrets stay out of transcripts.** `keys create --kind secret` needs `--write-env <file>` (written with mode 0600) or `--stdout-secret`.

## Exit codes

| code | meaning |
|---|---|
| 0 | ok |
| 1 | error |
| 2 | usage: the command line is wrong; nothing was sent |
| 3 | auth: no or invalid token, a missing scope, a denied login |
| 4 | **needs a person**: `human_required` (the error has the dashboard link), or a destructive command without `--confirm` |
| 5 | not found |
| 6 | conflict (`app_id_taken`, `idempotency_conflict`, …) |
| 7 | retryable: `rate`, `unavailable`, a network error |

## Commands

| command | does | options |
|---|---|---|
| `jsflow login` | Log in with a device code (a person approves it in the browser, which opens by itself when it can), or store a token from stdin. | `--with-token` `--wait` `--scopes <value>` `--no-browser` |
| `jsflow signup` | Create a jsflow account and log in, in one step: the same device login as `login`, with the approval page opening on "Create your jsflow account". Works with `npx jsflow-cli signup`. | `--scopes <value>` `--no-browser` |
| `jsflow logout` | Revoke the stored token on the server and forget it. A token from JSFLOW_TOKEN is not touched. |  |
| `jsflow whoami` | Who the token belongs to, the account it is bound to, its scopes and expiry. |  |
| `jsflow apps list` | The account's apps. | `--limit <value>` `--cursor <value>` `--all` |
| `jsflow apps get <app>` | Show one app: its origins, limits and options. |  |
| `jsflow apps create <id>` | Create an app and its first publishable key. Safe to retry: it sends an idempotency key. | `--name <value>` `--origin <value>` `--dev` `--dry-run` `--idempotency-key <value>` |
| `jsflow apps update <app>` | Change an app's name, limits or options. | `--name <value>` `--require-tickets <value>` `--link-beacon <value>` `--max-peers <value>` `--max-rooms <value>` `--join-per-min <value>` `--dry-run` |
| `jsflow apps delete <app>` | Delete an app. Only a person can: the API answers human_required with a dashboard link. | `--dry-run` `--confirm <value>` |
| `jsflow apps origins add <app> <origin>` | Allow another page origin. | `--dry-run` |
| `jsflow apps origins remove <app> <origin>` | Stop allowing a page origin. | `--dry-run` `--confirm <value>` |
| `jsflow keys list` | An app's keys (never a secret value). | `--app <value>` `--limit <value>` `--cursor <value>` `--all` |
| `jsflow keys create` | Create a publishable or a secret key. A secret key is written to a file, never printed. | `--app <value>` `--kind <value>` `--name <value>` `--write-env <value>` `--env-name <value>` `--force` `--stdout-secret` `--dry-run` `--idempotency-key <value>` |
| `jsflow keys revoke <key>` | Revoke a key. Pages and servers using it stop within about 30 seconds. | `--app <value>` `--confirm-last` `--dry-run` `--confirm <value>` |
| `jsflow usage` | Usage: for an app over time (--app), or for the whole account this period. | `--app <value>` `--from <value>` `--to <value>` `--step <value>` |
| `jsflow records` | The recent-records log: joins, refusals, evictions, sessions, relay. | `--app <value>` `--room <value>` `--peer <value>` `--user <value>` `--type <value>` `--since <value>` `--from <value>` `--to <value>` `--follow` `--limit <value>` `--cursor <value>` `--all` |
| `jsflow rooms list` | The rooms open now, largest first, with live totals. | `--app <value>` `--sort <value>` `--limit <value>` `--cursor <value>` `--all` |
| `jsflow rooms get <room>` | One open room and its peers, by its exact name. | `--app <value>` |
| `jsflow rooms evict <room>` | Remove a user or a peer from a room (and optionally keep them out). | `--app <value>` `--user <value>` `--peer <value>` `--until <value>` `--reason <value>` `--dry-run` `--confirm <value>` |
| `jsflow blocklist list` | The app's blocklist. | `--app <value>` `--limit <value>` `--cursor <value>` `--all` |
| `jsflow blocklist add` | Block a user or a peer from joining. | `--app <value>` `--user <value>` `--peer <value>` `--until <value>` `--reason <value>` `--dry-run` `--idempotency-key <value>` |
| `jsflow blocklist remove <entry>` | Remove a blocklist entry. | `--app <value>` `--dry-run` `--confirm <value>` |
| `jsflow billing` | Plan, period, spend cap and cap state (read only). |  |
| `jsflow billing open` | The dashboard page where a person changes the plan, the cap or the payment details. |  |
| `jsflow tokens list` | Access tokens (never their values). | `--limit <value>` `--cursor <value>` `--all` |
| `jsflow tokens revoke <id>` | Revoke an access token ("current" is the one in use). A token cannot create tokens: a person does that in the dashboard. | `--dry-run` `--confirm <value>` |
| `jsflow errors [code]` | What an error code means and how to fix it (offline). |  |
| `jsflow tickets mint` | Sign a join ticket offline, to test an app that requires tickets. Needs the secret key in the environment. | `--app <value>` `--room <value>` `--sub <value>` `--region <value>` `--ttl <value>` `--secret-env <value>` |
| `jsflow api <method> <path>` | A raw call to the API: jsflow api GET /apps/myapp. Writes honour --dry-run. | `--data <value>` `--query <value>` `--dry-run` `--idempotency-key <value>` |
| `jsflow help [topic]` | Help on a topic. `jsflow help agents` prints rules for coding agents, ready for an AGENTS.md. |  |
| `jsflow upgrade` | How to upgrade the CLI (it prints the command; it changes nothing). |  |

Global options: `--json`, `--token`, `--api`, `--actor`, `--retry`, `--help`.

## Environment

| variable | |
|---|---|
| `JSFLOW_TOKEN` | an access token; overrides a stored login |
| `JSFLOW_API` | the API base URL (default `https://api.jsflow.com/v1`) |
| `JSFLOW_AUTH_URL` | the authorization server, for login |
| `JSFLOW_APP` | the default for `--app` |
| `JSFLOW_ACTOR` | who is acting for you, shown in the audit log as "you via actor" (up to 64 printable characters, for example `claude:usage-report`) |
| `JSFLOW_SECRET_KEY`, `JSFLOW_KEY_ID` | for `tickets mint` |
| `JSFLOW_CONFIG_DIR` | where the login is stored (default `~/.config/jsflow`) |

Source: https://jsflow.com/docs/agents/cli/
