引言

本文是 OpenClaw 命令行工具(CLI)的常用命令速查与实战手册。内容主要面向开发者、运维人员以及习惯在终端工作的极客玩家。

通过这篇文章,你将系统掌握如何在命令行环境下高效驾驭 OpenClaw。文章涵盖了从基础的系统与大模型配置、Gateway 服务的启停运维,到跨平台(如 Telegram、WhatsApp、Slack 等)的消息流转,再到高阶的智能家居节点控制与 Cron 自动化定时任务。无论你是刚开始搭建本地的 AI 智能助理,还是准备将其部署并维护在生产环境中,这份指南都能帮你快速建立全局视角,用最纯粹的极客方式掌控 OpenClaw。

第一部分:快速入门

查看帮助信息

1
2
3
4
5
6
7
8
9
10
11
# 查看所有命令
openclaw --help

# 查看版本号
openclaw --version

# 查看特定命令的帮助
openclaw <command> --help

# 示例:查看 config 命令帮助
openclaw config --help

初始化配置

1
2
3
4
5
6
7
8
# 首次安装后初始化配置
openclaw setup

# 交互式引导配置(推荐新手)
openclaw onboard

# 打开控制面板
openclaw dashboard

第二部分:配置管理命令

查看配置

1
2
3
4
5
6
7
8
9
10
11
12
# 查看完整配置
openclaw config get


# 查看特定配置项
openclaw config get models.default
openclaw config get providers.openai.apiKey
openclaw config get providers.mistral.apiKey

# 查看特定部分配置
openclaw config get --section models
openclaw config get --section providers

示例输出:

1
2
3
4
5
6
7
8
9
10
{
"models": {
"default": "mistral:mixtral-8x7b"
},
"providers": {
"mistral": {
"apiKey": "***REDACTED***"
}
}
}

设置配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 设置默认模型
openclaw config set models.default mistral:mixtral-8x7b

# 设置快速模型
openclaw config set models.fast mistral:mistral-7b

# 配置 OpenAI API Key
openclaw config set providers.openai.apiKey YOUR_OPENAI_API_KEY_HERE

# 配置 Mistral API Key
openclaw config set providers.mistral.apiKey YOUR_API_KEY_HERE

# 启用缓存
openclaw config set cache.enabled true
openclaw config set cache.maxSize 5000

删除配置

1
2
3
4
5
# 删除特定配置项
openclaw config unset models.fast

# 重置某个节点
openclaw config unset models

配置向导

1
2
3
4
5
6
7
# 打开完整配置向导
openclaw configure

# 打开特定部分配置向导
openclaw configure --section models
openclaw configure --section providers
openclaw configure --section channels

第三部分:Gateway 控制命令

启动/停止 Gateway

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 启动 Gateway(默认端口 18789)
openclaw gateway start

# 自定义端口启动
openclaw gateway start --port 19000

# 强制启动(杀死占用进程)
openclaw gateway start --force

# 停止 Gateway
openclaw gateway stop

# 重启 Gateway
openclaw gateway restart

# 查看运行状态
openclaw gateway status

运行时 Gateway

1
2
3
4
5
6
7
8
# 前台运行 Gateway(调试用)
openclaw gateway

# 开发模式运行(隔离状态)
openclaw --dev gateway

# 查看健康状态
openclaw health

查看日志

1
2
3
4
5
6
7
8
9
10
11
# 查看实时日志
openclaw logs

# 查看最近 50 行日志
openclaw logs --lines 50

# 查看错误日志
openclaw logs --filter error

# 持续监控日志
openclaw logs --follow

系统服务管理

1
2
3
4
5
6
7
8
# 使用 systemd 管理(推荐生产环境)
sudo systemctl start openclaw-gateway
sudo systemctl stop openclaw-gateway
sudo systemctl restart openclaw-gateway
sudo systemctl status openclaw-gateway

# 开机自启动
sudo systemctl enable openclaw-gateway

第四部分:消息发送命令

发送消息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 发送消息到当前会话
openclaw message send --message "Hello"

# 发送到特定目标(Telegram)
openclaw message send \
--channel telegram \
--target @mychat \
--message "Hello from OpenClaw"

# 发送到特定目标(WhatsApp)
openclaw message send \
--channel whatsapp \
--target +8613012345678 \
--message "你好"

# 发送到 Slack 频道
openclaw message send \
--channel slack \
--target C1234567890 \
--message "@channel 重要通知"

发送媒体文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 发送图片
openclaw message send \
--channel telegram \
--target @mychat \
--media /tmp/photo.jpg \
--caption "这是一张图片"

# 发送音频
openclaw message send \
--channel whatsapp \
--target +8613012345678 \
--media /tmp/voice.mp3

# 发送文档
openclaw message send \
--channel telegram \
--target @mychat \
--media /tmp/report.pdf

高级消息功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 发送 JSON 格式(脚本自动化)
openclaw message send \
--target @mychat \
--message "Hello" \
--json

# 回复消息
openclaw message send \
--target @mychat \
--message "收到" \
--replyTo 12345

# 指定频道
openclaw message send \
--channel discord \
--target channel:1234567890 \
--message "Hello"

频道动作(投票、反应等)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 创建投票(Telegram)
openclaw message send \
--channel telegram \
--target @mychat \
--pollQuestion "OpenClaw 好用吗?" \
--pollOption 非常好用 \
--pollOption 一般 \
--pollOption 还需要改进 \
--pollDurationHours 24

# 发送反应(Discord)
openclaw message send \
--channel discord \
--messageId 1234567890 \
--emoji 👍 \
--action react

第五部分:技能管理命令

查看技能列表

1
2
3
4
5
6
7
8
# 查看所有已安装技能
openclaw skills list

# 搜索技能
openclaw skills search weather

# 查看技能详情
openclaw skills show weather

安装/卸载技能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 安装技能,原生内置命令
openclaw skills install weather

# 安装技能,独立包管理器,weather 是 skills 名称
npx clawhub@latest install weather

# clawhub 安装
clawhub install weather

# 从指定来源安装
openclaw skills install weather --source github

# 指定版本安装
openclaw skills install weather@1.2.0

# 卸载技能
openclaw skills uninstall weather

更新技能

1
2
3
4
5
6
7
8
# 更新所有技能
openclaw skills update

# 更新特定技能
openclaw skills update weather

# 同步技能
openclaw skills sync

技能开发

1
2
3
4
5
6
7
8
# 创建新技能
openclaw skills create my-skill

# 验证技能
openclaw skills validate my-skill

# 打包技能
openclaw skills pack my-skill

第六部分:模型配置命令

查看模型

1
2
3
4
5
6
7
8
9
10
11
# 查看所有配置的模型
openclaw models list

# 查看默认模型
openclaw models default

# 查看模型详情(Mistral)
openclaw models show mistral:mixtral-8x7b

# 查看模型详情(OpenAI)
openclaw models show openai:gpt-4

配置模型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 设置默认模型(Mistral)
openclaw models set-default mistral:mixtral-8x7b

# 设置默认模型(OpenAI)
openclaw models set-default openai:gpt-4

# 添加新模型(Mistral)
openclaw models add \
--name my-mistral-model \
--provider mistral \
--id mistral-medium \
--maxTokens 8192

# 添加新模型(OpenAI)
openclaw models add \
--name my-gpt4 \
--provider openai \
--id gpt-4 \
--maxTokens 8192

# 测试模型(Mistral)
openclaw models test \
--model mistral:mixtral-8x7b \
--prompt "Hello, OpenClaw!"

# 测试模型(OpenAI)
openclaw models test \
--model openai:gpt-4 \
--prompt "Hello, OpenClaw!"

模型切换

1
2
3
4
5
6
7
8
9
10
11
12
13
# 临时指定模型(Mistral)
openclaw agent \
--model mistral:mistral-7b \
--message "快速响应"

# 临时指定模型(OpenAI)
openclaw agent \
--model openai:gpt-4 \
--message "我需要一个准确的回答"

# 使用内置模型别名
openclaw agent --model fast --message "这个用fast模型"
openclaw agent --model premium --message "这个用premium模型"

第七部分:频道管理命令

查看频道

1
2
3
4
5
6
7
8
# 查看所有配置的频道
openclaw channels list

# 查看频道状态
openclaw channels status

# 查看特定频道详情
openclaw channels show telegram

登录频道

1
2
3
4
5
6
7
8
9
10
11
# Telegram 登录
openclaw channels login --channel telegram

# WhatsApp 登录(会显示 QR 码)
openclaw channels login --channel whatsapp --verbose

# Slack 登录
openclaw channels login --channel slack

# Discord 登录
openclaw channels login --channel discord

频道测试

1
2
3
4
5
6
7
8
# 测试频道连接
openclaw channels test --channel telegram

# 发送测试消息
openclaw channels test \
--channel telegram \
--target @mychat \
--message "测试消息"

频道配置

1
2
3
4
5
6
7
8
9
10
11
# 配置频道
openclaw channels configure --channel telegram

# 更新频道 Token
openclaw channels update \
--channel telegram \
--token NEW_TOKEN

# 启用/禁用频道
openclaw channels enable telegram
openclaw channels disable telegram

第八部分:会话管理命令

查看会话

1
2
3
4
5
6
7
8
9
10
11
# 列出所有会话
openclaw sessions

# 列出活跃会话
openclaw sessions --active

# 列出特定频道的会话
openclaw sessions --channel telegram

# 显示最近 10 个会话
openclaw sessions --limit 10

查看会话历史

1
2
3
4
5
6
7
8
# 查看特定会话的历史
openclaw sessions history <session-key>

# 查看最近的消息
openclaw sessions history <session-key> --limit 20

# 导出会话历史
openclaw sessions history <session-key> --export > history.json

会话操作

1
2
3
4
5
6
7
8
9
10
# 发送消息到会话
openclaw sessions send \
--session <session-key> \
--message "你好"

# 重置会话
openclaw sessions reset <session-key>

# 删除会话
openclaw sessions delete <session-key>

第九部分:节点管理命令(智能家居控制)

查看节点

1
2
3
4
5
6
7
8
# 查看所有配对的节点
openclaw nodes list

# 查看节点状态
openclaw nodes status

# 描述节点详情
openclaw nodes describe <node-id>

节点操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 发送通知到节点
openclaw nodes notify \
--node my-phone \
--title "提醒" \
--body "该吃饭了"

# 设置推送优先级
openclaw nodes notify \
--node my-phone \
--priority timeSensitive \
--title "紧急通知" \
--body "快递到了"

# 查看相册(手机)
openclaw nodes camera-list --node my-phone

# 拍照
openclaw nodes camera-snap \
--node my-phone \
--facing back \
--output /tmp/photo.jpg

节点配对

1
2
3
4
5
6
7
8
9
10
11
# 启动配对
openclaw node pairing start

# 查看待配对节点
openclaw nodes pending

# 批准配对
openclaw nodes approve --node <node-id>

# 拒绝配对
openclaw nodes reject --node <node-id>

第十部分:记忆管理命令

搜索记忆

1
2
3
4
5
6
7
8
9
10
11
# 搜索记忆
openclaw memory search "OpenClaw 配置"

# 搜索并显示多行上下文
openclaw memory search "配置" --lines 5

# 搜索特定路径的记忆
openclaw memory search "配置" --path MEMORY.md

# 限制结果数量
openclaw memory search "配置" --maxResults 10

记忆操作

1
2
3
4
5
6
7
8
# 查看记忆统计
openclaw memory stats

# 清理过期记忆
openclaw memory clean

# 备份记忆
openclaw memory backup --output /tmp/memory-backup.json

第十一部分:Cron 定时任务命令

查看 Cron 任务

1
2
3
4
5
6
7
8
# 列出所有任务
openclaw cron list

# 查看任务运行历史
openclaw cron runs <job-id>

# 查看调度器状态
openclaw cron status

创建 Cron 任务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 创建定时任务(每天凌晨触发)
openclaw cron add \
--name "daily-report" \
--schedule "0 0 * * *" \
--text "生成每日报告"

# 创建重复任务(每 30 分钟)
openclaw cron add \
--name "check-notifications" \
--schedule "*/30 * * * *" \
--text "检查通知"

# 创建单次任务(特定时间)
openclaw cron add \
--name "special-task" \
--schedule "at" \
--at "2026-03-01T10:00:00" \
--text "执行特殊任务"

Cron 任务操作

1
2
3
4
5
6
7
8
9
10
11
# 立即运行任务
openclaw cron run <job-id>

# 更新任务
openclaw cron update <job-id> --schedule "0 6 * * *"

# 删除任务
openclaw cron remove <job-id>

# 发送唤醒事件
openclaw cron wake --text "检查新消息"

第十二部分:系统命令

健康检查

1
2
3
4
5
6
7
8
9
# 运行健康检查
openclaw doctor

# 快速修复常见问题
openclaw doctor --fix

# 检查特定组件
openclaw doctor --check gateway
openclaw doctor --check channels

系统状态

1
2
3
4
5
6
7
8
# 查看健康状态
openclaw status

# 查看系统事件
openclaw system events

# 查看心跳状态
openclaw system heartbeat

安全检查

1
2
3
4
5
6
7
8
# 运行安全检查
openclaw security audit

# 检查权限配置
openclaw security check-permissions

# 检查 API Key 有效性
openclaw security verify-keys

第十三部分:插件管理命令

查看插件

1
2
3
4
5
6
7
8
# 查看已安装插件
openclaw plugins list

# 查看插件详情
openclaw plugins show <plugin-name>

# 检查插件状态
openclaw plugins status

插件操作

1
2
3
4
5
6
7
8
9
10
11
# 启用插件
openclaw plugins enable feishu

# 禁用插件
openclaw plugins disable feishu

# 重启插件
openclaw plugins restart feishu

# 更新插件
openclaw plugins update

第十四部分:浏览器控制命令

启动/停止浏览器

1
2
3
4
5
6
7
8
9
# 启动浏览器
openclaw browser start

# 停止浏览器
openclaw browser stop

# 切换配置
openclaw browser start --profile chrome
openclaw browser start --profile openclaw

浏览器操作

1
2
3
4
5
6
7
8
9
10
11
# 打开网页
openclaw browser open https://example.com

# 截图
openclaw browser screenshot --output /tmp/screenshot.png

# 获取快照
openclaw browser snapshot --target main

# 查看标签页
openclaw browser tabs

第十五部分:更新与维护命令

更新 OpenClaw

1
2
3
4
5
6
7
8
9
10
11
# 查看更新
openclaw update --dry-run

# 执行更新
openclaw update

# 更新到特定版本
openclaw update --tag 2026.2.22

# 更新到 Beta 版
openclaw update --channel beta

配置文件管理

1
2
3
4
5
6
7
8
# 备份配置
cp ~/.openclaw/config.json ~/.openclaw/config.json.backup

# 重置配置(保留 CLI)
openclaw reset

# 完全卸载(包括数据)
openclaw uninstall

Shell 自动补全

1
2
3
4
5
6
7
8
9
# 生成 Bash 补全脚本
openclaw completion bash > ~/.openclaw-completion

# 生成 Zsh 补全脚本
openclaw completion zsh > ~/.zsh-completion

# 应用补全(Bash)
echo "source ~/.openclaw-completion" >> ~/.bashrc
source ~/.bashrc

第十六部分:常用组合命令

快速部署新技能

1
2
3
4
# 一键创建、开发、测试技能
openclaw skills create my-new-skill \
&& cd ~/.openclaw/workspace/skills/my-new-skill \
&& vim SKILL.md

批量发送通知

1
2
3
4
5
6
7
8
9
# 发送到多个目标
openclaw message send --target @user1 --message "通知内容"
openclaw message send --target @user2 --message "通知内容"
openclaw message send --target @user3 --message "通知内容"

# 使用循环批量发送(需要脚本配合)
for target in user1 user2 user3; do
openclaw message send --target @$target --message "通知内容"
done

Gateway 重启 + 验证

1
2
3
4
5
# 重启并验证
openclaw gateway restart \
&& sleep 5 \
&& openclaw gateway status \
&& openclaw health

配置备份 + 更新

1
2
3
4
5
# 安全更新流程
cp ~/.openclaw/config.json ~/.openclaw/config.json.backup \
&& openclaw update --dry-run \
&& openclaw update \
&& openclaw gateway restart

每日报告生成

1
2
3
4
5
# 生成每日报告(Cron 脚本)
0 9 * * * openclaw cron add \
--name daily-report \
--schedule "0 9 * * *" \
--text "生成昨日数据分析报告"

第十七部分:故障排除命令

Gateway 无法启动

1
2
3
4
5
6
7
8
9
10
11
# 检查端口占用
sudo lsof -i :18789

# 强制重启
openclaw gateway start --force

# 查看错误日志
openclaw logs --filter error

# 运行健康检查
openclaw doctor

消息发送失败

1
2
3
4
5
6
7
8
9
10
11
# 检查频道状态
openclaw channels status

# 测试频道
openclaw channels test --channel telegram

# 重新登录频道
openclaw channels login --channel telegram

# 查看详细日志
openclaw message send --target @mychat --message "Test" --verbose

模型调用失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 检查 API Key(OpenAI)
openclaw config get providers.openai.apiKey

# 检查 API Key(Mistral)
openclaw config get providers.mistral.apiKey

# 测试模型(OpenAI)
openclaw models test --model openai:gpt-4 --prompt "test"

# 测试模型(Mistral)
openclaw models test --model mistral:mixtral-8x7b --prompt "test"

# 检查网络连接(OpenAI)
ping api.openai.com

# 检查网络连接(Mistral)
ping api.mistral.ai

# 运行诊断
openclaw doctor --check models

技能加载失败

1
2
3
4
5
6
7
8
9
10
11
12
# 检查技能列表
openclaw skills list

# 验证技能
openclaw skills validate my-skill

# 重新安装技能
openclaw skills uninstall my-skill
openclaw skills install my-skill

# 查看错误日志
openclaw logs --filter skill

第十八部分:生产环境最佳实践

使用环境变量

1
2
3
4
5
6
7
# 推荐方式:使用环境变量存储敏感信息
export OPENAI_API_KEY="sk-xxx"
export MISTRAL_API_KEY="xxx"
export TELEGRAM_BOT_TOKEN="xxx"

# 然后启动 Gateway
openclaw gateway start

配置文件权限

1
2
3
4
5
# 限制配置文件权限
chmod 600 ~/.openclaw/config.json

# 检查权限
ls -la ~/.openclaw/config.json

日志管理

1
2
3
4
5
6
7
8
9
10
# 配置日志轮转
sudo tee /etc/logrotate.d/openclaw <<EOF
~/.openclaw/logs/*.log {
daily
rotate 7
compress
missingok
notifempty
}
EOF

监控与告警

1
2
3
# 检查 Gateway 状态(Cron 脚本)
*/5 * * * * openclaw health || \
openclaw message send --target @admin --message "Gateway 宕机!"

第十九部分:快捷别名配置

创建常用别名

1
2
3
4
5
6
7
8
9
10
11
# 添加到 ~/.bashrc 或 ~/.zshrc
alias oc='openclaw'
alias ocg='openclaw gateway'
alias ocgl='openclaw logs --follow'
alias ocs='openclaw sessions'
alias ocm='openclaw message send'
alias occ='openclaw channels'

# 应用别名
source ~/.bashrc # Bash
source ~/.zshrc # Zsh

使用别名

1
2
3
4
5
6
7
8
9
10
11
# 启动 Gateway
ocg start

# 查看实时日志
ocgl

# 发送消息
ocm --target @mychat --message "Hello"

# 查看会话
ocs

参考

https://docs.openclaw.ai/zh-CN/cli