Skip to content

OpenClaw常用命令说明

OpenClaw 常用命令说明

本文档整理了 OpenClaw CLI 的常用命令,包括命令格式、参数说明和使用示例。

目录


Gateway 控制命令

Gateway 是 OpenClaw 的核心服务,提供 WebSocket 连接和消息路由功能。

gateway start

启动 Gateway 服务(后台运行,使用 launchd/systemd/schtasks)。

命令格式:

bash
openclaw gateway start [options]

参数说明:

参数说明
--port <port>指定 Gateway WebSocket 端口
--force强制启动,终止占用端口的进程
--dev使用开发模式配置
--verbose启用详细日志输出

使用示例:

bash
# 启动 Gateway 服务
openclaw gateway start

# 强制启动并指定端口
openclaw gateway start --force --port 19001

# 开发模式启动
openclaw gateway start --dev

gateway stop

停止 Gateway 服务。

命令格式:

bash
openclaw gateway stop [options]

使用示例:

bash
# 停止 Gateway 服务
openclaw gateway stop

gateway restart

重启 Gateway 服务。

命令格式:

bash
openclaw gateway restart [options]

使用示例:

bash
# 重启 Gateway 服务
openclaw gateway restart

# 强制重启
openclaw gateway restart --force

gateway status

查看 Gateway 服务状态和健康检查。

命令格式:

bash
openclaw gateway status [options]

使用示例:

bash
# 查看 Gateway 状态
openclaw gateway status

# 查看详细状态
openclaw gateway status --verbose

gateway run

以前台模式运行 Gateway(用于调试或手动运行)。

命令格式:

bash
openclaw gateway run [options]

常用参数:

参数说明
--port <port>WebSocket 端口,默认 18789
--bind <mode>绑定模式:loopback/lan/tailnet/auto/custom
--auth <mode>认证模式:token 或 password
--token <token>连接认证令牌
--verbose详细日志输出
--compact紧凑的 WebSocket 日志格式
--force终止占用端口的进程后启动

使用示例:

bash
# 前台运行 Gateway
openclaw gateway run

# 指定端口并启用详细日志
openclaw gateway run --port 19001 --verbose

# 强制运行(终止占用端口的进程)
openclaw gateway run --force

# 开发模式运行
openclaw gateway --dev

gateway health

获取 Gateway 健康状态。

命令格式:

bash
openclaw gateway health

gateway probe

探测 Gateway 可达性和状态摘要。

命令格式:

bash
openclaw gateway probe

Agent 管理命令

Agent 是 OpenClaw 的智能代理实例,可以独立运行和管理。

agent

运行单个 Agent 交互回合。

命令格式:

bash
openclaw agent [options]

常用参数:

参数说明
--to <target>目标接收者(电话号码或用户ID)
--message <text>要发送的消息内容
--deliver发送回复到指定渠道
--local使用嵌入式模式运行
--json以 JSON 格式输出结果

使用示例:

bash
# 向 Agent 发送消息
openclaw agent --to +15555550123 --message "生成今日报告"

# 运行 Agent 并发送回复到 WhatsApp
openclaw agent --to +15555550123 --message "运行摘要" --deliver

# 本地模式运行
openclaw agent --local

agents

管理多个独立的 Agent 实例(工作空间、认证和路由)。

命令格式:

bash
openclaw agents <command> [options]

子命令:

命令说明
list列出所有 Agent
add添加新的 Agent
remove移除 Agent
show显示 Agent 详情

使用示例:

bash
# 列出所有 Agent
openclaw agents list

# 添加新 Agent
openclaw agents add --name my-agent

# 显示 Agent 详情
openclaw agents show my-agent

消息发送命令

通过配置的渠道发送消息。

message send

发送消息到指定目标。

命令格式:

bash
openclaw message send [options]

常用参数:

参数说明
--target <target>目标接收者(电话号码、用户名或群组ID)
--message <text>消息内容
--channel <name>使用的渠道(whatsapp, telegram 等)
--json以 JSON 格式输出结果
--file <path>附加文件路径

使用示例:

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

# 发送 Telegram 消息
openclaw message send --channel telegram --target @mychat --message "Hi"

# 发送消息并输出 JSON 结果
openclaw message send --target +15555550123 --message "Hi" --json

# 发送带附件的消息
openclaw message send --target +15555550123 --message "请查收文件" --file ./report.pdf

渠道管理命令

管理消息渠道的登录和配置。

channels login

登录消息渠道。

命令格式:

bash
openclaw channels login [options]

常用参数:

参数说明
--verbose显示详细的连接日志和二维码
--channel <name>指定要登录的渠道

使用示例:

bash
# 登录 WhatsApp Web(显示二维码)
openclaw channels login --verbose

# 登录指定渠道
openclaw channels login --channel telegram --verbose

channels 其他命令

bash
# 列出所有渠道状态
openclaw channels list

# 登出渠道
openclaw channels logout --channel whatsapp

配置管理命令

管理 OpenClaw 的配置项。

config get

获取配置值。

命令格式:

bash
openclaw config get <key>

使用示例:

bash
# 获取 Gateway 模式配置
openclaw config get gateway.mode

# 获取默认模型配置
openclaw config get agents.defaults.model

config set

设置配置值。

命令格式:

bash
openclaw config set <key> <value>

使用示例:

bash
# 设置 Gateway 模式为本地模式
openclaw config set gateway.mode local

# 设置默认模型
openclaw config set agents.defaults.model claude-3-sonnet

config unset

删除配置项。

命令格式:

bash
openclaw config unset <key>

使用示例:

bash
# 删除配置项
openclaw config unset gateway.mode

config(交互式配置向导)

不带参数运行 config 命令会启动交互式配置向导。

命令格式:

bash
openclaw config

健康检查命令

doctor

运行健康检查和快速修复工具。

命令格式:

bash
openclaw doctor [options]

常用参数:

参数说明
--fix自动修复发现的问题
--verbose显示详细信息

使用示例:

bash
# 运行健康检查
openclaw doctor

# 运行检查并自动修复问题
openclaw doctor --fix

# 详细模式检查
openclaw doctor --verbose

其他常用命令

status

显示渠道健康状态和最近会话接收者。

命令格式:

bash
openclaw status [options]

使用示例:

bash
# 查看整体状态
openclaw status

# 查看详细状态
openclaw status --verbose

onboard

交互式向导,用于设置 Gateway、工作空间和技能。

命令格式:

bash
openclaw onboard [options]

使用示例:

bash
# 启动设置向导
openclaw onboard

setup

初始化 OpenClaw 配置文件和工作空间。

命令格式:

bash
openclaw setup [options]

使用示例:

bash
# 初始化配置
openclaw setup

# 开发模式初始化
openclaw setup --dev

configure

交互式配置向导,设置凭证、设备和 Agent 默认值。

命令格式:

bash
openclaw configure

reset

重置本地配置和状态(保留 CLI 安装)。

命令格式:

bash
openclaw reset [options]

使用示例:

bash
# 重置配置
openclaw reset

uninstall

卸载 Gateway 服务和本地数据(CLI 保留)。

命令格式:

bash
openclaw uninstall

全局选项

以下选项适用于所有命令:

选项说明
--dev使用开发配置(隔离状态到 ~/.openclaw-dev)
--profile <name>使用命名配置文件(隔离到 ~/.openclaw-)
--no-color禁用 ANSI 颜色输出
-h, --help显示命令帮助信息
-V, --version显示版本号

使用示例:

bash
# 使用开发模式
openclaw --dev gateway start

# 使用命名配置文件
openclaw --profile work gateway start

# 查看命令帮助
openclaw gateway --help

常见工作流程

初始化 OpenClaw

bash
# 首次设置
openclaw setup
openclaw onboard

# 配置凭证
openclaw configure

启动和使用 Gateway

bash
# 启动 Gateway
openclaw gateway start

# 检查状态
openclaw gateway status

# 登录消息渠道
openclaw channels login --verbose

# 发送消息
openclaw message send --target +15555550123 --message "Hello!"

故障排查

bash
# 运行健康检查
openclaw doctor

# 查看日志
openclaw logs

# 查看 Gateway 状态
openclaw gateway status --verbose

参考文档

官方文档:https://docs.openclaw.ai/cli


文档版本:2026.2.12