---
title: 'CLI Commands Reference'
url: 'http://phramecms.org/reference/cli-commands'
markdown_url: 'http://phramecms.org/reference/cli-commands.md'
bundle: reference
category: cli
package: phramecms/cli
summary: 'Complete reference for the ./bin/phrame CLI commands, global --json output envelopes, ExitCode enum, and the ./bin/phrame-mcp stdio entrypoint.'
source: 'https://github.com/PhrameCMS/docs/blob/main/reference/cli-commands.md'
updated_at: '2026-12-04T21:49:38+00:00'
---

# CLI Commands Reference

PhrameCMS provides two PHP CLI entrypoints inside a `phramecms/skeleton` project:

- **`./bin/phrame`** — runs `PhrameCms\Cli\CliApplication` with all commands tagged `CliApplication::COMMAND_TAG` (`phrame.cli_command`).
- **`./bin/phrame-mcp`** — runs the deny-by-default authenticated Stdio MCP server (`App\Mcp\StdioRunner`).

Both entrypoints load `.env` via `App\EnvLoader::load()`, construct `App\AppConfig::fromEnvironment()`, and boot the complete module stack via `App\AppBootstrap::boot()`.

---

## Global `--json` Flag & Output Envelopes

`PhrameCms\Cli\Bridge\SymfonyCommandAdapter` automatically adds `--json` to **every** registered CLI command:

- Disables interactive prompts and ANSI color decoration.
- Emits a single strictly valid JSON document to `stdout`.
- On unhandled exceptions or non-zero exits without output, `CliApplication::run()` emits a standardized JSON error envelope:

```json
{
  "ok": false,
  "exitCode": 2,
  "error": {
    "code": "validation_error",
    "type": "PhrameCms\\Core\\Exception\\ValidationException",
    "message": "Operation input JSON must decode to a JSON object.",
    "validation": {
      "message": "Operation input JSON must decode to a JSON object.",
      "errors": [],
      "errorsByPath": {}
    }
  }
}
```

- When `AuthorizationException` is thrown, `error.requiredPermissions` is also included.
- Commands that return structured failure responses directly (such as `user:login` and `user:password`) emit `{ "ok": false, "exitCode": <int>, "error": { "code": "<label>", "message": "<detail>" } }`.

---

## `ExitCode` Enum

All CLI commands and `./bin/phrame-mcp` return deterministic exit codes defined in `PhrameCms\Cli\ExitCode`:

| Exit Code | Enum Case | JSON Error `code` | Mapped Exceptions / Conditions |
| :-: | :--- | :--- | :--- |
| `0` | `ExitCode::Ok` | `ok` | Command succeeded. |
| `1` | `ExitCode::RuntimeError` | `runtime_error` | Unhandled runtime/database/unexpected errors. |
| `2` | `ExitCode::ValidationError` | `validation_error` | `ValidationException`, invalid CLI arguments/options (`InvalidOptionException`, `InvalidArgumentException`, `RuntimeException` from Symfony Console), or malformed JSON input. |
| `3` | `ExitCode::AuthorizationDenied` | `authorization_denied` | `AuthorizationException` or missing/invalid MCP stdio token. |
| `4` | `ExitCode::NotFound` | `not_found` | `OperationNotFoundException`, `CommandNotFoundException`, or target user not found. |

---

## Core CLI Commands (`phramecms/cli`)

Registered automatically by `PhrameCms\Cli\CliModule`.

### `modules:list`

List booted PhrameCMS modules in resolved topological dependency order.

```bash
./bin/phrame modules:list [--json]
```

- **Arguments**: None
- **Options**: `--json`
- **JSON output**: Array of `{ "name": string, "dependencies": string[], "class": string }`.

### `op:list`

List all registered `OperationBus` operations with their permissions and safety flags.

```bash
./bin/phrame op:list [--json]
```

- **Arguments**: None
- **Options**: `--json`
- **JSON output**: Array of `{ "name": string, "description": string, "requiredPermissions": string[], "mutatesState": bool, "supportsDryRun": bool }`.

### `op:describe`

Print full metadata, permissions, input JSON Schema, and output JSON Schema for a registered operation.

```bash
./bin/phrame op:describe <operation> [--json]
```

- **Arguments**:
  - `operation` *(required)* — registered operation name (for example, `entity.create`).
- **Options**: `--json`
- **JSON output**: `{ "name", "description", "requiredPermissions", "mutatesState", "supportsDryRun", "inputSchema", "outputSchema" }`.

### `op:run`

Execute any registered `OperationBus` operation directly from the command line.

```bash
./bin/phrame op:run <operation> [options] [--json]
```

- **Arguments**:
  - `operation` *(required)* — registered operation name to execute.
- **Options**:

| Option | Shortcut | Accepts Value | Default | Description |
| :--- | :-: | :-: | :--- | :--- |
| `--input` | `-i` | Yes | — | JSON object string of operation input (mutually exclusive with `--input-file`). |
| `--input-file` | `-f` | Yes | — | Path to a JSON file containing a JSON object of operation input. |
| `--dry-run` | — | No (flag) | `false` | Execute in dry-run preview mode when supported by the operation. |
| `--idempotency-key` | — | Yes | — | Non-empty idempotency key for deduplicating live executions. |
| `--actor-id` | — | Yes | `cli` | Actor identifier recorded in `ExecutionContext` and audit logs. |
| `--actor-type` | — | Yes | `human` | Actor type: `human`, `agent`, or `system` (`PhrameCms\Core\Security\ActorType`). |
| `--scopes` | — | Yes | — | Comma-separated permission scopes granted to the CLI actor (for example, `schema.read,entity.content.article.create` or `*`). |
| `--json` | — | No (flag) | `false` | Output result as strictly valid JSON. |

- **JSON output**:

```json
{
  "ok": true,
  "operation": "entity.schema",
  "dryRun": false,
  "target": null,
  "data": {},
  "diff": null,
  "beforeHash": null,
  "afterHash": null,
  "meta": {}
}
```

- **Example**:

```bash
./bin/phrame op:run entity.schema --scopes=schema.read --json
./bin/phrame op:run config.set \
  --input='{"name":"admin.settings","data":{"brand_name":"Acme CMS"}}' \
  --scopes=config.write \
  --dry-run --json
```

---

## Project CLI Commands (`phramecms/skeleton` — `App\AppModule`)

Registered automatically by `App\AppModule` in skeleton projects.

### `site:install`

Idempotently install database schemas for all registered `phrame.schema_installer` services, create the default `admin` RBAC role (`role_admin` with `['*']`), create/ensure the initial administrator account, and optionally issue an AI Agent Token.

```bash
./bin/phrame site:install [options] [--json]
```

- **Arguments**: None
- **Options**:

| Option | Accepts Value | Default | Description |
| :--- | :-: | :--- | :--- |
| `--admin-user` | Yes | `admin` | Username for the initial administrator account. |
| `--admin-email` | Yes | `admin@example.com` | Email address for the initial administrator account (validated with `FILTER_VALIDATE_EMAIL`). |
| `--admin-password` | Yes | *(random 24-byte base64url)* | Explicit password for the initial admin user (ignored if the user already exists). |
| `--issue-agent-token` | No (flag) | `false` | Issue a scoped AI Agent Token linked (`on_behalf_of`) to the admin user. |
| `--agent-name` | Yes | `local-dev-agent` | Display name for the issued AI Agent Token. |
| `--agent-scopes` | Yes | `*` | Comma-separated permission scopes for the issued AI Agent Token. |
| `--json` | No (flag) | `false` | Output installation summary as JSON. |

- **JSON output**: Includes `ok`, `schemas_installed`, `schema_installers`, `tables_by_installer`, `admin_created`, `admin_user`, plus `generated_password` (when newly generated) and `agent_token` (when `--issue-agent-token` is passed; `plaintext_token` is displayed once).

### `schema:install`

Idempotently install database schemas for all registered `phrame.schema_installer` services (official and custom modules) **without** creating or modifying users, roles, or agent tokens. Ideal for deployments and after enabling a new custom module.

```bash
./bin/phrame schema:install [--json]
```

- **Arguments**: None
- **Options**: `--json`
- **JSON output**: `{ "ok": true, "installers": string[], "tables": string[], "tables_by_installer": Record<string, string[]> }`.

### `user:login`

Generate a short-lived, single-use Admin UI login URL for an active user (equivalent to Drupal's `drush uli`).

```bash
./bin/phrame user:login [user] [options] [--json]
```

- **Arguments**:
  - `user` *(optional, default: `admin`)* — target username, user ID, or email address.
- **Options**:

| Option | Accepts Value | Default | Description |
| :--- | :-: | :--- | :--- |
| `--uri` | Yes | `PHRAME_BASE_URL` or `http://127.0.0.1:<PHRAME_HTTP_PORT>` | Base `http://` or `https://` URL for the generated login link. |
| `--ttl` | Yes | `900` | Single-use token lifetime in seconds (`1`–`86400`). |
| `--redirect` | Yes | `/admin` | Safe post-login relative redirect path starting with `/`. |
| `--json` | No (flag) | `false` | Output `{ ok, user_id, username, url, path, expires_at, ttl_seconds }` as JSON. |

- Returns exit code `4` (`NotFound`) if the user does not exist, or `2` (`ValidationError`) if the user is inactive or any option is invalid.

### `user:password`

Set or reset a user account's password by delegating to the `user.set_password` Core operation through `OperationBus` (hashed with Argon2id, minimum 8 characters, and revoking existing sessions by default).

```bash
./bin/phrame user:password <user> (--password=<pw> | --generate | --password-stdin) [--keep-sessions] [--json]
```

- **Arguments**:
  - `user` *(required)* — target username or user ID.
- **Options**:

| Option | Shortcut | Accepts Value | Default | Description |
| :--- | :-: | :-: | :--- | :--- |
| `--password` | `-p` | Yes | — | Explicit new password (mutually exclusive with `--generate` and `--password-stdin`). |
| `--generate` | — | No (flag) | `false` | Generate a cryptographically random 32-hex-char password and display it once. |
| `--password-stdin` | — | No (flag) | `false` | Read the new password from `stdin` (recommended to avoid shell history exposure). |
| `--keep-sessions` | — | No (flag) | `false` | Preserve existing active Admin UI sessions instead of revoking them. |
| `--json` | — | No (flag) | `false` | Output `{ ok, user_id, username, sessions_revoked, generated_password? }` as JSON. |

- **Example**:

```bash
printf '%s' '<new-strong-password>' | ./bin/phrame user:password admin --password-stdin --json
```

---

## Stdio MCP Entrypoint (`./bin/phrame-mcp`)

`./bin/phrame-mcp` starts `PhrameCms\Mcp\Transport\StdioTransport` behind `App\Mcp\StdioRunner`, which enforces **deny-by-default** AI Agent Token authentication before opening `stdin`/`stdout` for JSON-RPC 2.0 traffic:

```bash
PHRAME_MCP_TOKEN="<agent-token>" ./bin/phrame-mcp
# or explicitly:
./bin/phrame-mcp --token="<agent-token>"
```

- **Token resolution precedence**: `--token=<token>` or `--token <token>` CLI argument (before `--`) takes precedence over `PHRAME_MCP_TOKEN`.
- **Failure behavior**: If no token is supplied or `TokenAuthenticatorInterface::authenticate()` rejects the token, `StdioRunner` writes `[phrame-mcp] ...` strictly to `stderr` (never polluting `stdout`) and exits with code `3` (`ExitCode::AuthorizationDenied`).
- **Security tip**: Prefer `PHRAME_MCP_TOKEN` via environment configuration over `--token` on shared hosts so tokens are not exposed in process listings (`ps`).

---

## Local Docker Wrapper (`./bin/dev`)

`phramecms/skeleton` also includes `./bin/dev`, a lightweight shell wrapper around `docker compose` supporting selectable database overlays:

```bash
./bin/dev [--db-backend=sqlite|postgres|mariadb] [--dry-run|--print-cmd] <docker-compose-subcommand> [args...]
```

- Automatically exports `PHRAME_UID` and `PHRAME_GID` from the host user and passes `--env-file .env` when `.env` exists.
- Common usage: `./bin/dev up -d`, `./bin/dev up --db-backend=postgres -d`, and `./bin/dev exec php ./bin/phrame site:install --issue-agent-token`.
