引言 本文是 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 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 openclaw config set providers.openai.apiKey YOUR_OPENAI_API_KEY_HERE 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 openclaw gateway start openclaw gateway start --port 19000 openclaw gateway start --force openclaw gateway stop openclaw gateway restart openclaw gateway status
运行时 Gateway 1 2 3 4 5 6 7 8 openclaw gateway openclaw --dev gateway openclaw health
查看日志 1 2 3 4 5 6 7 8 9 10 11 openclaw logs openclaw logs --lines 50 openclaw logs --filter error openclaw logs --follow
系统服务管理 1 2 3 4 5 6 7 8 sudo systemctl start openclaw-gatewaysudo systemctl stop openclaw-gatewaysudo systemctl restart openclaw-gatewaysudo systemctl status openclaw-gatewaysudo 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" openclaw message send \ --channel telegram \ --target @mychat \ --message "Hello from OpenClaw" openclaw message send \ --channel whatsapp \ --target +8613012345678 \ --message "你好" 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 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 openclaw message send \ --channel telegram \ --target @mychat \ --pollQuestion "OpenClaw 好用吗?" \ --pollOption 非常好用 \ --pollOption 一般 \ --pollOption 还需要改进 \ --pollDurationHours 24 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 npx clawhub@latest install weather 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 openclaw models show mistral:mixtral-8x7b 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 openclaw models set-default mistral:mixtral-8x7b openclaw models set-default openai:gpt-4 openclaw models add \ --name my-mistral-model \ --provider mistral \ --id mistral-medium \ --maxTokens 8192 openclaw models add \ --name my-gpt4 \ --provider openai \ --id gpt-4 \ --maxTokens 8192 openclaw models test \ --model mistral:mixtral-8x7b \ --prompt "Hello, OpenClaw!" openclaw models test \ --model openai:gpt-4 \ --prompt "Hello, OpenClaw!"
模型切换 1 2 3 4 5 6 7 8 9 10 11 12 13 openclaw agent \ --model mistral:mistral-7b \ --message "快速响应" 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 openclaw channels login --channel telegram openclaw channels login --channel whatsapp --verbose openclaw channels login --channel slack 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 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 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 "生成每日报告" 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 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 openclaw update --channel beta
配置文件管理 1 2 3 4 5 6 7 8 cp ~/.openclaw/config.json ~/.openclaw/config.json.backupopenclaw reset openclaw uninstall
Shell 自动补全 1 2 3 4 5 6 7 8 9 openclaw completion bash > ~/.openclaw-completion openclaw completion zsh > ~/.zsh-completion echo "source ~/.openclaw-completion" >> ~/.bashrcsource ~/.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 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 :18789openclaw 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 openclaw config get providers.openai.apiKey openclaw config get providers.mistral.apiKey openclaw models test --model openai:gpt-4 --prompt "test" openclaw models test --model mistral:mixtral-8x7b --prompt "test" ping api.openai.com 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" openclaw gateway start
配置文件权限 1 2 3 4 5 chmod 600 ~/.openclaw/config.jsonls -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 */5 * * * * openclaw health || \ openclaw message send --target @admin --message "Gateway 宕机!"
第十九部分:快捷别名配置 创建常用别名 1 2 3 4 5 6 7 8 9 10 11 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 source ~/.zshrc
使用别名 1 2 3 4 5 6 7 8 9 10 11 ocg start ocgl ocm --target @mychat --message "Hello" ocs
参考 https://docs.openclaw.ai/zh-CN/cli