docs/cli/gateway.md
The Gateway is OpenClaw's WebSocket server (channels, nodes, sessions, hooks). Subcommands in this page live under openclaw gateway ….
Run a local Gateway process:
openclaw gateway
Foreground alias:
openclaw gateway run
openclaw gateway restart
openclaw gateway restart --safe
openclaw gateway restart --force
openclaw gateway restart --safe asks the running Gateway to preflight active OpenClaw work before restarting. If queued operations, reply delivery, embedded runs, or task runs are active, the Gateway reports the blockers, coalesces duplicate safe restart requests, and restarts once the active work drains. Plain restart keeps the existing service-manager behavior for compatibility. Use --force only when you explicitly want the immediate override path.
OPENCLAW_GATEWAY_STARTUP_TRACE=1 to log phase timings during Gateway startup, including per-phase eventLoopMax delay and plugin lookup-table timings for installed-index, manifest registry, startup planning, and owner-map work.OPENCLAW_DIAGNOSTICS=timeline with OPENCLAW_DIAGNOSTICS_TIMELINE_PATH=<path> to write a best-effort JSONL startup diagnostics timeline for external QA harnesses. You can also enable the flag with diagnostics.flags: ["timeline"] in config; the path is still env-provided. Add OPENCLAW_DIAGNOSTICS_EVENT_LOOP=1 to include event-loop samples.pnpm test:startup:gateway -- --runs 5 --warmup 1 to benchmark Gateway startup. The benchmark records first process output, /healthz, /readyz, startup trace timings, event-loop delay, and plugin lookup-table timing details.All query commands use WebSocket RPC.
<Tabs> <Tab title="Output modes"> - Default: human-readable (colored in TTY). - `--json`: machine-readable JSON (no styling/spinner). - `--no-color` (or `NO_COLOR=1`): disable ANSI while keeping human layout. </Tab> <Tab title="Shared options"> - `--url <url>`: Gateway WebSocket URL. - `--token <token>`: Gateway token. - `--password <password>`: Gateway password. - `--timeout <ms>`: timeout/budget (varies per command). - `--expect-final`: wait for a "final" response (agent calls). </Tab> </Tabs> <Note> When you set `--url`, the CLI does not fall back to config or environment credentials. Pass `--token` or `--password` explicitly. Missing explicit credentials is an error. </Note>gateway healthopenclaw gateway health --url ws://127.0.0.1:18789
The HTTP /healthz endpoint is a liveness probe: it returns once the server can answer HTTP. The HTTP /readyz endpoint is stricter and stays red while startup plugin sidecars, channels, or configured hooks are still settling. Local or authenticated detailed readiness responses include an eventLoop diagnostic block with event-loop delay, event-loop utilization, CPU core ratio, and a degraded flag.
gateway usage-costFetch usage-cost summaries from session logs.
openclaw gateway usage-cost
openclaw gateway usage-cost --days 7
openclaw gateway usage-cost --json
gateway stabilityFetch the recent diagnostic stability recorder from a running Gateway.
openclaw gateway stability
openclaw gateway stability --type payload.large
openclaw gateway stability --bundle latest
openclaw gateway stability --bundle latest --export
openclaw gateway stability --json
gateway diagnostics exportWrite a local diagnostics zip that is designed to attach to bug reports. For the privacy model and bundle contents, see Diagnostics Export.
openclaw gateway diagnostics export
openclaw gateway diagnostics export --output openclaw-diagnostics.zip
openclaw gateway diagnostics export --json
The export contains a manifest, a Markdown summary, config shape, sanitized config details, sanitized log summaries, sanitized Gateway status/health snapshots, and the newest stability bundle when one exists.
It is meant to be shared. It keeps operational details that help debugging, such as safe OpenClaw log fields, subsystem names, status codes, durations, configured modes, ports, plugin ids, provider ids, non-secret feature settings, and redacted operational log messages. It omits or redacts chat text, webhook bodies, tool outputs, credentials, cookies, account/message identifiers, prompt/instruction text, hostnames, and secret values. When a LogTape-style message looks like user/chat/tool payload text, the export keeps only that a message was omitted plus its byte count.
gateway statusgateway status shows the Gateway service (launchd/systemd/schtasks) plus an optional probe of connectivity/auth capability.
openclaw gateway status
openclaw gateway status --json
openclaw gateway status --require-rpc
gateway probegateway probe is the "debug everything" command. It always probes:
If you pass --url, that explicit target is added ahead of both. Human output labels the targets as:
URL (explicit)Remote (configured) or Remote (configured, inactive)Local loopbackopenclaw gateway probe
openclaw gateway probe --json
- `ok`: at least one target is reachable.
- `degraded`: at least one target accepted a connection but did not complete full detail RPC diagnostics.
- `capability`: best capability seen across reachable targets (`read_only`, `write_capable`, `admin_capable`, `pairing_pending`, `connected_no_operator_scope`, or `unknown`).
- `primaryTargetId`: best target to treat as the active winner in this order: explicit URL, SSH tunnel, configured remote, then local loopback.
- `warnings[]`: best-effort warning records with `code`, `message`, and optional `targetIds`.
- `network`: local loopback/tailnet URL hints derived from current config and host networking.
- `discovery.timeoutMs` and `discovery.count`: the actual discovery budget/result count used for this probe pass.
Per target (`targets[].connect`):
- `ok`: reachability after connect + degraded classification.
- `rpcOk`: full detail RPC success.
- `scopeLimited`: detail RPC failed due to missing operator scope.
Per target (`targets[].auth`):
- `role`: auth role reported in `hello-ok` when available.
- `scopes`: granted scopes reported in `hello-ok` when available.
- `capability`: the surfaced auth capability classification for that target.
The macOS app "Remote over SSH" mode uses a local port-forward so the remote gateway (which may be bound to loopback only) becomes reachable at ws://127.0.0.1:<port>.
CLI equivalent:
openclaw gateway probe --ssh user@gateway-host
Config (optional, used as defaults):
gateway.remote.sshTargetgateway.remote.sshIdentitygateway call <method>Low-level RPC helper.
openclaw gateway call status
openclaw gateway call logs.tail --params '{"sinceMs": 60000}'
openclaw gateway install
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
openclaw gateway uninstall
Use --wrapper when the managed service must start through another executable, for example a
secrets manager shim or a run-as helper. The wrapper receives the normal Gateway args and is
responsible for eventually exec'ing openclaw or Node with those args.
cat > ~/.local/bin/openclaw-doppler <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
exec doppler run --project my-project --config production -- openclaw "$@"
EOF
chmod +x ~/.local/bin/openclaw-doppler
openclaw gateway install --wrapper ~/.local/bin/openclaw-doppler --force
openclaw gateway restart
You can also set the wrapper through the environment. gateway install validates that the path is
an executable file, writes the wrapper into service ProgramArguments, and persists
OPENCLAW_WRAPPER in the service environment for later forced reinstalls, updates, and doctor
repairs.
OPENCLAW_WRAPPER="$HOME/.local/bin/openclaw-doppler" openclaw gateway install --force
openclaw doctor
To remove a persisted wrapper, clear OPENCLAW_WRAPPER while reinstalling:
OPENCLAW_WRAPPER= openclaw gateway install --force
openclaw gateway restart
gateway discover scans for Gateway beacons (_openclaw-gw._tcp).
local.openclaw.internal.) and set up split DNS + a DNS server; see Bonjour.Only gateways with Bonjour discovery enabled (default) advertise the beacon.
Wide-Area discovery records include (TXT):
role (gateway role hint)transport (transport hint, e.g. gateway)gatewayPort (WebSocket port, usually 18789)sshPort (optional; clients default SSH targets to 22 when it is absent)tailnetDns (MagicDNS hostname, when available)gatewayTls / gatewayTlsSha256 (TLS enabled + cert fingerprint)cliPath (remote-install hint written to the wide-area zone)gateway discoveropenclaw gateway discover
Examples:
openclaw gateway discover --timeout 4000
openclaw gateway discover --json | jq '.beacons[].wsUrl'