Run the Gateway
openclaw gateway run options, startup behavior, and revealing the configured token
Starting the Gateway process and reading its configured token. Part of the openclaw gateway reference.
Run the Gateway
openclaw gateway
openclaw gateway run # equivalent, explicit formStartup behavior
- Unexpected startup failures print a redacted
[openclaw] Reason:without requiring debug mode, including in managed service logs. Use--debugorOPENCLAW_DEBUG=1to include stack traces. - Agent requests wait for the current startup model runtime publication, including when a config refresh replaces the initial publication while startup is still preparing authentication.
- Deferred agent database preparation retries publication after an overlapping config or secrets refresh or a transient schema-admission change before admitting sessions, up to four attempts. Opening and migration separately retry classified SQLite lock failures with bounded backoff and fresh deletion and file-identity checks. Exhausted locks retain a degraded refusal with guidance to close competing processes and restart; genuine database failures remain terminal. Publication retries do not repeat opening or migration.
- Worker placement recovery waits through transient SQLite lock contention with up to five attempts and capped backoff (about 37 seconds including SQLite's busy waits). If the lock persists, startup fails with guidance to run
openclaw doctororopenclaw gateway status --deep. Other recovery errors fail immediately. - Refuses to start unless
gateway.mode=localis set in~/.openclaw/openclaw.json. Use--allow-unconfiguredfor ad-hoc/dev runs; it bypasses the guard without writing or repairing config. - Startup automatically applies rule-based, prompt-free legacy-key migrations to eligible invalid single-file configs, including in non-interactive service runs. It writes only after full validation, including plugins, and keeps the previous config in the
.bakring. Configs using$include, Nix-managed configs, and configs written by a newer version are excluded. See Legacy config key migrations. - If automatic migration cannot make the config valid, an interactive terminal can offer to run
openclaw doctor --fixand retry startup once after consent. Non-interactive runs print the command instead. If the repaired config is still invalid, startup remains stopped. - Configuration read failures, including unavailable storage during SQLite inspection, stop startup with exit code
1so service supervision can retry. They do not trigger config repair. Invalid configuration and required offline migrations retain exit code78, which prevents systemd restart loops; resolve the reported problem before restarting. - Startup hardens user-owned shared-state database files to mode
0600before opening SQLite. A database that remains read-only, full, or I/O-failing is reported as a storage failure with its path and recovery guidance. Fix ownership and permissions for the reported path, remount a read-only volume writable, or free disk space as directed. These failures keep exit code1and do not trigger another-Gateway contention waits or port diagnostics. - Before reading its shared-state snapshot, startup waits up to five minutes for a temporary schema owner in another OpenClaw process to finish. Explicit offline maintenance still blocks access, and exhausted contention remains a read failure with exit code
1. - Startup does not load plugin Doctor modules just to collect advisory repair rules for valid config. Invalid config still includes plugin repair guidance;
openclaw doctorinspects repair rules even when the config is valid. - Config recovery, shared-state readiness, and pending plugin migration reads share the current admission snapshot. Registry refresh rechecks admission while holding both migration and plugin lifecycle leases, then verifies the persisted replacement. Repairs still compare current state before writing. This does not change update migrations or stored data.
openclaw onboard --mode localandopenclaw setupwritegateway.mode=local. If the config file exists butgateway.modeis missing, that is treated as damaged/clobbered config and the Gateway refuses to guesslocalfor you — re-run onboarding, set the key manually, or pass--allow-unconfigured.- Binding beyond loopback without auth is blocked.
--bindvalueslan,tailnet, andcustomresolve over IPv4-only paths; IPv6-only bring-your-own-host setups need an IPv4 sidecar or proxy in front of the Gateway.SIGUSR2triggers an in-process restart when authorized.commands.restart(default: enabled) gates externally-sentSIGUSR2; set it tofalseto block manual OS-signal restarts. The agent-facinggatewaytool exposes owner-requestedrestart,update.run, andupdate.cleanup; cleanup keeps the Gateway serving. External-chat restarts and updates also honorcommands.restart. These runtime-owned actions preserve owner/operator authorization and explicit tool restrictions. Other delegated setup changes follow effective permissions. See Delegated setup and repair.SIGUSR1is reserved for Node's inspector, so attaching a debugger does not restart the Gateway. Preferopenclaw gateway restartfor restarts; update manual restart scripts to sendSIGUSR2.SIGINT/SIGTERMstop the process but do not restore custom terminal state — if you wrap the CLI in a TUI or raw-mode input, restore the terminal yourself before exit.- A foreground Gateway does not follow the lifetime of the process that started it. OpenClaw's own launchers, such as Node runtime recovery, forward stop signals and stop their Gateway when they exit. A shell or wrapper script that does not forward signals leaves the Gateway serving after the wrapper is killed. Signal the Gateway process itself (process title
openclaw-gateway), or forward signals from the wrapper (for exampleexec openclaw gateway run).
Options
WebSocket port (default from config/env; usually 18789).
Bind mode: loopback (default), lan, tailnet, auto, custom.
Shared token for connect.params.auth.token. Defaults to OPENCLAW_GATEWAY_TOKEN when set.
Auth mode: none, token, password, trusted-proxy.
Password for --auth password.
Read the Gateway password from a file.
Tailscale exposure: off, serve, funnel.
Start without enforcing gateway.mode=local. Ad-hoc/dev bootstrap only; does not persist or repair config.
Create a dev config + workspace if missing (skips BOOTSTRAP.md).
Allow the Gateway to auto-configure channels from ambient environment variables for this process, including config reloads. By default, foreground, dev, and service Gateways require explicit channels.<id> configuration, such as channels.discord.enabled=true. Configured channels can still read credentials from environment variables. For managed services, add the channel config block; this flag is not persisted by service installation.
Deprecated alias for --ambient-channels.
Reset dev config, credentials, sessions, and workspace. Requires --dev.
Kill any existing listener on the target port before starting. In a non-interactive shell, this refuses to kill a verified Gateway listener; use --dev or an isolated --profile with a free port instead.
Verbose logging to stdout/stderr.
Only show CLI backend logs in the console (also enables stdout/stderr).
WebSocket log style: auto, full, compact.
Alias for --ws-log compact.
Log raw model stream events to JSONL.
Raw stream JSONL path.
--claude-cli-logs is a deprecated alias for --cli-backend-logs.
For --bind custom, set gateway.customBindHost to an IPv4 address. Any address other than 127.0.0.1 or 0.0.0.0 also requires 127.0.0.1 on the same port for same-host clients; startup fails if either listener cannot bind. Wildcard 0.0.0.0 does not add a separate required alias. IPv6-only bring-your-own-host setups need an IPv4 sidecar or proxy in front of the Gateway.
Reveal the configured token
Run this on the Gateway host when a client needs the configured shared token:
openclaw gateway auth-token --showThe command resolves gateway.auth.token, OPENCLAW_GATEWAY_TOKEN, and configured SecretRefs, then prints only the token. It requires an interactive terminal and refuses redirected or piped output so the credential does not silently enter command logs. Treat the terminal output as a secret.
If no persistent token is configured, run openclaw doctor --generate-gateway-token, restart the Gateway, and then rerun the command. On Windows PowerShell, a Restricted execution policy blocks npm's openclaw.ps1 shim before Doctor starts; use npm's openclaw.cmd instead of changing the execution policy. Generic openclaw config get output remains redacted, including --json.
Wait for a previous container
A replacement Gateway waits for the previous Gateway to stop or for its heartbeat to go stale. Stop the previous container through its service manager if it is still running; do not remove the state lock. See Container restarts and replacements.