一句话总结:OpenClaw 是一个强大的 AI 智能体平台,通过 CLI 命令可以管理 Gateway 服务、配置聊天频道、运行智能体任务、控制浏览器自动化等。本文将详细介绍每个核心命令的使用方式和实际应用场景。
一、OpenClaw 是什么?
OpenClaw 是一个开源的 AI 智能体(Agent)平台,让你能够在本地或远程运行 AI 智能体,并通过多种聊天频道(Telegram、WhatsApp、Discord、飞书等)与智能体交互。它提供了丰富的 CLI 命令来管理整个系统。
核心优势:
🔒 本地优先:数据不离开你的机器 🤖 多模型支持:Claude、GPT、Gemini 等 📱 多频道支持:20+ 聊天平台 🛠️ 丰富的工具生态:浏览器、代码执行、文件操作等
二、核心命令分类速览
| 系统管理 | gatewaystatus, doctor | |
| 频道配置 | channelsmessage | |
| 智能体 | agentagents | |
| 模型管理 | models | |
| 自动化 | browsercron | |
| 开发工具 | skillsconfig |
三、系统管理命令
1. openclaw gateway - Gateway 服务管理
Gateway 是 OpenClaw 的核心服务,负责处理所有 AI 请求和频道连接。
常用子命令:
# 前台运行 Gateway(开发调试时常用)openclaw gateway run# 后台启动服务openclaw gateway start# 停止服务openclaw gateway stop# 重启服务openclaw gateway restart# 查看服务状态openclaw gateway status# 安装为系统服务(开机自启)openclaw gateway install
常用选项:
# 指定端口运行openclaw gateway run --port 18789# 开发模式(隔离配置)openclaw gateway run --dev# 强制启动(杀死占用端口的进程)openclaw gateway run --force# Tailscale 暴露(远程访问)openclaw gateway run --tailscale serve
使用场景:
🏠 本地开发:使用 gateway run前台运行,方便查看日志🚀 生产部署:使用 gateway install安装为系统服务🔧 故障排查: gateway status检查服务健康状态🌐 远程访问:配合 --tailscale serve实现安全远程连接
2. openclaw status - 系统状态检查
快速查看 OpenClaw 的整体健康状态。
# 基础状态检查openclaw status# 深度检查(包含频道探测)openclaw status --deep# 查看模型使用情况openclaw status --usage# JSON 格式输出(用于脚本)openclaw status --json
输出示例:
Gateway: ✅ Running (ws://127.0.0.1:18789)Channels: 3 connected (telegram, discord, feishu)Models: Claude 3.5 Sonnet (active)Health: All systems operational
使用场景:
📊 日常检查:快速确认系统是否正常运行 🔍 故障排查: --deep模式检查频道连接状态💰 用量监控: --usage查看 API 调用量和配额
3. openclaw doctor - 健康诊断与修复
自动检测并修复常见问题。
# 运行诊断openclaw doctor# 自动修复问题openclaw doctor --fix# 深度扫描(检查系统服务)openclaw doctor --deep# 非交互模式(CI/CD 使用)openclaw doctor --non-interactive --yes
使用场景:
🩺 问题排查:遇到奇怪错误时先运行 doctor 🔧 自动修复: --fix自动解决配置问题🏭 CI/CD 集成: --non-interactive模式用于自动化流程
四、频道管理命令
4. openclaw channels - 聊天频道管理
连接和管理各种聊天平台。
常用子命令:
# 列出已配置的频道openclaw channels list# 查看频道状态openclaw channels status# 添加 Telegram 机器人openclaw channels add --channel telegram --token "YOUR_BOT_TOKEN"# 添加 Discord 机器人openclaw channels add --channel discord --token "YOUR_BOT_TOKEN"# 登录 WhatsApp(扫码登录)openclaw channels login --channel whatsapp# 移除频道openclaw channels remove --channel telegram --account default --delete
使用场景:
🤖 机器人部署:添加 Telegram/Discord 机器人 📱 个人使用:连接 WhatsApp 个人账号 👥 团队协作:配置飞书、Slack 等办公平台
5. openclaw message - 消息发送与管理
通过命令行发送消息和进行频道操作。
常用子命令:
# 发送文本消息openclaw message send --target "+86138xxxxxxxx" --message "Hello World"# 发送图片openclaw message send --target "@username" --message "Check this out" --media photo.jpg# 创建投票(Discord)openclaw message poll --channel discord --target "channel:123" \--poll-question "今晚吃什么?" \--poll-option "火锅" \--poll-option "烧烤"# 添加表情反应openclaw message react --channel discord --target 123 --message-id 456 --emoji "✅"# 读取最近消息openclaw message read --channel telegram --target "@channel" --limit 10
使用场景:
📢 消息推送:从脚本发送通知 🤖 自动化回复:配合 cron 定时发送报告 📊 交互功能:创建投票、收集反馈
五、智能体命令
6. openclaw agent - 运行 AI 智能体
直接与 AI 智能体交互。
# 基础对话openclaw agent --message "你好,请介绍一下 OpenClaw"# 指定目标发送回复openclaw agent --to "+86138xxxxxxxx" --message "总结今天的邮件" --deliver# 使用特定智能体openclaw agent --agent ops --message "检查服务器状态"# 调整思考深度openclaw agent --message "分析这个代码问题" --thinking high# 本地模式运行(不经过 Gateway)openclaw agent --message "Hello" --local# JSON 输出(用于脚本处理)openclaw agent --message "生成报告" --json
选项说明:---thinking:控制AI思考深度(off/minimal/low/medium/high/xhigh)---deliver:将回复发送到指定频道---local:本地运行,需要配置 API key---verbose:显示详细日志
使用场景:
💬 快速提问:命令行直接询问 AI 🔧 运维任务:让智能体检查系统状态 📧 自动回复:结合 --deliver实现自动客服
7. openclaw agents - 智能体管理
管理多个独立的智能体。
# 列出所有智能体openclaw agents list# 添加新智能体openclaw agents add --name "ops" --workspace ~/agents/ops# 绑定频道openclaw agents bind --agent ops --bind telegram:alerts# 删除智能体openclaw agents delete ops --force
使用场景:
🏢 多团队管理:不同团队使用不同智能体 🎯 角色分离:运维、客服、开发等角色分离 🔒 权限隔离:不同智能体访问不同资源
六、模型管理命令
8. openclaw models - AI 模型配置
管理 AI 模型和认证信息。
# 查看模型状态openclaw models status# 列出可用模型openclaw models list# 设置默认模型openclaw models set "claude-3-5-sonnet-20241022"# 设置图像模型openclaw models set-image "gemini-2.0-flash-exp"# 扫描可用模型openclaw models scan# 添加认证openclaw models auth add --provider anthropic# 管理模型别名openclaw models aliases add fast "gpt-4o-mini"
使用场景:
🔄 模型切换:快速切换不同 AI 模型 🔑 认证管理:配置 API key 📊 用量监控:查看配额和调用量
七、自动化命令
9. openclaw browser - 浏览器自动化
控制 Chrome/Chromium 浏览器进行自动化操作。
常用子命令:
# 启动浏览器openclaw browser start# 打开网页openclaw browser open https://example.com# 截图openclaw browser screenshotopenclaw browser screenshot --full-page# 获取页面快照openclaw browser snapshot# 页面导航openclaw browser navigate https://example.com# 调整窗口大小openclaw browser resize 1280 720# 点击元素openclaw browser click 12# 输入文本openclaw browser type 23 "hello" --submit# 按下按键openclaw browser press Enter# 执行 JavaScriptopenclaw browser evaluate --fn 'document.title'# 导出 PDFopenclaw browser pdf
使用场景:
📸 网页截图:自动化生成网页预览 🤖 网页自动化:自动填写表单、点击按钮 🔍 数据抓取:配合 snapshot 提取页面信息 📄 报告生成:导出网页为 PDF
10. openclaw cron - 定时任务管理
设置自动化定时任务。
# 查看定时任务列表openclaw cron list# 添加每小时执行的任务openclaw cron add --name "hourly-report" \--every "1h" \--message "生成每小时报告"# 添加定时任务(每天 9 点)openclaw cron add --name "morning-brief" \--cron "0 9 * * *" \--message "发送晨会简报"# 添加单次任务openclaw cron add --name "reminder" \--at "2024-12-25 09:00" \--message "圣诞节提醒"# 启用/禁用任务openclaw cron enable hourly-reportopenclaw cron disable hourly-report# 删除任务openclaw cron rm hourly-report# 立即运行任务(调试)openclaw cron run hourly-report# 查看执行历史openclaw cron runs --id hourly-report
使用场景:
📊 定时报告:每天/每周自动生成报告 🔔 定时提醒:重要事项自动提醒 🔄 数据同步:定时同步数据 🤖 自动运维:定时执行系统检查
八、开发工具命令
11. openclaw skills - 技能管理
查看和管理 OpenClaw 技能。
# 列出所有技能openclaw skills list# 查看技能详情openclaw skills info github# 检查技能就绪状态openclaw skills check# 只显示就绪的技能openclaw skills list --eligible
使用场景:
📚 技能发现:查看系统有哪些可用技能 ✅ 依赖检查:确认技能依赖是否满足 🔍 技能详情:了解某个技能的具体功能
12. openclaw config - 配置管理
非交互式配置管理。
# 查看配置路径openclaw config file# 获取配置值openclaw config get "agents.defaults.model.primary"# 设置配置值openclaw config set "agents.defaults.model.primary" "claude-3-5-sonnet"# 删除配置项openclaw config unset "agents.defaults.model.primary"# 验证配置openclaw config validate
使用场景:
⚙️ 脚本配置:自动化部署时设置配置 🔧 批量修改:批量调整配置项 ✅ 配置验证:提交前验证配置正确性
九、其他实用命令
13. openclaw memory - 记忆搜索
语义搜索本地记忆文件。
# 查看记忆索引状态openclaw memory status# 重新索引记忆文件openclaw memory index# 搜索记忆openclaw memory search "OpenClaw 配置"
使用场景:
🔍 信息查找:快速找到之前记录的信息 🧠 知识管理:整理和检索个人知识库
14. openclaw sessions - 会话管理
查看和管理对话会话。
# 列出会话openclaw sessions list# 查看活跃会话openclaw sessions list --active 60# JSON 输出openclaw sessions list --json
使用场景:
📋 会话追踪:查看历史对话记录 🧹 清理管理:识别长期未用的会话
15. openclaw logs - 日志查看
查看 Gateway 日志。
# 查看最近日志openclaw logs# 实时跟踪日志openclaw logs --follow# 限制行数openclaw logs --limit 100# JSON 格式openclaw logs --json
使用场景:
🐛 故障排查:查看错误日志定位问题 📊 监控运行:实时跟踪系统运行状态
十、实用技巧与最佳实践
1. 开发模式使用
# 开发调试时使用 --dev 隔离配置openclaw --dev gateway runopenclaw --dev agent --message "测试"
2. 配置文件管理
# 使用配置文件管理多个环境openclaw --profile work gateway statusopenclaw --profile personal agent --message "Hi"
3. 脚本自动化示例
#!/bin/bash# daily-report.sh - 每日报告自动化# 检查服务状态if ! openclaw health --json > /dev/null; thenecho "Gateway 未运行,正在启动..."openclaw gateway startsleep 5fi# 生成报告并发送到 Telegramopenclaw agent --message "生成今日数据报告" --deliver --reply-channel telegram --reply-to "@mychannel"
4. 快捷别名配置
在 ~/.zshrc 或 ~/.bashrc 中添加:
# OpenClaw 快捷命令alias oc='openclaw'alias ocs='openclaw status'alias ocg='openclaw gateway'alias oca='openclaw agent'alias ocb='openclaw browser'
十一、常见问题 FAQ
Q: Gateway 启动失败怎么办?
# 1. 检查端口占用openclaw gateway run --force# 2. 运行诊断openclaw doctor --fix# 3. 重置配置(谨慎使用)openclaw reset --scope config
Q: 如何查看详细的命令帮助?
openclaw <command> --helpopenclaw <command> <subcommand> --help# 例如:openclaw browser screenshot --help
Q: 如何调试频道连接问题?
# 深度检查频道状态openclaw status --deep# 查看频道日志openclaw channels logs --channel telegram --lines 50
Q: 如何备份和恢复配置?
# 创建备份openclaw backup create# 验证备份openclaw backup verify
十二、总结
OpenClaw 的 CLI 命令设计遵循以下原则:
1.一致性:所有命令遵循相似的语法结构2.可组合:命令可以组合使用,支持管道和脚本3.自文档:--help 提供详细的帮助信息4.安全优先:敏感操作需要确认,支持 --dry-run
推荐学习路径:
先掌握 gateway、status、doctor三个系统管理命令然后学习 channels和message进行频道配置熟练使用 agent与 AI 交互最后探索 browser、cron等高级自动化功能
相关资源:
📖 官方文档:https://docs.openclaw.ai 💬 社区 Discord:https://discord.com/invite/clawd 🐙 GitHub:https://github.com/openclaw/openclaw
夜雨聆风