This document covers how OCCode's built-in OpenClaw installer works, what prerequisites it checks, and the design decisions behind the install flow.
When a user opens OCCode and OpenClaw is not installed, the Home panel offers a one-click install. The installer runs silently (no terminal window) and streams output to the Home panel in real-time.
The install flow follows this sequence:
1. Prerequisite checks (platform-specific)
2. Permission detection (proactive sudo)
3. Install via npm or fallback script
4. Post-install CLI verification
5. Auto-configure (if signed in)
| Prerequisite | Check | If Missing |
|---|---|---|
| Xcode CLI Tools | xcode-select -p |
Triggers xcode-select --install (system dialog), asks user to restart |
| Node.js >= 20 | node --version + nvm check |
Auto-installs via nvm or official .pkg |
| npm | npm --version |
Comes with Node.js install |
| Write access | fs.accessSync(npmPrefix, W_OK) |
Asks for sudo password upfront |
| Prerequisite | Check | If Missing |
|---|---|---|
| Node.js | node --version |
Fails with link to nodejs.org |
| npm | npm --version |
Fails with link to nodejs.org |
| Prerequisite | Check | If Missing |
|---|---|---|
| Node.js >= 20 | node --version + nvm check |
Auto-installs via nvm, apt-get, dnf, or yum |
| npm | npm --version |
Comes with Node.js install |
| Write access | fs.accessSync(/usr/local/*, W_OK) |
Asks for sudo password upfront |
Problem solved: Previously, the installer would attempt npm install -g,
fail with EACCES, then ask for a password and retry. This caused confusing
error output and a poor UX.
New approach: Before any install command runs:
- If npm is available: check write access to
$(npm config get prefix)/binand$(npm config get prefix)/lib - If npm is not available: check write access to
/usr/local/binand/usr/local/lib - If either check fails -> prompt for password via the in-webview modal
- Cache credentials with
sudo -S -v - All subsequent install commands use
sudo -E/sudo -nfrom the start
The cached sudo session is reused across Node.js install + openclaw install, so the user only enters their password once.
After install, ~/.openclaw ownership is fixed with
sudo chown -R $USER:$USER ~/.openclaw && chmod 700 ~/.openclaw.
After install, the extension needs to find the openclaw binary. The following
directories are added to PATH for all spawned processes:
| Path | Source |
|---|---|
/usr/local/bin |
Standard system |
/opt/homebrew/bin |
Homebrew (Apple Silicon) |
~/.local/bin |
User-local installs |
~/.npm-global/bin |
Custom npm prefix |
~/.openclaw/bin |
OpenClaw self-install |
~/.nvm/versions/node/v*/bin |
nvm (top 3 versions, newest first) |
~/.local/share/fnm/node-versions/v*/bin |
fnm |
/opt/homebrew/opt/node/bin |
Homebrew Node (macOS) |
/usr/local/opt/node/bin |
Homebrew Node Intel (macOS) |
| Path | Source |
|---|---|
%APPDATA%\npm |
npm global |
%ProgramFiles%\nodejs |
Official installer |
%LOCALAPPDATA%\Programs\nodejs |
User-scoped installer |
%SystemRoot%\System32 |
System |
After install reports success, the extension does not immediately run
openclaw onboard. Instead:
- Waits 2 seconds for PATH changes to settle
- Sends
verifyCliBeforeSetupto extension host - Extension host runs
_testOpenClawCli()(nvm-aware) - If found -> proceeds to auto-configure
- If not found -> shows "Please restart OCCode" message
This prevents the ENOENT crash that occurred when the binary was installed
but not yet visible to the extension process.
# Without sudo (nvm, user-writable prefix)
npm install -g openclaw
# With sudo (system prefix like /usr/local)
sudo -E npm install -g openclaw- Try nvm if
~/.nvm/nvm.shexists - macOS: download official Node.js .pkg, install via
sudo installer - Linux: use nodesource setup script + apt-get/dnf/yum
- Then
npm install -g openclaw
npm install -g openclawFallback:
powershell -NoProfile -ExecutionPolicy Bypass -Command `
"Invoke-WebRequest -UseBasicParsing https://openclaw.ai/install.ps1 | Invoke-Expression"If all install methods fail:
- Full output log is collected
- AI assistant (MoltPilot) is invoked with the complete log + system info
- User can ask MoltPilot for platform-specific troubleshooting
All install logic lives in:
apps/editor/extensions/openclaw/src/panels/home.ts
Key methods:
runInstall()— main install flow with prerequisite checks + proactive sudo_buildExecEnv()— PATH construction for spawned processes (nvm/fnm/homebrew aware)_testOpenClawCli()— post-install binary detection (nvm-aware)_findOpenClawPath()— binary path resolution