前面几篇把安装和升级都捋清楚了。这篇就聊两个实战场景:日常 CLI 怎么用,以及怎么把 onboarding 流程脚本化——毕竟在 CI/CD 流水线里,没人会手动去跑向导。

核心命令
网关
网关相关的操作相当直观:
openclaw gateway --port 18789 # 前台启动openclaw gateway status # 状态openclaw gateway stop # 停止openclaw gateway restart # 重启openclaw gateway install # 注册系统服务诊断
诊断命令提供了不同粒度的健康检查:
openclaw status # 本地状态openclaw status --all # 完整诊断openclaw status --deep # 附带 Gateway 健康探测openclaw health --json # 健康快照openclaw doctor # 配置检查 + 迁移openclaw logs --follow # 实时日志渠道与配置
openclaw channels login # 渠道登录(扫码等)openclaw configure # 修改配置openclaw setup # 初始化工作区openclaw dashboard # 打开 Control UI个人助手配置
比较典型的场景是:用一个专用的 WhatsApp 号来充当 AI 助手。这里有三个关键点需要留意:
- 别用个人号——否则每条消息都会被 Agent 处理,干扰日常聊天
- 用一个预付费 SIM 专门做助手号
- 一定要设
allowFrom白名单,防止被陌生人滥用
最简配置示例如下:
{agent: {model: "anthropic/claude-opus-4-6",heartbeat: { every: "0m" }, // 先关掉},channels: {whatsapp: {allowFrom: ["+15555550123"],groups: { "*": { requireMention: true } },},},session: {scope: "per-sender",resetTriggers: ["/new", "/reset"],},}工作区
Agent 的"大脑"其实就在工作区里——默认路径 ~/.openclaw/workspace。里面包含 AGENTS.md、SOUL.md、TOOLS.md 等文件,定义了 Agent 的行为和人设。初始化命令是:
openclaw setup # 初始化工作区强烈建议把这个目录做成 Git 仓库,方便备份和版本管理。
心跳
默认每 30 分钟会让 Agent 主动检查任务。这会消耗 token,初期可以先关掉体验一下再说。
会话
/new或/reset— 开启新会话/compact— 压缩上下文,节省 token
向导自动化
这才是这篇的重点——在生产环境里,尤其是 CI/CD 场景中,不可能有人手动跑向导。必须脚本化。
非交互模式
核心命令如下:
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 只是输出格式,不是非交互模式。脚本里一定要用 --non-interactive 参数。
密钥引用模式
为了避免把 API Key 明文写死在配置里,可以用引用模式:
export ANTHROPIC_API_KEY="sk-xxx"openclaw onboard --non-interactive --mode local --auth-choice apiKey --secret-input-mode ref --gateway-port 18789 --gateway-bind loopback这样配置里存的只是一个环境变量引用,而不是明文 key。这个设计巧妙之处在于把密钥管理的复杂度推给了运行时环境,安全性和灵活性都兼顾了。
各供应商自动化示例
# Ollama(本地模型)openclaw onboard --non-interactive --auth-choice ollama --custom-model-id "qwen3.5:27b" --accept-risk# 自定义供应商openclaw onboard --non-interactive --auth-choice custom-api-key --custom-base-url "https://llm.example.com/v1" --custom-model-id "my-model" --custom-provider-id "my-custom" --custom-compatibility anthropic自动化添加 Agent
添加一个带有独立工作区和认证的 Agent:
openclaw agents add work --workspace ~/.openclaw/workspace-work --model openai/gpt-5.2 --bind whatsapp:biz --non-interactive --json每个 Agent 可以拥有独立的配置,互不干扰。
下一篇
入门篇到此结束。下一篇将进入渠道篇——渠道总览与配对机制。敬请期待。
