OpenClaw 是一个个人 AI 助手框架,能把你的聊天统一接入 WhatsApp、Telegram、Discord、Web 等平台。除了 Web 控制台,它的真正能力藏在终端里。
本文覆盖日常高频使用的 CLI 命令。
1. 启动与健康检查
先用这几条确认 Gateway 是否正常运行:
# 查看服务状态
openclaw gateway status
# 快速健康探测
openclaw health
# 自动诊断并修复问题
openclaw doctor
# 查看日志
openclaw logs
如果 Gateway 还没跑起来:
openclaw gateway start # 以守护进程启动
openclaw gateway run # 前台运行(调试用)
openclaw gateway restart # 重启
openclaw gateway stop # 停止
2. 打开会话
TUI 交互式终端
# 基本用法 —— 连到 Gateway,使用默认 "main" 会话
openclaw chat
# 本地嵌入式模式(不需要 Gateway,需在环境变量中设置 API Key)
openclaw chat --local
# 指定自定义 session key
openclaw chat --session mychat
# 打开时设置推理深度
openclaw chat --thinking high
# 启动时自动发送一条消息
openclaw chat --message "帮我分析一下这个项目"
单次 Agent 调用(不走 TUI)
# 发一条消息,在终端获取回复
openclaw agent --message "帮我总结最近日志"
# 指定某个 agent
openclaw agent --agent ops --message "检查系统状态"
# 发到手机号(会创建新会话)
openclaw agent --to +15555550123 --message "你好"
# 回复投递回聊天渠道
openclaw agent --deliver --message "报告已生成"
3. 选择 / 切换模型
查看当前默认模型
openclaw config get agents.defaults.model
# 输出: { "primary": "deepseek/deepseek-v4-pro" }
设置新默认模型
openclaw config set agents.defaults.model "anthropic/claude-sonnet-4-20250514"
单次运行指定模型
openclaw agent --model openai/gpt-4o --message "..."
openclaw agent --model deepseek/deepseek-v4-pro --thinking high --message "..."
交互式配置
openclaw configure --section model
4. 查看会话历史
# 列出所有会话
openclaw sessions
# 最近 50 条
openclaw sessions --limit 50
# 只看最近 2 小时活跃的
openclaw sessions --active 120
# 按 agent 过滤
openclaw sessions --agent work
# 汇总所有 agent 的会话
openclaw sessions --all-agents
# JSON 输出(方便脚本处理)
openclaw sessions --json
5. 管理设备
当你用新设备(手机、平板、另一台电脑)登录时,会产生一个配对请求。需要在已授权的设备上批准:
# 查看待处理和已配对的设备
openclaw devices list
# 批准配对请求(用 request ID)
openclaw devices approve <request-id>
# 拒绝配对请求
openclaw devices reject <request-id>
# 撤销设备授权
openclaw devices revoke <device-id>
6. 管理 Agent
Agent 是独立的 AI 身份,有自己的工作区、模型和路由规则。
# 列出所有 agent
openclaw agents list
# 新建 agent
openclaw agents add
# 查看路由绑定
openclaw agents bindings
# 删除 agent
openclaw agents delete <agent-id>
7. 管理消息渠道
openclaw channels
支持 Telegram、WhatsApp、Discord、Signal、Slack、iMessage、Matrix、LINE、飞书、企业微信(QQ Bot)、Microsoft Teams 等众多平台。
8. 配置速查
# 读取配置项
openclaw config get gateway.port
# 设置配置项
openclaw config set gateway.port 19001
# 删除配置项
openclaw config unset some.key
# 校验配置合法性
openclaw config validate
# 打印配置文件路径
openclaw config file
# 交互式引导配置
openclaw configure
9. 定时任务(Cron)
安排定期或一次性的 Agent 任务:
openclaw cron list # 列出已调度任务
openclaw cron add # 创建新任务
openclaw cron run <id> # 立即触发任务
openclaw cron remove <id> # 删除任务
10. 备份
openclaw backup
创建 OpenClaw 状态的本地备份归档。
实战流程示例
一个典型的运维排查流程:
# 1. 看看系统是否健康
openclaw health
# 2. 查看最近活跃的会话
openclaw sessions --active 60
# 3. 批准手机登录
openclaw devices list
openclaw devices approve <id>
# 4. 用指定模型开个聊天
openclaw chat --model deepseek/deepseek-v4-pro --thinking high
# 5. 出问题后翻日志
openclaw logs
以上就是 OpenClaw 命令行的核心操作面。深入某个命令可以跑 openclaw <command> --help,或者查阅官方文档。