# CLI

Covers: the install, the sign-in and every command of `poema` that a user of an organization runs.

For: developers and agents who work from a shell.

An instance is a `Task` in code.

`poema` drives poema cloud from a shell: it makes, watches, enters, suspends and forks instances, and saves keys. The
commands below are grouped by what you do with them.

## Install

`poema` runs on Node 22.19 or later. It is not on npm: this site carries its package.

```
npm install -g https://client-test.poema.dev/dl/poema-cli-0.1.0.tgz
```

## Sign in

With poema login:

Sign in from the shell, with no key to copy:

```
poema login --url https://client-test.poema.dev
```

It prints a link and a code, you approve the code in the dashboard (an Admin's sign-in: a User cannot make a key), and
it keeps an API key of your organization, named `login-…` on API keys, until `poema logout` revokes it. The SDK and
`poema-mcp` read it too.

With an API key:

It reads the same variables as the SDK, and takes manifests in YAML or JSON:

```
export POEMA_URL=https://api.client-test.poema.dev
export POEMA_API_KEY=poema_ns_...

echo '{"apiVersion": "poema.dev/v1alpha1", "kind": "Task", "metadata": {"name": "hello"},
  "spec": {"command": ["sh", "-c", "echo hello; sleep 600"], "gateway": {"name": "default"}, "debug": true}}' | poema apply -f -
poema get tasks
poema logs hello
poema terminal hello             # a shell in it (debug: true turns the terminal on)
poema forward hello 3000:3000    # 127.0.0.1:3000 here, to port 3000 inside it
```

In a script or a CI job, set `POEMA_URL` and `POEMA_API_KEY` from the job's secrets, with a key made for that job alone
([Team and access](https://client-test.poema.dev/docs/team.md)).

- `poema login --url URL` and `poema logout` sign in through this site and out again, as above.
- `poema version` (or `poema --version`) prints the CLI's version.
- Every command takes `--url` in place of `POEMA_URL` (keep the key in `POEMA_API_KEY`: on the command line it would
  stay in your shell's history and `ps`), and `-o json` or `-o yaml` where it prints a list
  or a resource.

## Instances

- `poema apply -f FILE` creates or updates the resources in a file, `-` for stdin. With `--from NAME` every Task in it is made from the suspended instance `NAME`, a prepared environment, as a fork (`--memory` for its memory too).
- `poema get KIND [NAME] [-o json|yaml]` lists or shows `tasks`, `workspaces`, `gateways`, `models` or `secrets`; `poema get tasks --phase Running,Pending` lists only those phases.
- `poema describe task NAME` shows an instance's spec, status, conditions, token counts and its last 20 activity
  entries, refused hosts included.
- `poema watch task NAME` prints a line per change of its status.
- `poema logs NAME [-f] [--tail N]` is its command's output, `--tail` its last N lines.
- `poema suspend NAME` and `poema resume NAME` suspend it, memory and files kept, and resume it where it stopped.
  `poema suspend` returns at once: `poema get tasks` shows when it is `Suspended`.
- `poema timeout NAME SECONDS` suspends it SECONDS from now, at most your plan's session length; 0 sets that length.
- `poema fork NAME NEW [NEW...] [--memory] [--suspend]` forks the suspended instance `NAME` into a new one of each name,
  each on a copy of its workspace, or with `--memory` of its memory too. With `--suspend` each fork stays suspended,
  copied at once: a snapshot, to resume or fork later.
- `poema delete KIND NAME [--no-wait]` deletes a resource, and for an instance waits until it is gone unless told not to.
- `poema ingress NAME` lists the listeners of an instance's Gateway and where each is reached.
- `poema mcp report NAME [--tools]` lists the MCP servers a running instance's workspaces and repositories declare, and `poema mcp tools URL`
  the tools the server at `URL` offers.

## Work inside an instance

These need an instance made with `debug: true` (Access from your machine on the dashboard).

- `poema exec NAME -- CMD [ARGS...]` runs a command in it, when it was made with `debug: true`.
- `poema terminal NAME [--cwd DIR]` opens a shell in it, in `DIR` or its first cloned repository, when it was made with
  `debug: true`.
- `poema forward NAME [LOCAL:]REMOTE` listens on `127.0.0.1:LOCAL` and carries each connection to `127.0.0.1:REMOTE`
  inside it, also with `debug: true`.
- `poema ssh NAME [-- SSH-ARGS...]` opens an SSH session in it with OpenSSH's `ssh`, also with `debug: true`; what
  follows `--` is ssh's own, after the host: a command, or `-L` and the like.
- `poema ssh-config [NAME] [--write]` prints the one SSH block that reaches every instance, `Host *.poema`, for `ssh`,
  `scp`, `sftp` and editors, and with `--write` puts it in `~/.ssh/config`. Each instance is then
  `NAME.NAMESPACE.poema`; with `NAME`, it checks that instance and says its host.
- `poema code NAME [--editor code|cursor] [--folder DIR]` opens it in VS Code's or Cursor's Remote-SSH, in `DIR` or its
  first cloned repository, also with `debug: true`.

## Keys and secrets

- `poema secret set NAME KEY=VALUE ...` stores a secret and `poema secret list` shows their names and keys, never their
  values. Give a value as `KEY=@FILE` (a file's text), `KEY=-` (stdin) or `KEY='$ENV'` (an environment variable, in single
  quotes), so it stays out of your shell's history and `ps`.
- `poema credential add -f FILE [value=@FILE]` saves a key on the Keys page by id: `FILE` says what it is, such as
  `{"kind": "static_key", "label": "GitHub key", "service": "github-token"}`, where `service` is one of the services Keys lists, and the value comes as `@FILE`, `-` or `'$ENV'`, never
  typed on the line. It prints the key's id. `poema credential list [ID]` shows them (never a value),
  `poema credential replace ID value=@FILE` replaces one and `poema credential remove ID` removes one. An Admin runs these
  ([Secrets and keys](https://client-test.poema.dev/docs/secrets.md)).
- `poema orgapp list` shows your organization's own sign-in apps (never a client secret), `poema orgapp set --service NAME`
  (or `--issuer URL`, or `--mcp-url URL`) `--client-id ID client_secret=@FILE` sets one, and `poema orgapp remove ID` removes
  one, after which sign-ins use poema's app again. An Admin runs them, and the secret comes as `@FILE`, `-` or `'$ENV'`,
  never typed on the line.
- `poema service add -f FILE`, `poema service list` and `poema service remove NAME --expected-version VERSION` manage your organization's own
  service entries; `poema help` gives their options.

## Usage and quota

- `poema usage [--from DAY] [--to DAY]` is your organization's model spend and compute, in total, by model and by day
  (`DAY` is `YYYY-MM-DD`).
- `poema quota get` shows your organization's quota next to what it has in use. Changing a quota is for operators: your plan sets it ([Plans, limits and billing](https://client-test.poema.dev/docs/plans.md)).

## Commands for operators

`poema help` also lists commands for poema's operators (`apikey`, `audit`, `sessions`, `events`, `namespaces`,
`quota set`). Your keys are owner keys, so these answer `Forbidden`: make and revoke API keys on Settings, Account
([Team and access](https://client-test.poema.dev/docs/team.md)). For one instance's recent activity, use `poema describe task NAME`.

## Example: an instance to work in

```
poema apply -f - <<'EOF'
kind: Task
metadata: {name: work}
spec:
  command: [sleep, infinity]
  gateway: {name: default}
  debug: true
EOF
poema exec work -- git clone --depth 1 https://github.com/octocat/Hello-World
poema exec work -- ls Hello-World
poema suspend work
```

A command your role may not run answers `error: Forbidden: ...`. `poema help` lists every command, the operator's among them.

Last checked: unreleased checkout.
