OpenClaw 常用命令参考手册

快速掌握 OpenClaw CLI 的核心命令,提升你的 AI 助手工作效率

OpenClaw 是一个强大的 AI 助手框架,通过命令行接口(CLI)提供了丰富的功能。无论是管理网关、配置频道、控制浏览器,还是与 AI 代理交互,都有对应的命令可供使用。本文将为你整理最常用的 OpenClaw 命令,帮助你快速上手。

目录

  • 基础命令
  • 网关管理
  • 频道配置
  • 会话管理
  • 消息发送
  • 模型配置
  • 浏览器控制
  • 节点管理
  • 定时任务
  • 诊断与维护

基础命令

查看版本和帮助

# 查看版本
openclaw --version
openclaw -v

# 查看所有可用命令
openclaw --help

# 查看特定命令的帮助
openclaw gateway --help

全局标志

# 使用开发模式
openclaw --dev status

# 使用自定义配置文件
openclaw --profile myprofile status

# 禁用颜色输出
openclaw --no-color status

# 输出 JSON 格式
openclaw status --json

网关管理

网关(Gateway)是 OpenClaw 的核心服务,负责处理 WebSocket 连接、频道通信和会话管理。

# 前台运行网关
openclaw gateway run

# 后台安装网关服务
openclaw gateway install

# 启动/停止/重启网关服务
openclaw gateway start
openclaw gateway stop
openclaw gateway restart

# 查看网关状态
openclaw gateway status

# 深度检测
openclaw gateway status --deep

# 卸载网关服务
openclaw gateway uninstall

频道配置

OpenClaw 支持多种通信频道:WhatsApp、Telegram、Discord、Slack 等。

# 列出已配置的频道
openclaw channels list

# 查看频道状态
openclaw channels status

# 添加新频道
openclaw channels add --channel telegram --name "Bot" --token $TOKEN

# 移除频道
openclaw channels remove --channel discord --delete

# WhatsApp 登录
openclaw channels login --channel whatsapp

会话管理

# 列出所有会话
openclaw sessions

# 查看特定代理的会话
openclaw sessions --agent work

# 仅查看活跃会话(最近 120 分钟)
openclaw sessions --active 120

# JSON 格式输出
openclaw sessions --json

# 预览清理结果
openclaw sessions cleanup --dry-run

消息发送

# 发送文本消息
openclaw message send --target +15555550123 --message "你好!"

# 指定频道发送
openclaw message send --channel telegram --target @mychat --message "大家好"

# 回复消息
openclaw message send --channel discord --target channel:123 --message "收到" --reply-to 456

# 创建投票
openclaw message poll --channel discord --target channel:123 \
  --poll-question "吃什么?" \
  --poll-option 披萨 --poll-option 寿司 \
  --poll-multi --poll-duration-hours 48

# 添加表情反应
openclaw message react --channel slack --target C123 --message-id 456 --emoji "✅"

# 编辑消息
openclaw message edit --channel discord --target channel:123 --message-id 456 --message "更新内容"

# 删除消息
openclaw message delete --channel telegram --target @mychat --message-id 789

模型配置

# 查看模型状态
openclaw models status

# 检查认证状态
openclaw models status --check

# 列出可用模型
openclaw models list

# 设置默认模型
openclaw models set claude-sonnet-4-5-20250929

# 设置图像模型
openclaw models set-image claude-sonnet-4-5-20250929

# 管理别名
openclaw models aliases list
openclaw models aliases add qwen claude-sonnet-4-5-20250929
openclaw models aliases remove qwen

# 管理回退模型
openclaw models fallbacks add claude-haiku-4-5-20250929

浏览器控制

# 查看浏览器状态
openclaw browser status

# 启动/停止浏览器
openclaw browser start
openclaw browser stop

# 列出标签页
openclaw browser tabs

# 打开网页
openclaw browser open https://example.com

# 截图
openclaw browser screenshot  --full-page

# 导航到网页
openclaw browser navigate https://example.com --target-id 

# 点击元素
openclaw browser click  --target-id 

# 输入文本
openclaw browser type  "Hello World" --target-id 

# 执行 JavaScript
openclaw browser evaluate --fn "document.title" --target-id 

节点管理

# 列出节点
openclaw nodes list

# 查看节点状态
openclaw nodes status

# 查看节点详情
openclaw nodes describe --node 

# 安装节点服务
openclaw node install --host  --port 18789

# 启动/停止/重启节点
openclaw node start/stop/restart

# 在节点上运行命令
openclaw nodes run --node  ls -la

# 发送通知(Mac 节点)
openclaw nodes notify --node  --title "提醒" --body "任务完成"

# 拍摄摄像头照片
openclaw nodes camera snap --node  --facing front

# 录制视频片段
openclaw nodes camera clip --node  --duration 10s

定时任务

# 查看 cron 状态
openclaw cron status

# 列出所有任务
openclaw cron list

# 添加定时任务
openclaw cron add --name "每日备份" --cron "0 2 * * *" --message "执行备份"

# 添加每小时任务
openclaw cron add --name "每小时检查" --every 1h --system-event "检查状态"

# 启用/禁用任务
openclaw cron enable 
openclaw cron disable 

# 删除任务
openclaw cron rm 

# 手动运行任务
openclaw cron run 

诊断与维护

# 快速诊断
openclaw status

# 完整诊断
openclaw status --all

# 深度检测
openclaw status --deep

# 查看模型使用量
openclaw status --usage

# 健康检查
openclaw health

# 医生模式(自动修复)
openclaw doctor

# 安全审计
openclaw security audit

# 查看日志
openclaw logs --follow
openclaw logs --limit 200

# 配置管理
openclaw config get agents.defaults.model
openclaw config set agents.defaults.model claude-sonnet-4-5-20250929
openclaw configure

实用技巧

1. 使用 JSON 输出进行脚本编写

openclaw channels status --json | jq '.channels[]'
openclaw sessions --json | jq '.sessions[].key'

2. 使用环境变量

export OPENCLAW_GATEWAY_TOKEN=your_token
export ANTHROPIC_API_KEY=your_key
openclaw models status

快速参考表

类别常用命令
网关gateway start/stop/restart/status
频道channels list/add/remove/login
消息message send/poll/react/broadcast
会话sessions list/cleanup
模型models status/set/aliases/fallbacks
浏览器browser start/stop/open/screenshot
节点nodes list/run/notify/camera
定时cron list/add/run/rm
诊断status/health/doctor/logs
配置config get/set/configure

结语

OpenClaw 提供了丰富的命令行工具,涵盖了从基础配置到高级自动化的各个方面。掌握这些命令可以帮助你更高效地管理和使用 AI 助手。

提示:

  • 使用 --help 查看任何命令的详细选项
  • 使用 --json 获取机器可读的输出
  • 使用 --dry-run 预览操作结果
  • 定期运行 openclaw doctor 进行健康检查

更多详细信息,请访问 OpenClaw 官方文档

最后更新:2026 年 2 月 25 日