CLI 自动化

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

注意: --json 并不意味着非交互模式。脚本中请使用 --non-interactive(配合 --workspace)。

基本的非交互示例

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 可以在认证 profile 中存储基于环境变量的引用,而不是明文值。 交互式 onboarding 流程中还支持在环境变量引用和已配置的 provider ref(fileexec)之间选择。

在非交互 ref 模式下,供应商环境变量必须在进程环境中已设置。 在没有对应环境变量的情况下传入内联 key 参数会直接报错。

示例:

openclaw onboard --non-interactive \
  --mode local \
  --auth-choice openai-api-key \
  --secret-input-mode ref \
  --accept-risk

各供应商示例

Gemini 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice gemini-api-key \
  --gemini-api-key "$GEMINI_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
Z.AI 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice zai-api-key \
  --zai-api-key "$ZAI_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
Vercel AI Gateway 示例
```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
```
Cloudflare AI Gateway 示例
```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
```
Moonshot 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice moonshot-api-key \
  --moonshot-api-key "$MOONSHOT_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
Mistral 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice mistral-api-key \
  --mistral-api-key "$MISTRAL_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
Synthetic 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice synthetic-api-key \
  --synthetic-api-key "$SYNTHETIC_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
OpenCode 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice opencode-zen \
  --opencode-zen-api-key "$OPENCODE_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback
```
切换到 Go catalog:`--auth-choice opencode-go --opencode-go-api-key "$OPENCODE_API_KEY"`。
Ollama 示例
```bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice ollama \
  --custom-model-id "qwen3.5:27b" \
  --accept-risk \
  --gateway-port 18789 \
  --gateway-bind loopback
```
自定义供应商示例
```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` 是可选的。如果省略,onboarding 会检查 `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
```

在此模式下,onboarding 将 `apiKey` 存储为 `{ source: "env", provider: "default", id: "CUSTOM_API_KEY" }`。

添加新 Agent

使用 openclaw agents add <name> 创建独立的 Agent,拥有自己的工作区、会话和认证 profile。不加 --workspace 参数会启动向导。

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

相关文档