CLAWIST.
📖 指南阅读时间 8 分钟••作者:Lin

OpenClaw CLI 命令:完整参考指南

OpenClaw CLI 命令:完整参考指南

OpenClaw's 的命令行界面是您管理 AI 助手的首要工具。从启动网关、配置渠道到设置自动化,CLI 都能完成。

本参考涵盖了每一个重要命令,并附有实用示例。请收藏本页,以便需要时快速查阅。

安装与验证

OpenClaw CLI 安装 安装 OpenClaw 并验证其是否正常运行

安装 OpenClaw:

npm install -g openclaw

验证安装:

openclaw --version
openclaw --help

初始化工作区:

cd ~/.openclaw  # Or your preferred location
openclaw init

这将创建带有默认配置文件的工作区结构。

网关命令

网关管理命令 控制 OpenClaw 网关守护进程

网关是处理所有消息和 AI 交互的核心服务。

启动网关:

openclaw gateway start

停止网关:

openclaw gateway stop

重启网关:

openclaw gateway restart

检查网关状态:

openclaw gateway status

查看网关日志:

openclaw gateway logs
openclaw gateway logs --follow  # Tail logs
openclaw gateway logs --lines 100  # Last 100 lines

渠道配置

渠道配置 将消息平台连接到 OpenClaw

列出已连接的渠道:

openclaw channels status

配置 Telegram:

openclaw config set telegram.enabled true
openclaw config set telegram.botToken "your-token"

配置 Discord:

openclaw config set discord.enabled true
openclaw config set discord.botToken "your-token"

配置 Slack:

openclaw config set slack.enabled true
openclaw config set slack.botToken "xoxb-your-token"
openclaw config set slack.signingSecret "your-secret"

测试频道连接:

openclaw channels test telegram

定时任务(Cron Jobs)

定时任务自动化 安排周期性的 AI 任务

列出所有定时任务:

openclaw cron list

添加定时任务:

openclaw cron add "job-name" "0 9 * * *" "Your prompt here"

Cron 表达式格式:

* * * * *
│ │ │ │ │
│ │ │ │ └── 星期几 (0-7,0 和 7 均为星期日)
│ │ │ └──── 月份 (1-12)
│ │ └────── 每月的日期 (1-31)
│ └──────── 小时 (0-23)
└────────── 分钟 (0-59)

常用计划:

  • 0 9 * * * - 每天上午 9 点
  • 0 9 * * 1-5 - 工作日上午 9 点
  • 0 */2 * * * - 每 2 小时
  • 0 0 1 * * - 每月 1 日

删除定时任务:

openclaw cron remove "job-name"

立即运行定时任务:

openclaw cron run "job-name"

配置管理

配置设置 管理 OpenClaw 设置

查看当前配置:

openclaw config show

获取特定设置:

openclaw config get ai.model

设置配置值:

openclaw config set ai.model "claude-sonnet-4-20250514"

常用设置:

openclaw config set ai.provider anthropic
openclaw config set ai.model claude-sonnet-4-20250514

openclaw config set anthropic.apiKey "sk-ant-..."

openclaw config set tools.browser.enabled true
openclaw config set tools.filesystem.enabled true
openclaw config set tools.exec.enabled true

openclaw config set memory.enabled true
openclaw config set memory.maxAge "30d"

重置配置:

openclaw config reset

配对与访问控制

访问控制设置 管理谁可以访问您的 AI 助手

列出待处理的配对请求:

openclaw pairing list

批准配对请求:

openclaw pairing approve telegram ABC123

拒绝配对请求:

openclaw pairing reject telegram ABC123

列出已批准的用户:

openclaw pairing approved

撤销访问权限:

openclaw pairing revoke telegram user_id

工具管理

工具配置 启用并配置 AI 工具

列出可用工具:

openclaw tools list

启用工具:

openclaw tools enable browser
openclaw tools enable gmail
openclaw tools enable exec

禁用工具:

openclaw tools disable exec

配置工具设置:

openclaw tools config browser.headless true
openclaw tools config exec.approvalMode prompt

测试工具:

openclaw tools test browser

故障排除命令

故障排查与调试 诊断并修复常见问题

检查系统健康状况:

openclaw doctor

验证 API 连接:

openclaw test api

清除会话数据:

openclaw sessions clear

恢复默认设置:

openclaw reset --soft  # Keep data, reset config
openclaw reset --hard  # Full reset (destructive)

调试模式:

openclaw gateway start --debug

导出配置:

openclaw config export > backup.json

导入配置:

openclaw config import backup.json

结语

带有 CLI 命令的终端 掌握 OpenClaw CLI,高效管理 AI 助手

本参考文档涵盖了日常使用 OpenClaw 所需的基本 CLI 命令。请将其收藏,以便在管理 AI 助手时快速查阅。

需要记住的关键命令:

  • openclaw gateway start/stop/status - 管理守护进程
  • openclaw config set/get - 配置设置
  • openclaw cron add/list/remove - 安排任务
  • openclaw channels status - 检查连接
  • openclaw doctor - 排查问题

继续学习:

掌握命令行工具,您的 AI 助手就会成为您工作流程的延伸。

常见问题

CLI 常见问题 关于命令行工具的常见问题

配置文件存储在哪里?

默认存储在 ~/.openclaw/。使用 OPENCLAW_HOME 环境变量可更改此位置。

如何更新 OpenClaw?

npm update -g openclaw
openclaw gateway restart

可以运行多个实例吗?

可以,为每个实例使用不同的工作区目录和端口即可。

如何备份我的设置?

cp -r ~/.openclaw ~/.openclaw-backup

或者使用 openclaw config export 仅备份配置。

如果命令卡住了怎么办?

使用以下命令查看网关日志 openclaw gateway logs。使用 --debug 参数可获得详细输出。