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

# CLI Overview

> Install and use the Refrain CLI.

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm install -g @refrainai/cli
  ```

  ```bash pnpm theme={null}
  pnpm add -g @refrainai/cli
  ```

  ```bash npx (no install) theme={null}
  npx @refrainai/cli <command>
  ```
</CodeGroup>

## Commands

| Command                           | Description                                                    |
| --------------------------------- | -------------------------------------------------------------- |
| [`generate`](/cli/generate)       | Generate a runbook by AI-driven browser exploration            |
| [`execute`](/cli/execute)         | Execute a runbook                                              |
| [`fix-runbook`](/cli/fix-runbook) | Apply repair suggestions from an execution report to a runbook |
| [`compose`](/cli/compose)         | Merge multiple runbooks into a single branching runbook        |
| [`runner`](/cli/runner)           | Start a remote browser runner                                  |
| [`serve`](/cli/serve)             | Start the API server for remote execution and Web Console      |

## Global options

| Option            | Description         |
| ----------------- | ------------------- |
| `--version`, `-v` | Show version number |
| `--help`, `-h`    | Show help           |

## Basic usage

### Generate a runbook

```bash theme={null}
npx @refrainai/cli generate -- \
  --url "https://app.example.com/login" \
  --goal "Log in and export dashboard data" \
  --output ./login-export.yaml \
  --context ./context.md \
  --secrets ./secrets.json \
  --headless false \
  --model "claude-sonnet-4-6" \
  --model-provider anthropic
```

<Tip>
  Set default model and provider via environment variables instead of passing them on every command. See [default model configuration](/guides/ai-setup#default-model).
</Tip>

### Execute a runbook

```bash theme={null}
npx @refrainai/cli execute -- \
  --runbook ./login-export.yaml \
  --context ./context.md \
  --secrets ./secrets.json \
  --headless false \
  --model "claude-sonnet-4-6" \
  --model-provider anthropic
```

### Self-heal mode

Validate a runbook with aggressive retry and generate repair suggestions:

```bash theme={null}
npx @refrainai/cli execute -- \
  --runbook ./login-export.yaml \
  --self-heal
```

### Apply fixes

Apply AI-generated repair suggestions to update a broken runbook:

```bash theme={null}
npx @refrainai/cli fix-runbook -- \
  --runbook ./login-export.yaml \
  --report ./report.md
```

## AI provider configuration

By default, Refrain uses **Anthropic Claude**. Set the API key:

```bash theme={null}
export ANTHROPIC_API_KEY="sk-ant-..."
```

For other providers (OpenAI, Google, Azure, Bedrock, Vertex), see the [AI provider setup guide](/guides/ai-setup) for required environment variables and flags.

## API key (Plan tiers)

Unlock advanced features by setting an API key:

```bash theme={null}
export REFRAIN_API_KEY="rfn-eyJ..."
```

Or pass it per-command:

```bash theme={null}
npx @refrainai/cli execute -- --runbook ./flow.yaml --api-key "rfn-eyJ..."
```

See [Plan tiers](/concepts/plan-tiers) for feature details.
