Skip to content

CLI 命令参考

本文档提供 OpenClaw 命令行工具的完整参考。

Terminal window
# 最常用命令
openclaw onboard # 启动配置向导
openclaw gateway # 启动网关服务
openclaw dashboard # 打开控制面板
openclaw doctor # 诊断问题

启动交互式配置向导。

Terminal window
openclaw onboard [选项]
选项:
--install-daemon 安装系统服务
--config <path> 使用指定配置文件
--yes 自动确认所有选项
--verbose 显示详细日志

管理网关服务。

Terminal window
# 启动网关
openclaw gateway [选项]
选项:
--port <port> 指定端口(默认18789)
--host <host> 绑定地址(默认127.0.0.1)
--daemon 后台运行
--verbose 详细日志
--dev 开发模式
--force 强制启动(终止占用端口的进程)
# 停止网关
openclaw gateway stop
# 重启网关
openclaw gateway restart
# 查看状态
openclaw gateway status

打开浏览器控制界面。

Terminal window
openclaw dashboard [选项]
选项:
--port <port> 指定端口
--browser <name> 指定浏览器(chrome/firefox/safari)
Terminal window
# 查看配置
openclaw config get [key]
# 设置配置项
openclaw config set <key> <value>
# 删除配置项
openclaw config delete <key>
# 验证配置
openclaw config validate
# 编辑配置文件
openclaw config edit
# 查看配置路径
openclaw config path
# 导出配置
openclaw config export [path]
# 导入配置
openclaw config import <path>

示例:

Terminal window
# 设置 WhatsApp 频道
openclaw config set channels.whatsapp.enabled true
# 设置代理模型
openclaw config set agents.default.model claude-3.5-sonnet
# 验证配置
openclaw config validate
Terminal window
# 列出所有频道
openclaw channels list
# 查看频道状态
openclaw channels status
# 登录/连接频道
openclaw channels login <platform>
# platform: whatsapp, telegram, discord
# 重新连接频道
openclaw channels reconnect <platform>
# 断开频道连接
openclaw channels disconnect <platform>
# 测试频道连接
openclaw channels test <platform>
# 查看频道日志
openclaw channels logs <platform>

示例:

Terminal window
# WhatsApp 登录(显示二维码)
openclaw channels login whatsapp
# 检查 Telegram 状态
openclaw channels status telegram
# 重新连接 Discord
openclaw channels reconnect discord
Terminal window
# 发送消息
openclaw message send [选项]
选项:
--target <id> 目标用户ID
--platform <name> 平台(whatsapp/telegram/discord)
--message <text> 消息内容
--file <path> 附件文件
# 发送测试消息
openclaw message test
# 查看消息历史
openclaw message history [选项]
--session <id> 指定会话
--limit <n> 限制条数

示例:

Terminal window
# 发送私信
openclaw message send \
--target "+8613800138000" \
--platform whatsapp \
--message "你好!"
# 发送带附件的消息
openclaw message send \
--target "@username" \
--platform telegram \
--message "查看这个文件" \
--file document.pdf
Terminal window
# 列出所有代理
openclaw agent list
# 查看代理状态
openclaw agent status [agent-id]
# 切换代理
openclaw agent switch <agent-id>
# 重新加载代理
openclaw agent reload [agent-id]
# 测试代理
openclaw agent test [agent-id]
Terminal window
# 列出所有会话
openclaw session list [选项]
--active 仅显示活跃会话
--platform <name> 按平台筛选
# 查看会话详情
openclaw session info <session-id>
# 重置会话
openclaw session reset <session-id>
# 删除会话
openclaw session delete <session-id>
# 备份会话
openclaw session backup <session-id> [path]
# 恢复会话
openclaw session restore <path>
# 清理会话
openclaw session clean [选项]
--hibernated 清理休眠会话
--older-than <time> 清理超过指定时间的会话
--all 清理所有会话(谨慎!)
Terminal window
openclaw doctor [选项]
选项:
--fix 自动修复问题
--yes 确认修复
--verbose 详细输出
--check <type> 检查特定类型
# types: config, sessions, channels, network, storage
# 示例
openclaw doctor --check config
openclaw doctor --check network --fix
Terminal window
openclaw logs [选项]
选项:
--follow 实时跟踪
--lines <n> 显示最后n行(默认100)
--level <level> 日志级别(debug/info/warn/error)
--module <name> 模块筛选
--since <time> 从指定时间开始
--until <time> 到指定时间结束
--grep <pattern> 文本搜索
# 示例
openclaw logs --follow --level debug
openclaw logs --module gateway --lines 50
openclaw logs --since "1 hour ago" --grep "error"
Terminal window
# 列出可用工具
openclaw tools list
# 查看工具详情
openclaw tools info <tool-name>
# 测试工具
openclaw tools test <tool-name>
# 启用/禁用工具
openclaw tools enable <tool-name>
openclaw tools disable <tool-name>
Terminal window
# 安装服务
openclaw service install
# 卸载服务
openclaw service uninstall
# 启动服务
openclaw service start
# 停止服务
openclaw service stop
# 重启服务
openclaw service restart
# 查看服务状态
openclaw service status
Terminal window
# 检查更新
openclaw update check
# 执行更新
openclaw update
# 更新到指定版本
openclaw update --version <version>
# 强制重新安装
openclaw update --force

所有命令都支持以下全局选项:

Terminal window
--config <path> 指定配置文件
--verbose 详细输出
--quiet 静默模式
--json JSON格式输出
--help 显示帮助
--version 显示版本
Terminal window
# 配置文件路径
export OPENCLAW_CONFIG_PATH=~/.openclaw/openclaw.json
# 状态目录
export OPENCLAW_STATE_DIR=~/.openclaw/state
# 日志级别
export OPENCLAW_LOG_LEVEL=debug
# 跳过画布服务
export OPENCLAW_SKIP_CANVAS_HOST=1
# API密钥
export ANTHROPIC_API_KEY=your-key
export OPENAI_API_KEY=your-key
~/.openclaw/
├── openclaw.json # 主配置文件
├── state/
│ ├── sessions/ # 会话数据
│ └── cache/ # 缓存文件
├── workspace/
│ ├── canvas/ # 画布文件
│ ├── memory/ # 记忆存储
│ └── skills/ # 技能脚本
├── logs/
│ └── gateway.log # 网关日志
└── backups/ # 配置备份
Terminal window
# 1. 安装并配置
npm install -g openclaw
openclaw onboard
# 2. 启动网关
openclaw gateway --daemon
# 3. 连接 WhatsApp
openclaw channels login whatsapp
# 扫描二维码...
# 4. 发送测试消息
openclaw message test
# 5. 查看状态
openclaw gateway status
openclaw channels status
# 6. 诊断问题
openclaw doctor
# 7. 查看日志
openclaw logs --follow
Terminal window
# 网关无法启动
openclaw doctor --check network
openclaw logs --level error --lines 20
# 频道连接失败
openclaw channels disconnect whatsapp
openclaw channels login whatsapp
# 配置错误
openclaw config validate
openclaw doctor --fix
# 完全重置
openclaw service stop
rm -rf ~/.openclaw
openclaw onboard