OpenLegion · Docsllms.txt
Docs pages

CLI reference

The CLI in the npm package openlegion. This page is npx openlegion help, generated from the CLI itself.

The OpenLegion CLI
Run it as npx openlegion <command>.

Usage
  npx openlegion init    [dir] [--yes] [--force] [--no-login] [--port <n>] [--source <code>] [--profile <name>]
                         [--base-url <url>] [--no-browser] [--json]
  npx openlegion login   [--profile <name>] [--base-url <url>] [--no-browser] [--device-name <name>] [--json]
  npx openlegion logout  [--profile <name>] [--json]
  npx openlegion whoami  [--profile <name>] [--api-key <key>] [--base-url <url>] [--json]

  npx openlegion setup   [--tool claude|cursor|codex|vscode] [--diagnose] [--yes] [--json]
  npx openlegion mcp     [--profile <name>] [--base-url <url>]

  npx openlegion dev     [--port <n>] [--app <url>] [--connector <con_…|slug>] [--webhook-path <path> | --no-webhooks]
                         [--once] [--force-promote] [--json]
  npx openlegion listen  --forward-to <http://localhost:…/path> [--events <type|family.*|*>]… [--json]
  npx openlegion deploy  --url <https://your.app> [--prepare] [--live [--data-rights]] [--vercel-env <env>] [--wait]
                         [--secrets-file] [--header <name=value>]… [--webhook-path <path> | --no-webhooks]
                         [--allow-disable] [--force-promote] [--no-data-rights] [--forget-secrets] [--json]

  npx openlegion templates push  (--app <url> [--connector <con_…|slug>] [--header <name=value>]…
                                  | --file <spec.json> [--template <slug>])
                                 [--promote | --force-promote] [--dry-run] [--json]
  npx openlegion templates list  [--json]
  npx openlegion templates versions <slug> [--json]
  npx openlegion templates promote  <slug> <version> [--json]
  npx openlegion connectors pin  <con_…|slug> [--dry-run] [--allow-disable] [--json]
  npx openlegion events tail     [--type <type|family.*>] [--workspace <ws_…>] [--json]

  npx openlegion --version | npx openlegion help

npx openlegion init adds the kit to your Next.js app (TypeScript, App Router), or makes a new app in [dir]: one
route, openlegion/{tools,template,session,client}.ts, an /agent page with <AgentChat>, the packages, and a
sign-in that puts a test-mode key for the app in .env.local (unless git would commit it). It never overwrites
a file without --force, and running it again changes nothing. --source <code> says where the sign-in was
started from (a short code, such as a tutorial's): the approval page shows it, and it changes nothing else.

npx openlegion login signs this terminal in to an OpenLegion organization: it shows a code, you type it in your
browser and approve. It keeps a test-mode key for the CLI in ~/.config/openlegion/credentials.json.
In CI, set OPENLEGION_CLI_KEY instead (every command also takes --api-key, --base-url and --profile).
OPENLEGION_API_KEY is your app's key, with other scopes: the CLI never uses it.
The API is --base-url, else OPENLEGION_BASE_URL, else the saved profile's address (only with that profile's
own key), else https://api.openlegion.ai/platform/v1.

npx openlegion setup adds OpenLegion's MCP server (npx openlegion mcp) to your coding agent for this project, then opens it with
the setup guide in place. It finds Claude Code, Cursor, Codex and VS Code here, asks which, says what it will
write and asks once, then uses the tool's own way: claude mcp add --scope project (.mcp.json), this
project's .cursor/mcp.json, codex mcp add, or code --add-mcp. With no terminal it prints the lines to paste
and changes nothing. --diagnose starts with the guide that first says what OpenLegion would do for your app.

npx openlegion mcp is that server, which your coding agent starts (stdio): the setup and diagnose guides, and tools to
see what is done and the next step, sign in, add OpenLegion to an app, and read this project's runs, tool
calls and the docs. It uses the CLI's test-mode key, refuses a live one, and never shows a key.

npx openlegion dev keeps your agent live in test mode while you work: it reads your template from your running app,
checks the app refuses calls OpenLegion did not sign, pins the connector, runs Test connection and pushes
the template;
then, on every save, re-pins or pushes what changed, and prints runs and tool calls until Ctrl-C.
OpenLegion reaches your app through this terminal, with nothing listening and no tunnel: npx openlegion dev makes the
project a dev connector and a dev webhook endpoint (their secrets go into .env.local, unless git would
commit it) and forwards each call it verifies to your app. --connector with an https connector uses its URL.
Webhooks go to the kit route's /webhooks; --webhook-path /your/route sends them to another path on the
app. With --no-webhooks the session carries tool calls only: run npx openlegion listen --forward-to <url> beside it
to send the webhooks anywhere on this machine.

npx openlegion deploy wires your deployed app (https) to OpenLegion in your CLI key's mode. It finds the connector
and webhook endpoint for the app's URL, or makes them; with --prepare it gives existing ones new secrets,
the old ones working 24 h more so the running deployment is not cut off. New secrets go to your linked
Vercel project's env (vercel env add, on its stdin; preview for a test key, production for a live one, or
--vercel-env), else to 0600 files outside the project; never printed. A live key needs --live for that.
After you redeploy, OpenLegion reads your template from the deployment through the connector (so CI needs
no connector secret), and npx openlegion deploy runs Test connection, pins and pushes it, promoted (--wait waits up to
10 minutes for the redeploy). Until its secret files are deleted, and with --wait, npx openlegion deploy reads the
template itself, signed with the new secret. It never deploys, and refuses to run while a project .env*
file holds the CLI's key.
In test mode, with a linked Vercel project, it also puts your app's keys there: OPENLEGION_API_KEY and
OPENLEGION_DATA_RIGHTS_KEY (--no-data-rights: the first only). You approve them once in the browser; they
are never printed. A later run keeps them while Vercel has them, and --prepare replaces them (the old ones
work 24 h more).
Going live, from a terminal: --live with your test CLI key asks for one approval. An owner or admin types the
code in their browser (every owner and admin is emailed). OpenLegion then makes a live key for this run only (an
hour; revoked when the run ends, never written anywhere) and, with a linked Vercel project, your app's live
OPENLEGION_API_KEY in its production environment (--data-rights: OPENLEGION_DATA_RIGHTS_KEY too). The run wires
your live connector and webhook endpoint and waits for your redeploy: npx openlegion deploy --url <https://your.app>
--prepare --live --wait. In CI, use a live key as OPENLEGION_CLI_KEY (on the Keys page in live mode, the starting
point “Your deploy pipeline (CI)”).

npx openlegion listen forwards OpenLegion's webhooks to a URL on this machine, verified first, signature kept, through
the project's dev webhook endpoint (the one npx openlegion dev uses: starting one stops the other).

templates push --app reads your template from your running app's OpenLegion route and publishes it. When
the connector is that app's own (https, at the app's /mcp), OpenLegion reads it and no secret is needed;
otherwise the read is signed with the connector's secret (OPENLEGION_CONNECTOR_SECRET, or your app's
.env.local). --dry-run reads the template and says what a push would create, push and promote, and changes
nothing. The spec is checked when you push, and a refused push changes nothing (except that a new
template's name, made first, stays).

templates promote moves every workspace tracking the template to that version; rolling back is promoting
an older one (npx openlegion templates versions <slug> lists them). While the promoted version is not the latest,
someone chose it: npx openlegion dev and templates push --promote then push without promoting, and say so.
--force-promote promotes anyway.

Exit codes: 0 done · 1 refused · 2 usage · 3 network · 4 a pin that would take a tool away
(connectors pin and deploy, without --allow-disable).