跳转到内容

CLI Automation

使用 --non-interactive 自动化 openclaw onboard

`--json` 不意味着非交互模式。在脚本中使用 `--non-interactive`(和 `--workspace`)。
Terminal window
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-skills

添加 --json 以获取机器可读的摘要。

使用 --secret-input-mode ref 将环境变量引用存储到 auth profiles 中,而不是明文值。 交互式选择环境变量引用和已配置的提供者引用(fileexec)在引导向导流程中可用。

在非交互式 ref 模式下,提供者环境变量必须在进程环境中设置。 传递内联 key 标志但没有匹配的环境变量时会立即失败。

示例:

Terminal window
openclaw onboard --non-interactive \
--mode local \
--auth-choice openai-api-key \
--secret-input-mode ref \
--accept-risk
```bash openclaw onboard --non-interactive \ --mode local \ --auth-choice gemini-api-key \ --gemini-api-key "$GEMINI_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback ``` ```bash openclaw onboard --non-interactive \ --mode local \ --auth-choice zai-api-key \ --zai-api-key "$ZAI_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback ``` ```bash 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 loopback ``` ```bash 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 loopback ``` ```bash openclaw onboard --non-interactive \ --mode local \ --auth-choice moonshot-api-key \ --moonshot-api-key "$MOONSHOT_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback ``` ```bash openclaw onboard --non-interactive \ --mode local \ --auth-choice mistral-api-key \ --mistral-api-key "$MISTRAL_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback ``` ```bash openclaw onboard --non-interactive \ --mode local \ --auth-choice synthetic-api-key \ --synthetic-api-key "$SYNTHETIC_API_KEY" \ --gateway-port 18789 \ --gateway-bind loopback ``` ```bash 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 catalog。 ```bash 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 \ --gateway-port 18789 \ --gateway-bind loopback ```
`--custom-api-key` 是可选的。如果省略,引导流程会检查 `CUSTOM_API_KEY`。
Ref 模式变体:
```bash
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 \
--gateway-port 18789 \
--gateway-bind loopback
```
在此模式下,引导流程将 `apiKey` 存储为 `{ source: "env", provider: "default", id: "CUSTOM_API_KEY" }`。

使用 openclaw agents add <name> 创建一个拥有独立工作区、会话和 auth profiles 的代理。不带 --workspace 运行会启动向导。

Terminal window
openclaw agents add work \
--workspace ~/.openclaw/workspace-work \
--model openai/gpt-5.2 \
--bind whatsapp:biz \
--non-interactive \
--json

它设置的内容:

  • agents.list[].name
  • agents.list[].workspace
  • agents.list[].agentDir

说明:

  • 默认工作区遵循 ~/.openclaw/workspace-<agentId> 格式。
  • 添加 bindings 来路由入站消息(向导可以完成此操作)。
  • 非交互式标志:--model--agent-dir--bind--non-interactive