> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lexq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Command Reference

> Complete reference for the LexQ CLI.

## Command Structure

```bash theme={null}
lexq <group> <action> [options]
```

## At a Glance

```text theme={null}
lexq auth                  login | logout | whoami
lexq status                API health check
lexq serve                 Run as MCP stdio server (--mcp)
lexq groups                list | get | create | update | delete
lexq groups ab-test        start | stop | adjust
lexq versions              list | get | create | update | delete | clone
lexq rules                 list | get | create | update | delete | reorder | toggle
lexq facts                 list | create | update | delete | action-metadata | unregistered
lexq deploy                publish | live | schedule | unschedule | schedules | rollback | undeploy | history | detail | overview | deployable | diff
lexq analytics             dry-run | dry-run-compare | requirements
lexq analytics simulation  start | status | list | cancel | export
lexq analytics dataset     upload | template
lexq profile               per-rule latency (--rule for detail)
lexq history               list | get | stats
lexq replay                decision | start | list | get | cancel
lexq provenance            get | reveal-audits
lexq integrations          list | get | save | delete | config-spec
lexq logs                  list | get | action | bulk-action
lexq webhook-subscriptions list | get | save | delete | test
```

Each section below covers the commands in detail.

## Auth

| Command            | Description                                               |
| ------------------ | --------------------------------------------------------- |
| `lexq auth login`  | Store API key interactively                               |
| `lexq auth logout` | Remove stored credentials                                 |
| `lexq auth whoami` | Show current authentication info (tenant, role, key mask) |

## Status

| Command       | Description                                |
| ------------- | ------------------------------------------ |
| `lexq status` | Check API connectivity and measure latency |

<Info>
  `lexq status` verifies that the API is reachable and your key is valid by calling the `whoami` endpoint and reporting latency. `lexq auth whoami` returns the full authentication details. Use `status` for quick health checks; use `whoami` for identity verification.
</Info>

## Groups

| Command                                                      | Description            |
| ------------------------------------------------------------ | ---------------------- |
| `lexq groups list`                                           | List all policy groups |
| `lexq groups get --id <gid>`                                 | Get group detail       |
| `lexq groups create --json '{...}'`                          | Create a new group     |
| `lexq groups update --id <gid> --json '{...}'`               | Update group           |
| `lexq groups delete --id <gid>`                              | Delete group           |
| `lexq groups ab-test start --group-id <gid> --json '{...}'`  | Start A/B test         |
| `lexq groups ab-test stop --group-id <gid>`                  | Stop A/B test          |
| `lexq groups ab-test adjust --group-id <gid> --json '{...}'` | Adjust traffic rate    |

## Versions

| Command                                                           | Description        |
| ----------------------------------------------------------------- | ------------------ |
| `lexq versions list --group-id <gid>`                             | List versions      |
| `lexq versions get --group-id <gid> --id <vid>`                   | Get version detail |
| `lexq versions create --group-id <gid> --json '{...}'`            | Create DRAFT       |
| `lexq versions update --group-id <gid> --id <vid> --json '{...}'` | Update version     |
| `lexq versions delete --group-id <gid> --id <vid>`                | Delete version     |
| `lexq versions clone --group-id <gid> --id <vid>`                 | Clone to new DRAFT |

## Rules

| Command                                                                           | Description        |
| --------------------------------------------------------------------------------- | ------------------ |
| `lexq rules list --group-id <gid> --version-id <vid>`                             | List rules         |
| `lexq rules get --group-id <gid> --version-id <vid> --id <rid>`                   | Get rule detail    |
| `lexq rules create --group-id <gid> --version-id <vid> --json '{...}'`            | Create rule        |
| `lexq rules update --group-id <gid> --version-id <vid> --id <rid> --json '{...}'` | Update rule        |
| `lexq rules delete --group-id <gid> --version-id <vid> --id <rid>`                | Delete rule        |
| `lexq rules reorder --group-id <gid> --version-id <vid> --rule-ids "a,b,c"`       | Set priority order |
| `lexq rules toggle --group-id <gid> --version-id <vid> --id <rid> --enabled true` | Enable/disable     |

Example:

```bash theme={null}
lexq rules create --group-id <gid> --version-id <vid> --json '{
  "name": "VIP 10% Discount",
  "priority": 0,
  "condition": {
    "type": "GROUP", "operator": "AND",
    "children": [
      { "type": "SINGLE", "field": "customer_tier", "operator": "EQUALS", "value": "VIP", "valueType": "STRING" },
      { "type": "SINGLE", "field": "payment_amount", "operator": "GREATER_THAN_OR_EQUAL", "value": 100000, "valueType": "NUMBER" }
    ]
  },
  "actions": [{ "type": "MUTATE_FACT", "parameters": { "refVar": "payment_amount", "operator": "SUB", "method": "PERCENTAGE", "rate": 10 } }]
}'
```

## Facts

| Command                                                       | Description                                                                                                                           |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `lexq facts list`                                             | List all fact definitions                                                                                                             |
| `lexq facts create --key <key> --name <n> --type <type>`      | Create fact                                                                                                                           |
| `lexq facts update --id <fid> --name <n>`                     | Update fact                                                                                                                           |
| `lexq facts delete --id <fid>`                                | Delete fact                                                                                                                           |
| `lexq facts action-metadata`                                  | Show runtime fact metadata per action type (which facts are required/produced by `MUTATE_FACT`, `INCREMENT_FACT`, `EMIT_EVENT`, etc.) |
| `lexq facts unregistered --group-id <gid> --version-id <vid>` | List facts a version's rules reference but the schema does not define (non-blocking)                                                  |

<Info>
  `lexq facts action-metadata` is read-only and cached per session — safe to call anytime when designing rules.
</Info>

## Deploy

| Command                                                                 | Description                                           |
| ----------------------------------------------------------------------- | ----------------------------------------------------- |
| `lexq deploy publish --group-id <gid> --version-id <vid> --memo "..."`  | DRAFT → ACTIVE                                        |
| `lexq deploy live --group-id <gid> --version-id <vid> --memo "..."`     | Deploy to production                                  |
| `lexq deploy rollback --group-id <gid> --memo "..."`                    | Revert to previous version                            |
| `lexq deploy undeploy --group-id <gid> --memo "..."`                    | Remove live version                                   |
| `lexq deploy history [--group-id <gid>]`                                | List deployment history                               |
| `lexq deploy detail --deployment-id <id>`                               | Get deployment detail                                 |
| `lexq deploy overview`                                                  | All groups' deployment status                         |
| `lexq deploy deployable --group-id <gid>`                               | List ACTIVE versions ready for deployment             |
| `lexq deploy diff --base-version-id <vid> --target-version-id <vid>`    | Compare rule snapshots between two versions           |
| `lexq deploy schedule --group-id <gid> --version-id <vid> --memo "..."` | Schedule a future-dated ACTIVE version to auto-deploy |
| `lexq deploy unschedule --group-id <gid>`                               | Cancel the pending scheduled deployment               |
| `lexq deploy schedules [--format table]`                                | List scheduled deployments (all statuses)             |

## Analytics — Dry Run

| Command                                                           | Description          |
| ----------------------------------------------------------------- | -------------------- |
| `lexq analytics dry-run --version-id <vid> --json '{...}'`        | Execute Dry Run      |
| `lexq analytics dry-run-compare --json '{...}'`                   | Compare two versions |
| `lexq analytics requirements --group-id <gid> --version-id <vid>` | Check required facts |

## Analytics — Impact Simulation

| Command                                                            | Description      |
| ------------------------------------------------------------------ | ---------------- |
| `lexq analytics simulation start --json '{...}'`                   | Start simulation |
| `lexq analytics simulation status --id <simId>`                    | Poll for results |
| `lexq analytics simulation list [--status <s>]`                    | List simulations |
| `lexq analytics simulation cancel --id <simId>`                    | Cancel           |
| `lexq analytics simulation export --id <simId> --format json\|csv` | Export results   |

## Analytics — Dataset

| Command                                                               | Description             |
| --------------------------------------------------------------------- | ----------------------- |
| `lexq analytics dataset upload --file <path>`                         | Upload CSV/JSON dataset |
| `lexq analytics dataset template --group-id <gid> --version-id <vid>` | Download template       |

## Profile

| Command                                  | Description                                                                 |
| ---------------------------------------- | --------------------------------------------------------------------------- |
| `lexq profile <groupId>`                 | Group latency overview — per-rule percentiles with relative slow-rule flags |
| `lexq profile <groupId> --rule <ruleId>` | Single-rule detail: summary by phase × cache state + 60s window series      |

Filters: `--version <vid>` (default: live), `--from` / `--to` (ISO-8601 instants), `--cache HIT|MISS`.
Percentiles are withheld (`–`) below 100 samples; judgment is relative only — see the
[Performance Profiling guide](/guides/performance-profiling).

## History

| Command                                 | Description            |
| --------------------------------------- | ---------------------- |
| `lexq history list [--group-id <gid>]`  | List execution history |
| `lexq history get --id <eid>`           | Get execution detail   |
| `lexq history stats [--group-id <gid>]` | Aggregate statistics   |

## Replay

| Command                                                          | Description                                                          |
| ---------------------------------------------------------------- | -------------------------------------------------------------------- |
| `lexq replay decision --trace-id <tid> --version-id <vid>`       | Replay one decision against a candidate version (free)               |
| `lexq replay start --version-id <vid> --from <date> --to <date>` | Submit a window replay job (billed; `--max-records` caps the sample) |
| `lexq replay list`                                               | List replay jobs                                                     |
| `lexq replay get --id <jobId>`                                   | Poll job status, summary, and changed samples                        |
| `lexq replay cancel --id <jobId>`                                | Cancel a pending or running job                                      |

## Provenance

| Command                                   | Description                                      |
| ----------------------------------------- | ------------------------------------------------ |
| `lexq provenance get --trace-id <tid>`    | Get a decision's lineage (PII facts masked)      |
| `lexq provenance reveal-audits [filters]` | List the PII reveal audit ledger (metadata only) |

<Info>
  There is no `reveal` command — revealing PII plaintext is console-only by design, and every console reveal writes an audit row first.
</Info>

## Integrations

| Command                                       | Description            |
| --------------------------------------------- | ---------------------- |
| `lexq integrations list`                      | List all integrations  |
| `lexq integrations get --id <iid>`            | Get integration detail |
| `lexq integrations save --json '{...}'`       | Create or update       |
| `lexq integrations delete --id <iid>`         | Delete                 |
| `lexq integrations config-spec --type <type>` | Show required config   |

## Logs

| Command                                    | Description          |
| ------------------------------------------ | -------------------- |
| `lexq logs list [filters]`                 | List failure logs    |
| `lexq logs get --id <lid>`                 | Get detail           |
| `lexq logs action --id <lid> --action <a>` | Retry, skip, resolve |
| `lexq logs bulk-action --json '{...}'`     | Bulk action          |

## Webhook Subscriptions

Platform event webhooks receive deployment lifecycle notifications (`VERSION_PUBLISHED`, `DEPLOYED`, `ROLLED_BACK`, `UNDEPLOYED`, `DEPLOY_SCHEDULED`, `DEPLOY_SCHEDULE_CANCELED`). Separate from rule-level `EMIT_WEBHOOK` actions.

| Command                                          | Description                              |
| ------------------------------------------------ | ---------------------------------------- |
| `lexq webhook-subscriptions list`                | List all webhook subscriptions           |
| `lexq webhook-subscriptions get --id <wid>`      | Get subscription detail                  |
| `lexq webhook-subscriptions save --json '{...}'` | Create or update (omit `id` to create)   |
| `lexq webhook-subscriptions delete --id <wid>`   | Delete subscription                      |
| `lexq webhook-subscriptions test --id <wid>`     | Send a test event to verify connectivity |

Example:

```bash theme={null}
lexq webhook-subscriptions save --json '{
  "name": "slack-deploy-alerts",
  "webhookUrl": "https://hooks.slack.com/services/...",
  "subscribedEvents": ["DEPLOYED", "ROLLED_BACK"],
  "payloadFormat": "SLACK",
  "secret": "your-hmac-secret",
  "isActive": true
}'
```

## Serve

| Command            | Description            |
| ------------------ | ---------------------- |
| `lexq serve --mcp` | Start stdio MCP server |

→ [MCP Server Setup Guide](/cli/mcp-server)

## Standard Workflow

```bash theme={null}
# 1. Create group       → lexq groups create --json '{...}'
# 2. Create version      → lexq versions create --group-id <gid> --json '{...}'
# 3. Register facts      → lexq facts create --key ... --name ... --type ...
# 4. Add rules           → lexq rules create --group-id <gid> --version-id <vid> --json '{...}'
# 5. Validate (dry run)  → lexq analytics dry-run --version-id <vid> --debug --mock --json '{...}'
# 6. Publish             → lexq deploy publish --group-id <gid> --version-id <vid> --memo "..."
# 7. Deploy              → lexq deploy live --group-id <gid> --version-id <vid> --memo "..."
```

<Warning>
  Cannot create rules without a DRAFT version. Cannot publish without rules. Cannot deploy a DRAFT. Always dry-run before publishing.
</Warning>
