fix: use user-local npm prefix for openclaw install (#1941)

npm install -g openclaw fails with EACCES on non-root users (e.g.,
ubuntu on AWS Lightsail) because /usr/local/lib/node_modules isn't
writable. Use the same ~/.npm-global prefix pattern already used by
codex and kilocode agents.

Fixes both the standard installAgent path and the batched
setupOpenclawBatched path (used by Fly).

Co-authored-by: spawn-bot <spawn-bot@openrouter.ai>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
A 2026-02-25 21:57:09 -08:00 committed by GitHub
parent 357132b506
commit 954f3b4893
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.10.17",
"version": "0.10.18",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -327,12 +327,13 @@ export async function setupOpenclawBatched(
const script = [
'echo "==> Checking openclaw..."',
'export PATH="$HOME/.bun/bin:$HOME/.local/bin:$PATH"',
'export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH"',
"if command -v openclaw >/dev/null 2>&1; then",
' echo " openclaw found at $(command -v openclaw)"',
"else",
' echo " openclaw not found, installing..."',
" npm install -g openclaw",
" mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g openclaw",
' export PATH="$HOME/.npm-global/bin:$PATH"',
' command -v openclaw || { echo "ERROR: openclaw install failed"; exit 1; }',
"fi",
'echo "==> Writing environment variables..."',
@ -475,7 +476,12 @@ export function createAgents(runner: CloudRunner): Record<string, AgentConfig> {
cloudInitTier: "full",
modelPrompt: true,
modelDefault: "openrouter/auto",
install: () => installAgent(runner, "openclaw", "source ~/.bashrc && npm install -g openclaw"),
install: () =>
installAgent(
runner,
"openclaw",
"source ~/.bashrc && mkdir -p ~/.npm-global/bin && npm config set prefix ~/.npm-global && npm install -g openclaw",
),
envVars: (apiKey) => [
`OPENROUTER_API_KEY=${apiKey}`,
`ANTHROPIC_API_KEY=${apiKey}`,