# CLI

> Install the CLI, sign in, and manage apps, specs, changesets and records from a terminal.

Source: https://docs.ligament.ai/developers/cli/

The `ligament` command line tool wraps the API for terminals, scripts and CI jobs. Use it to pull your app definitions into files, plan and propose changes as changesets, list and change records, and keep an eye on workflow runs and approvals. Every command authenticates with an API key, so a script can only do what its key allows.

The full list of commands and options is in the [CLI reference](https://docs.ligament.ai/reference/cli/index.md).

## Get the CLI

The CLI is the Node.js package `@ligament/cli`, which installs the `ligament` command. Publishing it on the public npm registry is **Coming**: until then `npm install` from the registry won’t find it. To get the package, contact hello@ligament.ai.

Check it runs:

```sh
ligament --version
```

```plaintext
0.1.0
```

## Sign in

The CLI reads two environment variables:

| Variable | Value |
| --- | --- |
| `LIGAMENT_URL` | Your workspace’s address, for example `https://app.ligament.ai`. Required |
| `LIGAMENT_API_KEY` | An API key |

It also reads a `.env` file in the current directory, so you can keep both there for a project. Variables already set in your shell take precedence over the file.

### With a key you create

1.  Create a key in **Settings › API keys** with the scopes your work needs (see [API keys and scopes](https://docs.ligament.ai/developers/api-keys/index.md)). For reading and proposing spec changes that’s `spec:read` and `spec:propose`; for records, `records:read` and maybe `records:write`.
    
2.  Put it where the CLI looks:
    
    ```sh
    export LIGAMENT_URL=https://app.ligament.ai
    export LIGAMENT_API_KEY=<your key>
    ```
    
3.  Run any command, for example `ligament records list incident -n 2`.
    

### With `ligament login`

`ligament login` creates a key for you through the browser. Set `LIGAMENT_URL` first: it opens the **Authorize the Ligament CLI** page at that address (or prints the address if no browser opens). You’re asked whether to add any admin scopes, then select **Authorize**.

\[Screenshot: The Authorize the CLI page: the CLI gets a new API key with full access, with optional admin scopes listed below and an Authorize button\]

The page creates a key named “CLI” with full access (`*`) plus the admin scopes you ticked, and hands it to the waiting terminal:

```plaintext
✔ Authentication successful!

✓ Saved API Key to .env
```

The key is appended to `.env` in the directory you ran `login` from. Keep that file out of version control. The key appears in **Settings › API keys** like any other, and you revoke it there.

**Note**

If the page that opens isn’t your workspace, check `LIGAMENT_URL` (in your shell or in `.env`). Older setups that set `LIGAMENT_APP_URL` for `login` still work; `LIGAMENT_URL` wins when both are set.

## Command families

| Commands | Scopes | What they do |
| --- | --- | --- |
| `ligament records list`, `get`, `history`, `changes`, `change` | `records:read`, `records:write` | Read and change records, including effective-dated ones |
| `ligament spec list`, `get`, `pull`, `validate`, `plan`, `apply`, `history`, `schema`, `catalog` | `spec:read`, `spec:apply` | Read app artefacts (pages, access rules and so on) as files, plan changes, apply them |
| `ligament changeset list`, `show`, `create`, `add`, `remove`, `ready`, `plan`, `apply`, `discard` | `spec:read`, `spec:propose`, `spec:apply` | Propose several artefact changes for review, then apply them together |
| `ligament app init`, `validate`, `publish`, `install`, `uninstall`, `list` | `apps:write`, `apps:install` | Author an app manifest locally and publish or install it |
| `ligament workflows`, `runs`, `cancel`, `replay` | `workflows:read`, `workflows:run` | List workflows and runs, show a run’s stages, cancel or replay a run |
| `ligament approvals`, `approve`, `reject` | `approvals:decide` | List and decide approvals waiting on a person |
| `ligament secrets`, `prompts`, `endpoints`, `skills`, `rag` | varies | Manage workspace secrets, prompt templates, endpoints, skills and RAG collections |
| `ligament agent start`, `tunnel`, `serve-tools` | `ai:use` for `agent start` | Run agents on your own machine with a local model and tools |

`ligament <command> --help` lists the options for each.

### Records

Filters are `field.op.value` and repeat. The list prints one record per line, then a count:

```sh
ligament records list incident -f priority.eq.critical -f state.eq.in_progress --sort=-createdAt -n 2
```

```plaintext
cmx1ws1sh004rrszicroqvw7t {"title":"Payments API returning 500s","impact":"high","number":"INC0000035","urgency":"high",…}
cmx1vv4ef011vfeutovalscd8 {"tags":["hardware"],"title":"Laptop battery swelling (#33)","impact":"low","number":"INC0000034",…}
2 of 13
```

Add `--json` for the raw API response. Filters and sorting work as described in [Lists, filters and pagination](https://docs.ligament.ai/developers/pagination/index.md).

### Spec and changesets

```sh
ligament spec list
```

```plaintext
ADDRESS                     LAYER   CUSTOMISED  CONFLICTS  HASH              UPDATED
crm/page/crm_home           custom  yes                    04c3e5a99107abb3  2026-12-01T09:21:04.590Z
csm/page/csm_home           custom  yes                    ba3ac2c15c5ef956  2026-12-01T09:21:04.599Z
…
```

```sh
ligament spec get crm/page/crm_home
```

```plaintext
crm/page/crm_home  layer custom  v0  hash 04c3e5a99107abb3  customised
{
  "app": "crm",
  "key": "crm_home",
  "title": "Sales home",
  "blocks": [
    …
```

The summary line goes to stderr and the doc to stdout, so `ligament spec get … > page.json` saves just the doc. `ligament spec pull <address>` writes `<type>.<key>.json` files plus `.ligament/spec.lock.json`, which remembers the version each file started from. `plan`, `apply` and `changeset create` send that version, so changes someone else made in the meantime are merged rather than overwritten. The workflow is described in [Changesets](https://docs.ligament.ai/guides/building-apps/changesets/index.md).

### Workflow runs

```sh
ligament runs -n 3
```

```plaintext
STATUS     WORKFLOW                  DURATION    STARTED     RUN ID
──────────────────────────────────────────────────────────────────────────────────────────
complete   csm/incident_account      120ms       3m ago      a59bb9b1-276c-42f7-82e9-898bd79b087c
complete   csm/incident_account      72ms        47m ago     e3b8bf71-3d5e-4935-b12a-2b40f96c05a4
complete   csm/incident_account      318ms       47m ago     5bb517a1-ad9a-4031-a61c-defd22b29cce
```

`ligament runs <run id>` shows one run’s stages.

## Errors

When the API refuses a call, the CLI prints the error and the API’s `fix` on the next line, then exits with code 1:

```plaintext
Error (insufficient_scope): This API key lacks the "spec:read" scope.
Use a key that has "spec:read" (or "*"). Create one in Settings → API keys; the scopes are listed at https://docs.ligament.ai/reference/scopes/.
The key needs a spec scope: spec:read (read, plan), spec:propose (changesets) or spec:apply.
```

`approvals` with a `*` key fails the same way, because `approvals:decide` is an admin scope that `*` doesn’t include. Without a key at all:

```plaintext
Error: LIGAMENT_API_KEY is not set
Run `ligament login`, or export it in your shell.
```

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | OK |
| `1` | Error: invalid doc, missing permission, network problem and so on |
| `2` | Conflict (`spec` and `changeset` commands): nothing was applied, because of a real conflict or a clean merge you didn’t accept with `--merge` |
| `3` | Proposed, not applied (`spec` and `changeset` commands): the workspace requires a person to apply this change, and it’s waiting in **Build › Changes** |

Scripts can rely on `2` and `3` to tell “someone else changed this” and “waiting for review” apart from real failures.
