CLI 自動化
使用 --non-interactive 來自動化 openclaw onboard。
基礎非互動式範例
Section titled “基礎非互動式範例”openclaw onboard --non-interactive \ --mode local \ --auth-choice apiKey \ --anthropic-api-key "$ANTHROPIC_API_KEY" \ --secret-input-mode plaintext \ --gateway-port 18789 \ --gateway-bind loopback \ --install-daemon \ --daemon-runtime node \ --skip-bootstrap \ --skip-skills新增 --json 以取得機器可讀取的摘要。
當您的自動化預先植入工作區檔案,並且不希望入門流程建立預設的啟動檔案時,請使用 --skip-bootstrap。
使用 --secret-input-mode ref 將環境變數支援的參照 (env-backed refs) 儲存在設定檔中,而不是純文字值。
在入門流程中,可以進行環境變數參照與已設定的提供者參照 (file 或 exec) 之間的互動式選擇。
在非互動式 ref 模式下,必須在程序環境中設定提供者環境變數。
現在,如果傳遞內聯金鑰旗標但沒有相符的環境變數,將會快速失敗。
範例:
openclaw onboard --non-interactive \ --mode local \ --auth-choice openai-api-key \ --secret-input-mode ref \ --accept-risk特定提供者的範例
Section titled “特定提供者的範例”Anthropic API 金鑰範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice apiKey \ --anthropic-api-key "$ANTHROPIC_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackGemini 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice gemini-api-key \ --gemini-api-key "$GEMINI_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackZ.AI 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice zai-api-key \ --zai-api-key "$ZAI_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackVercel AI Gateway 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice ai-gateway-api-key \ --ai-gateway-api-key "$AI_GATEWAY_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackCloudflare AI Gateway 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice cloudflare-ai-gateway-api-key \ --cloudflare-ai-gateway-account-id "your-account-id" \ --cloudflare-ai-gateway-gateway-id "your-gateway-id" \ --cloudflare-ai-gateway-api-key "$CLOUDFLARE_AI_GATEWAY_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackMoonshot 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice moonshot-api-key \ --moonshot-api-key "$MOONSHOT_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackMistral 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice mistral-api-key \ --mistral-api-key "$MISTRAL_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback綜合範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice synthetic-api-key \ --synthetic-api-key "$SYNTHETIC_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopbackOpenCode 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice opencode-zen \ --opencode-zen-api-key "$OPENCODE_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback切換至 --auth-choice opencode-go --opencode-go-api-key "$OPENCODE_API_KEY" 以使用 Go 目錄。
Ollama 範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice ollama \ --custom-model-id "qwen3.5:27b" \ --accept-risk \ --gateway-port 18789 \ --gateway-bind loopback自訂供應商範例
openclaw onboard --non-interactive \ --mode local \ --auth-choice custom-api-key \ --custom-base-url "https://llm.example.com/v1" \ --custom-model-id "foo-large" \ --custom-api-key "$CUSTOM_API_KEY" \ --custom-provider-id "my-custom" \ --custom-compatibility anthropic \ --custom-image-input \ --gateway-port 18789 \ --gateway-bind loopback--custom-api-key 是可選的。如果省略,入門向導會檢查 CUSTOM_API_KEY。
OpenClaw 會自動將常見的視覺模型 ID 標記為具備影像處理能力。為未知的自訂視覺 ID 新增 --custom-image-input,或新增 --custom-text-input 以強制僅使用文字元資料。
參照模式變體:
export CUSTOM_API_KEY="your-key"openclaw onboard --non-interactive \ --mode local \ --auth-choice custom-api-key \ --custom-base-url "https://llm.example.com/v1" \ --custom-model-id "foo-large" \ --secret-input-mode ref \ --custom-provider-id "my-custom" \ --custom-compatibility anthropic \ --custom-image-input \ --gateway-port 18789 \ --gateway-bind loopback在此模式下,入門向導會將 apiKey 儲存為 { source: "env", provider: "default", id: "CUSTOM_API_KEY" }。
Anthropic setup-token 仍然可用作支援的 onboarding token 路徑,但 OpenClaw 現在會優先使用可用的 Claude CLI。對於生產環境,建議使用 Anthropic API 金鑰。
新增另一個代理程式
Section titled “新增另一個代理程式”使用 openclaw agents add <name> 建立一個擁有自己工作區、
工作階段和驗證設定檔的獨立代理程式。若未帶 --workspace 執行則會啟動精靈。
openclaw agents add work \ --workspace ~/.openclaw/workspace-work \ --model openai/gpt-5.5 \ --bind whatsapp:biz \ --non-interactive \ --json設定項目:
agents.list[].nameagents.list[].workspaceagents.list[].agentDir
備註:
- 預設工作區遵循
~/.openclaw/workspace-<agentId>。 - 新增
bindings以路由傳送傳入訊息(精靈可以執行此操作)。 - 非互動式旗標:
--model、--agent-dir、--bind、--non-interactive。
- 入門中心:入門 (CLI)
- 完整參考:CLI 設定參考
- 指令參考:
openclaw onboard