﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>> ## Documentation Index
> Fetch the complete documentation index at: https://openworkflow.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> ### When to use OpenWorkflow
>
> Use OpenWorkflow in TypeScript or JavaScript apps for:
>
> - Background jobs that need retries and must resume after a crash or deploy.
> - Multi-step integrations and data pipelines that need to save progress between operations.
> - AI workflows with multiple model or tool calls that need durable checkpoints.
> - Workflows that wait for a human approval, a webhook, or a timer before continuing.
>
> OpenWorkflow runs on Node.js 22.22+ or Bun, with PostgreSQL or SQLite storing workflow state. Your app enqueues runs, and a worker executes them.
>
> ### How to use OpenWorkflow
>
> Read and follow https://openworkflow.dev/skills/setup.md to set up OpenWorkflow.
>
> Define workflows with `defineWorkflow`, wrap operations in `step.run`, and enqueue runs with `ow.runWorkflow(workflow.spec, input)`. Start a worker with `npx @openworkflow/cli worker start` to execute them. See [Workflows](https://openworkflow.dev/docs/workflows.md), [Steps](https://openworkflow.dev/docs/steps.md), and [Signals](https://openworkflow.dev/docs/signals.md) for the APIs.

# CLI Reference

> Command-line interface for OpenWorkflow, with commands to set up a project, start workers, and open the dashboard

The OpenWorkflow CLI
[(`@openworkflow/cli`)](https://www.npmjs.com/package/@openworkflow/cli) is the
primary way to set up your project, run workers, and launch the dashboard. The
CLI reads your `openworkflow.config.ts` by default, or you can override the path
with `--config`.

## Installation

```bash npm theme={null}
npm install -D @openworkflow/cli
```

```bash pnpm theme={null}
pnpm add -D @openworkflow/cli
```

```bash bun theme={null}
bun add -D @openworkflow/cli
```

## Commands

### `init`

Initialize OpenWorkflow in a project with an existing `package.json`:

```bash npm theme={null}
npx @openworkflow/cli init
```

```bash pnpm theme={null}
pnpx @openworkflow/cli init
```

```bash bun theme={null}
bunx @openworkflow/cli init
```

By default, `init` is interactive and prompts for a backend, installs
dependencies, and creates a config, client, example workflow, and runner. It
also adds a `worker` script and updates `.gitignore` or `.env` for the selected
backend.

Options:

* `--backend <backend>` - Select `sqlite`, `postgres`, or `both`. With `both`,
  PostgreSQL is used when `NODE_ENV=production`; otherwise SQLite is used.
* `-y, --yes` - Skip prompts. Requires `--backend` and rejects existing configs.
* `--skip-install` - Create files without installing dependencies or changing
  dependency declarations. Prints the installation commands to run later.

For unattended setup without installing dependencies:

```bash theme={null}
npx --yes @openworkflow/cli init --backend postgres --yes --skip-install
```

### `worker start`

Start a worker to process workflows:

```bash npm theme={null}
npx @openworkflow/cli worker start
```

```bash pnpm theme={null}
pnpx @openworkflow/cli worker start
```

```bash bun theme={null}
bunx @openworkflow/cli worker start
```

Options:

* `--concurrency <n>` - Number of concurrent workflow executions (overrides
  config)

```bash npm theme={null}
# Run with 4 concurrent workflows
npx @openworkflow/cli worker start --concurrency 4
```

```bash pnpm theme={null}
# Run with 4 concurrent workflows
pnpx @openworkflow/cli worker start --concurrency 4
```

```bash bun theme={null}
# Run with 4 concurrent workflows
bunx @openworkflow/cli worker start --concurrency 4
```

The worker:

1. Loads your config file
2. Discovers workflows in the configured directories
3. Registers all workflows
4. Starts polling for work
5. Handles graceful shutdown on SIGINT/SIGTERM

### `dashboard`

Start the web dashboard:

```bash npm theme={null}
npx @openworkflow/cli dashboard
```

```bash pnpm theme={null}
pnpx @openworkflow/cli dashboard
```

```bash bun theme={null}
bunx @openworkflow/cli dashboard
```

The dashboard starts on `http://localhost:3000` by default.

To use a custom port:

```bash npm theme={null}
npx @openworkflow/cli dashboard --port 4000
```

```bash pnpm theme={null}
pnpx @openworkflow/cli dashboard --port 4000
```

```bash bun theme={null}
bunx @openworkflow/cli dashboard --port 4000
```

See [Dashboard](https://openworkflow.dev/docs/dashboard.md) for details.

### `doctor`

Check your config, backend connection, and workflows for problems.

```bash npm theme={null}
npx @openworkflow/cli doctor
```

```bash pnpm theme={null}
pnpx @openworkflow/cli doctor
```

```bash bun theme={null}
bunx @openworkflow/cli doctor
```

### `--version`

Show the CLI version:

```bash npm theme={null}
npx @openworkflow/cli --version
```

```bash pnpm theme={null}
pnpx @openworkflow/cli --version
```

```bash bun theme={null}
bunx @openworkflow/cli --version
```

### `--help`

Show help for any command:

```bash npm theme={null}
npx @openworkflow/cli --help
npx @openworkflow/cli worker --help
npx @openworkflow/cli worker start --help
```

```bash pnpm theme={null}
pnpx @openworkflow/cli --help
pnpx @openworkflow/cli worker --help
pnpx @openworkflow/cli worker start --help
```

```bash bun theme={null}
bunx @openworkflow/cli --help
bunx @openworkflow/cli worker --help
bunx @openworkflow/cli worker start --help
```

## Environment Variables

The CLI loads `.env` from the current directory before reading the config. You
can pass `--env-file <path>` to load a different .env file.

```bash theme={null}
# .env
OPENWORKFLOW_POSTGRES_URL=postgresql://user:pass@localhost:5432/openworkflow
```

## Telemetry

The CLI sends command names, backend types, CLI/Node.js versions, OS,
architecture, and a random installation ID to PostHog by default. It does not
send project contents, paths, or error messages.

Disable telemetry with `--no-telemetry` or `DO_NOT_TRACK=1` in your shell.
Any nonempty `CI` or `OPENWORKFLOW_TELEMETRY_DISABLED` also disables it.

## Exit Codes

| Code | Meaning |
| - | - |
| 0 | Success |
| 1 | Error (config not found, connection failed, etc.) |

## Graceful Shutdown

When running `worker start`, the CLI handles shutdown signals:

* **SIGINT** (Ctrl+C) - Graceful shutdown
* **SIGTERM** - Graceful shutdown

On shutdown, the worker:

1. Stops accepting new work
2. Waits for active workflows to complete
3. Closes the backend connection


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.