Skip to content
广告 · 本站推荐广告

CLI 自动化

使用 --non-interactive 参数可以在脚本和自动化流程中运行 openclaw onboard,无需人工交互。

注意

--json 隐含非交互模式。脚本中必须显式使用 --non-interactive(以及 --workspace)。

基础非交互示例

bash
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 中存储基于环境变量的引用(ref),而非明文值。

  • 在交互式引导中,可以选择环境变量引用或已配置的 provider 引用(fileexec
  • 在非交互 ref 模式下,provider 环境变量必须在进程环境中预先设置
  • 传入内联密钥参数但缺少对应环境变量时,将会立即失败
bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice openai-api-key \
  --secret-input-mode ref \
  --accept-risk

各 Provider 示例

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

ZAI

bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice zai-api-key \
  --zai-api-key "$ZAI_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback

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 Zen

bash
openclaw onboard --non-interactive \
  --mode local \
  --auth-choice opencode-zen \
  --opencode-zen-api-key "$OPENCODE_API_KEY" \
  --gateway-port 18789 \
  --gateway-bind loopback

自定义 API Key

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

自定义 Provider 的 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 存储为:

json
{ "source": "env", "provider": "default", "id": "CUSTOM_API_KEY" }

添加新的 Agent(智能体)

使用 openclaw agents add 创建一个独立的 Agent,拥有自己的工作空间、会话和 auth profiles。不带 --workspace 运行会启动交互式向导。

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

设置的配置项:

  • agents.list[].name — Agent 名称
  • agents.list[].workspace — 工作空间路径
  • agents.list[].agentDir — Agent 目录

注意事项:

  • 默认工作空间路径遵循 ~/.openclaw/workspace-<name> 格式
  • 添加 bindings 可以路由入站消息(向导可以完成此操作)
  • 非交互模式支持的参数:--model--agent-dir--bind--non-interactive

相关文档

基于MIT协议开源 | 内容翻译自 官方文档,同步更新