{“content”:”---\nname: openclaw-pc-startup\ndescription: 在 Windows PC 上啟動 OpenClaw(Node.js 龍蝦)的正確方法(透過 SSH)\ntrigger: 啟動 openclaw, start openclaw, openclaw 沒有在跑, 龙虾没有反应\n---\n\n# OpenClaw PC 啟動方法(SSH 遠端)\n\n## 系統架構(重要釐清)\n\n- OpenClaw(龍蝦) = Node.js 程序,openclaw.mjs,port 18789\n- Hermes Gateway = Python 程序,gateway.cmd 是 Hermes 的啟動選單,不是 OpenClaw\n- 兩者是獨立的,OpenClaw 是你的 AI Agent 本體\n\n## OpenClaw 正確路徑\n\n\nC:\\Users\\Sozo\\AppData\\Roaming\\npm\\node_modules\\openclaw\\openclaw.mjs\n\n\n⚠️ .openclaw-VddkRhR3 資料夾已不穩定(被 npm install 覆蓋後 openclaw.mjs 消失)。請用上面的穩定路徑。\n\n## 啟動指令(2026-04-20 確認有效)\n\nbash\nssh [email protected] \"powershell -NoProfile -Command \\\"Remove-Item 'C:\\\\Users\\\\Sozo\\\\AppData\\\\Local\\\\Temp\\\\openclaw\\\\gateway.*.lock' -Force 2>`$null; Start-Process -FilePath 'C:\\\\Program Files\\\\nodejs\\\\node.exe' -ArgumentList '--stack-size=4096','C:\\\\Users\\\\Sozo\\\\AppData\\\\Roaming\\\\npm\\\\node_modules\\\\openclaw\\\\openclaw.mjs','gateway','--port','18789' -WindowStyle Hidden -RedirectStandardOutput 'C:\\\\Users\\\\Sozo\\\\AppData\\\\Local\\\\Temp\\\\openclaw\\\\stdout.log' -RedirectStandardError 'C:\\\\Users\\\\Sozo\\\\AppData\\\\Local\\\\Temp\\\\openclaw\\\\stderr.log'\\\"\"\n\n\n## 驗證\n\nbash\nssh [email protected] \"netstat -ano | findstr 18789\"\n\n\n確認有 TCP 127.0.0.1:18789 LISTENING 即成功。若無回應,等 10 秒再試。\n\n## 為什麼其他方法失敗\n\n| 方法 | 問題 |\n|------|------|\n| cmd /c start \"gateway.cmd\" | 啟動的是 Hermes 選單,不是 OpenClaw |\n| Start-Process -NoNewWindow -Wait | foreground 等待,SSH session 會卡住 |\n| Start-Process -WindowStyle Hidden( alone)| 程序啟動但沒有真正背景化,port 不 Listening |\n| cmd /c start + openclaw.mjs | SSH timeout 無法等待程序啟動 |\n\n成功關鍵:同時使用 -RedirectStandardOutput + -RedirectStandardError 讓程序真正脫離 SSH session。\n\n## 常見問題\n\n1. SSH timeout — 用 Tailscale IP 100.83.112.84,LAN IP 192.168.68.100 容易不穩\n2. cmd /c start 無反應 — OpenClaw 不能這樣啟動,必須用 PowerShell Start-Process\n3. openclaw.mjs 消失 — npm install 會覆蓋 .openclaw-VddkRhR3,使用 C:\\\\Users\\\\Sozo\\\\AppData\\\\Roaming\\\\npm\\\\node_modules\\\\openclaw\\\\ 下的穩定版本\n4. Lock file 導致無法啟動 — 位置在 C:\\Users\\Sozo\\AppData\\Roaming\\npm\\node_modules\\openclaw\\state\\lock。啟動前刪除,若仍失敗再刪一次後重試\n5. 重啟前 kill 舊程序:\n bash\n ssh [email protected] \"taskkill /F /PID <PID>\"\n \n\n## Port 對照\n\n| Port | Service |\n|------|---------|\n| 18789 | OpenClaw Gateway HTTP |\n| 18791 | Browser control |\n\n## Telegram Bot 沒有回應的排查\n\n### 1. 確認進程在運行\nbash\nssh [email protected] 'powershell -NoProfile -Command \"Get-Process -Name node | Select-Object Id,Path,WorkingSet64\"'\n\n應該看到 node.exe 進程,記憶體 1GB+ 為正常。\n\n### 2. 確認 Port 18789 監聽中\nbash\nssh [email protected] 'powershell -NoProfile -Command \"Get-NetTCPConnection -LocalPort 18789\"'\n\n或連接測試:\nbash\nssh [email protected] 'powershell -NoProfile -Command \"try { $client = New-Object System.Net.Sockets.TcpClient; $client.Connect(\\\"127.0.0.1\\\", 18789); $client.Close(); Write-Host \\\"CONNECTED\\\" } catch { Write-Host \\\"FAILED:\\\", $_.Exception.Message }\"'\n\n\n### 3. 檢查 OpenClaw 日誌\nbash\n# Temp 目錄的日誌\nssh [email protected] 'cmd /c \"type C:\\Users\\Sozo\\AppData\\Local\\Temp\\openclaw\\openclaw-2026-05-05.log\"'\n\n# 或 OpenClaw 目錄的日誌\nssh [email protected] 'cmd /c \"type D:\\OpenClaw_Home\\.openclaw\\logs\\gateway-out.log\"'\n\n\n### 4. 常見錯誤與修復\n\nSandbox 模式錯誤:\n\n[tools] exec failed: exec host=sandbox requires a sandbox runtime for this session.\nEnable sandbox mode (`agents.defaults.sandbox.mode=\"non-main\"` or `\"all\"`) or use host=auto/gateway/node.\n\n→ 在 D:\\OpenClaw_Home\\.openclaw\\openclaw.json 裡添加:\njson\n{\n \"agents\": {\n \"defaults\": {\n \"sandbox\": {\n \"mode\": \"all\"\n }\n }\n }\n}\n\n\nWorkspace 路徑錯誤:\n\n[tools] read failed: EISDIR: illegal operation on a directory\n\n→ 檢查 agents.defaults.tools.execute.path 設定,確保是檔案而非目錄。\n\n### 5. 確認 Telegram 配置正確\nbash\nssh [email protected] 'powershell -NoProfile -Command \"Get-Content D:\\OpenClaw_Home\\.openclaw\\openclaw.json | ConvertFrom-Json | Select-Object -ExpandProperty channels | Select-Object -ExpandProperty telegram | ConvertTo-Json -Depth 3\"'\n\n應該看到 \"enabled\": true。\n\n### 6. SSH PowerShell 路徑處理注意\nSSH 裡執行 PowerShell 時,C:\\Program Files\\nodejs\\node.exe 這類有空格的路徑會失敗。解決方法:\n\n方法A:使用 8.3 短路徑\nbash\n# 獲取短路徑\nssh [email protected] 'cmd /c \"for %i in (C:\\Program Files\\nodejs\\node.exe) do @echo %~si\"'\n# 輸出:C:\\PROGRA~1\\nodejs\\node.exe\n\n# 使用短路徑\nssh [email protected] 'cmd /c \"C:\\PROGRA~1\\nodejs\\node.exe --version\"'\n\n\n方法B:上傳腳本執行(最可靠)\npowershell\n# 寫 script.ps1 上传到 PC\n# C:\\Users\\Sozo\\AppData\\Local\\Temp\\script.ps1\n# 然後執行:\nssh [email protected] 'powershell -ExecutionPolicy Bypass -File C:\\Users\\Sozo\\AppData\\Local\\Temp\\script.ps1'\n\n\n### 7. OpenClaw 目錄結構\n\nConfig: D:\\OpenClaw_Home\\.openclaw\\openclaw.json\nLogs: D:\\OpenClaw_Home\\.openclaw\\logs\\gateway-*.log\n C:\\Users\\Sozo\\AppData\\Local\\Temp\\openclaw\\openclaw-*.log\nTelegram: D:\\OpenClaw_Home\\.openclaw\\telegram\\\nWorkspace: D:\\OpenClaw_Home\\.openclaw\\workspace\\\n\n”}