--- summary: "Supervise the OpenClaw Gateway as a child process from Electron or another host app" read_when: - Embedding OpenClaw in a desktop or server application - Supervising the Gateway as a child process - Handling Gateway readiness, restart, shutdown, or invalid config without scraping logs title: "Embedding OpenClaw" --- An embedding host should supervise the installed `openclaw` executable, use the Gateway WebSocket protocol as its control plane, and treat the child process as a replaceable runtime. This keeps process ownership, readiness, failure recovery, and upgrades explicit without depending on OpenClaw's private state layout. For client authentication and reconnect state, read [Building a Gateway client](https://docs.openclaw.ai/gateway/clients). ## Start the child with an embedding preset Use a real `node_modules` installation and spawn the package executable. A useful baseline for a host that owns discovery, restart, and channel lifecycle is: ```ts import { spawn } from "node:child_process"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; // Supply an absolute path to a real Node runtime managed by the host application. declare const hostNodeExecutable: string; const packageEntry = fileURLToPath(import.meta.resolve("openclaw")); const openclawEntry = resolve(dirname(packageEntry), "..", "openclaw.mjs"); const gateway = spawn(hostNodeExecutable, [openclawEntry, "gateway", "--allow-unconfigured"], { env: { ...process.env, OPENCLAW_DISABLE_BONJOUR: "1", OPENCLAW_EXEC_SHELL_SNAPSHOT: "0", OPENCLAW_NO_RESPAWN: "1", OPENCLAW_SKIP_CHANNELS: "1", }, stdio: ["ignore", "inherit", "inherit"], }); ``` Resolve OpenClaw through the installed package as shown; do not assume that a project-local `openclaw` binary is on the host process's `PATH`. The example inherits output so the child cannot block on full stdout or stderr pipes. If the host captures those streams instead, attach consumers immediately after spawning. | Setting | Embedding effect | | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `OPENCLAW_DISABLE_BONJOUR=1` | Disables Gateway-owned LAN multicast advertising when the host owns discovery. | | `OPENCLAW_NO_RESPAWN=1` | In an unmanaged embedding child, prevents OpenClaw from handing an update restart to a detached child. Routine restarts remain in process, so the host keeps ownership of the tracked PID. | | `OPENCLAW_EXEC_SHELL_SNAPSHOT=0` | Disables login-shell snapshot capture for host exec commands. | | `OPENCLAW_SKIP_CHANNELS=1` | Skips channel startup and reload. Set it only when the embedding app wants a control-plane or WebChat-only Gateway. | `--allow-unconfigured` bypasses only the `gateway.mode=local` startup guard. It does not write configuration or repair an invalid file. Omit it when the embedding app provisions a normal local configuration through onboarding, the config CLI, or Gateway RPC. ### Electron shell snapshot warning Shell snapshot capture runs `process.execPath -e