From cb4e6839b762aa9e3adb229ee7d99ff347eee6f9 Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:45:36 -0800 Subject: [PATCH] fix: add ~/.npm-global/bin to OpenClaw PATH for gateway, launch, and reconnect (#1972) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add ~/.npm-global/bin to OpenClaw PATH for gateway, launch, and reconnect OpenClaw installs to ~/.npm-global/bin/ via npm, but startGateway() and launchCmd() only included ~/.bun/bin and ~/.local/bin in PATH — so the `openclaw` binary was never found on non-Fly clouds (DigitalOcean, Hetzner, AWS, GCP). Fly was unaffected because it uses setupOpenclawBatched() which correctly includes the npm-global path. Three fixes: 1. startGateway(): add $HOME/.npm-global/bin to PATH 2. launchCmd(): add $HOME/.npm-global/bin to PATH 3. install(): persist PATH to ~/.bashrc and ~/.zshrc (matching codex/kilocode pattern) so reconnects via `spawn openclaw --name ...` also work Closes #1965 Co-Authored-By: Claude Opus 4.6 (1M context) * fix: correct command chaining and idempotency in npm-global PATH setup - Use curly braces to group grep||echo so PATH append only runs after successful npm install (fixes operator precedence bug) - Skip ~/.zshrc modification when file doesn't exist (avoids creating it on non-zsh systems) - Use grep -qF for literal string matching (no regex interpretation) - Apply fix to all three affected agents: openclaw, codex, kilocode Co-Authored-By: Claude Sonnet 4.6 --------- Co-authored-by: Claude Co-authored-by: Claude Opus 4.6 (1M context) Co-authored-by: B <6723574+louisgv@users.noreply.github.com> --- packages/cli/package.json | 2 +- packages/cli/src/shared/agent-setup.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index c272c32d..558a9bc3 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@openrouter/spawn", - "version": "0.10.25", + "version": "0.10.26", "type": "module", "bin": { "spawn": "cli.js" diff --git a/packages/cli/src/shared/agent-setup.ts b/packages/cli/src/shared/agent-setup.ts index 34e73ebc..691271bb 100644 --- a/packages/cli/src/shared/agent-setup.ts +++ b/packages/cli/src/shared/agent-setup.ts @@ -463,8 +463,8 @@ export function createAgents(runner: CloudRunner): Record { runner, "Codex CLI", "mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g @openai/codex && " + - "grep -q '.npm-global/bin' ~/.bashrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.bashrc; " + - "grep -q '.npm-global/bin' ~/.zshrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.zshrc", + "{ grep -qF '.npm-global/bin' ~/.bashrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.bashrc; } && " + + "{ [ ! -f ~/.zshrc ] || grep -qF '.npm-global/bin' ~/.zshrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.zshrc; }", ), envVars: (apiKey) => [ `OPENROUTER_API_KEY=${apiKey}`, @@ -482,7 +482,9 @@ export function createAgents(runner: CloudRunner): Record { installAgent( runner, "openclaw", - "source ~/.bashrc && mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g openclaw", + "source ~/.bashrc && mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g openclaw && " + + "{ grep -qF '.npm-global/bin' ~/.bashrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.bashrc; } && " + + "{ [ ! -f ~/.zshrc ] || grep -qF '.npm-global/bin' ~/.zshrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.zshrc; }", ), envVars: (apiKey) => [ `OPENROUTER_API_KEY=${apiKey}`, @@ -513,8 +515,8 @@ export function createAgents(runner: CloudRunner): Record { runner, "Kilo Code", "mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g @kilocode/cli && " + - "grep -q '.npm-global/bin' ~/.bashrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.bashrc; " + - "grep -q '.npm-global/bin' ~/.zshrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.zshrc", + "{ grep -qF '.npm-global/bin' ~/.bashrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.bashrc; } && " + + "{ [ ! -f ~/.zshrc ] || grep -qF '.npm-global/bin' ~/.zshrc 2>/dev/null || echo 'export PATH=\"$HOME/.npm-global/bin:$PATH\"' >> ~/.zshrc; }", ), envVars: (apiKey) => [ `OPENROUTER_API_KEY=${apiKey}`,