OpenClaw的常用命令大全以及使用新手指南(2026最新)
未来转换
一、OpenClaw 简介
OpenClaw 是一款开源的个人 AI 助手框架,2026 年初开源后迅速成为最受关注的 AI Agent 框架之一。与依赖 Web 界面或桌面应用的同类工具不同,OpenClaw 从设计之初就以 CLI(命令行)为主要入口,天然适合与 DevOps 工具链、Shell 脚本和自动化调度集成。
核心特性:
- 40+ 顶级命令,覆盖 Gateway、模型、频道、Skills、Hooks、Plugins 等
- 20+ 通信频道:Telegram、Discord、Slack、WhatsApp、Signal、飞书等
- 100+ 子命令,完整的终端操作能力
- 内置浏览器自动化、定时任务、语义记忆搜索
二、安装与初始化
2.1 安装
# macOS / Linux curl -fsSL https://openclaw.ai/install.sh | bash # Windows PowerShell iwr -useb https://openclaw.ai/install.ps1 | iex # Windows CMD curl -fsSL https://openclaw.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
2.2 验证安装
# 查看版本(注意:没有 openclaw version 命令,必须用 --version) openclaw --version # 输出: 2026.2.25 # 查看所有命令帮助 openclaw --help
2.3 首次初始化
# 交互式配置向导(推荐新手使用) openclaw configure # 健康检查,确认环境就绪 openclaw doctor
2.4 更新与卸载
# 更新到最新稳定版 openclaw update # 切换更新频道(stable/beta/dev) openclaw update --channel beta # 预览更新内容(不实际执行) openclaw update --dry-run # 更新后不自动重启 Gateway openclaw update --no-restart # 卸载 Gateway 服务和本地数据(CLI 保留) openclaw uninstall # 完全卸载(含配置、状态、工作空间) openclaw uninstall --all --yes # 重置本地配置(保留 CLI) openclaw reset
三、全局标志(Global Flags)
任何命令都可以附加以下全局标志:
| 标志 | 说明 |
|---|---|
--help / -h | 显示帮助信息 |
--version / -V | 显示版本号 |
--log-level <level> | 全局日志级别:silent/fatal/error/warn/info/debug/trace |
--no-color | 禁用 ANSI 颜色(适合 CI 管道) |
--dev | 使用开发环境,隔离状态到 ~/.openclaw-dev |
--profile <name> | 使用命名配置文件,隔离状态 |
四、Gateway 管理(核心服务)
Gateway 是 OpenClaw 的心脏,是一个 WebSocket 服务,负责接收消息、调度 Agent、管理会话。默认监听 ws://127.0.0.1:18789。
4.1 启动与运行
# 前台运行(Ctrl+C 停止,适合调试) openclaw gateway # 指定端口 openclaw gateway --port 18790 # 绑定模式 openclaw gateway --bind loopback # 仅本机(默认,最安全) openclaw gateway --bind lan # 局域网可访问 openclaw gateway --bind tailnet # Tailscale 网络 # 强制启动(杀掉占用端口的进程) openclaw gateway --force # 设置认证模式 openclaw gateway --auth token --token "your-secret-token" openclaw gateway --auth password --password "your-password" # Tailscale 暴露 openclaw gateway --tailscale serve # 内网暴露 openclaw gateway --tailscale funnel # 公网暴露 # 详细日志模式 openclaw gateway --verbose
4.2 服务管理(持久化)
# 安装为系统服务(launchd/systemd/schtasks) openclaw gateway install # 启动 / 停止 / 重启 openclaw gateway start openclaw gateway stop openclaw gateway restart # 卸载系统服务 openclaw gateway uninstall # 查看服务状态 openclaw gateway status
Windows 注意:openclaw gateway install 需要管理员权限(底层使用 schtasks),非管理员环境请用前台模式。
4.3 状态查询与日志
# 查看完整状态 openclaw gateway status # 健康检查 openclaw gateway health # 探测 Gateway 可达性 openclaw gateway probe # 发现局域网/广域网上的 Gateway openclaw gateway discover # 调用 Gateway RPC 方法 openclaw gateway call health # 查看用量成本 openclaw gateway usage-cost # 查看日志 openclaw logs openclaw logs --follow # 实时跟踪 openclaw logs --limit 100 # 限制行数 openclaw logs --json # JSON 格式
五、配置管理
配置文件位于 ~/.openclaw/openclaw.json,使用 JSON5 格式(支持注释和尾逗号)。
# 获取配置值(点路径语法) openclaw config get gateway.port # 输出: 18789 # 设置配置值 openclaw config set gateway.port 18790 openclaw config set gateway.bind loopback # 删除配置项 openclaw config unset gateway.tailscale # 交互式配置向导 openclaw configure openclaw configure --section model # 仅配置模型部分 openclaw configure --section web # 仅配置 Web 部分
六、模型管理
6.1 查看与设置模型
# 列出已配置的模型 openclaw models list # 查看当前模型状态 openclaw models status openclaw models status --json # JSON 格式 # 设置默认模型 openclaw models set qwen-portal/coder-model openclaw models set qwen # 使用别名 # 设置图像模型 openclaw models set-image qwen-portal/vision-model
6.2 模型认证
# 交互式认证向导(引导完成 OAuth 或 Token 设置) openclaw models auth add # 手动粘贴 Token openclaw models auth paste-token # 通过 CLI 设置 Token openclaw models auth setup-token # 管理认证顺序 openclaw models auth order
6.3 别名与回退
# 管理模型别名 openclaw models aliases # 管理回退链(主模型不可用时自动切换) openclaw models fallbacks # 管理图像模型回退 openclaw models image-fallbacks # 扫描 OpenRouter 免费模型 openclaw models scan
支持的模型提供商:OpenAI、Anthropic(Claude)、Google(Gemini)、OpenRouter、DeepSeek、Mistral、Groq 等。
七、频道管理(Channels)
OpenClaw 支持 20+ 通信频道:Telegram、WhatsApp、Discord、Slack、Signal、iMessage、IRC、飞书、LINE 等。
7.1 添加频道
# 添加 Telegram Bot openclaw channels add --channel telegram --token "123456:ABC..." # 添加 Discord Bot openclaw channels add --channel discord --token "MTIz..." # 添加 Slack App openclaw channels add --channel slack --bot-token "xoxb-..." --app-token "xapp-..." # 添加 WhatsApp(需要扫码登录) openclaw channels login --channel whatsapp # 添加 Matrix openclaw channels add --channel matrix --homeserver "https://matrix.org" --user-id "@user:matrix.org" --access-token "..." # 添加 Signal openclaw channels add --channel signal --signal-number "+886..." # 添加多账号(指定 account ID) openclaw channels add --channel telegram --account work --token "..."
7.2 管理频道
# 列出所有频道 openclaw channels list # 查看频道连接状态(含 Gateway 探测) openclaw channels status openclaw channels status --probe # 查看频道日志 openclaw channels logs # 查看频道支持的功能 openclaw channels capabilities # 移除频道 openclaw channels remove --channel telegram # 登出频道 openclaw channels logout --channel whatsapp
7.3 DM 配对
# 查看待配对请求 openclaw pairing # 批准配对 openclaw pairing approve telegram WR8XRQQA
八、Skills(技能插件)
Skills 是 OpenClaw 的功能扩展机制,每个 Skill 定义 AI Agent 可以执行的特定能力。
# 列出所有 Skills openclaw skills list # 检查 Skills 就绪状态 openclaw skills check # 查看某个 Skill 详情 openclaw skills info coding-agent
常用内置 Skills:
| Skill | 说明 | 依赖 |
|---|---|---|
| weather | 天气查询 | curl |
| github | GitHub 仓库操作 | gh CLI |
| coding-agent | 代码辅助 | 无 |
| himalaya | 邮件收发 | himalaya CLI + IMAP |
| openai-whisper-api | 语音转文字 | OPENAI_API_KEY |
| session-logs | 搜索历史对话 | jq + rg |
| summarize | 网页/视频摘要 | summarize CLI |
九、Hooks(事件钩子)
Hooks 是 OpenClaw 的事件驱动自动化机制,特定事件触发时自动执行预定义操作。
# 列出所有 Hooks openclaw hooks list # 查看某个 Hook 详情 openclaw hooks info session-memory # 检查 Hooks 就绪状态 openclaw hooks check # 启用 / 禁用 Hook openclaw hooks enable session-memory openclaw hooks disable command-logger # 安装 Hook 包 openclaw hooks install ./my-hook-pack openclaw hooks install some-npm-hook-package # 更新已安装的 Hooks openclaw hooks update
内置 Hooks:boot-md(启动时运行 BOOT.md)、session-memory(/new 或 /reset 时保存上下文)、command-logger(记录所有命令事件)。
十、Plugins(插件管理)
# 列出所有插件 openclaw plugins list # 查看插件详情 openclaw plugins info some-plugin # 安装插件 openclaw plugins install ./my-plugin openclaw plugins install some-npm-plugin # 启用 / 禁用插件 openclaw plugins enable some-plugin openclaw plugins disable some-plugin # 诊断插件加载问题 openclaw plugins doctor
十一、Agents(代理管理)
Agents 是 OpenClaw 的隔离执行单元,每个 Agent 有独立的工作空间、认证配置和路由规则。
# 列出所有 Agent openclaw agents list # 添加隔离 Agent openclaw agents add work # 设置 Agent 身份 openclaw agents set-identity work --name "Work Bot" # 删除 Agent openclaw agents delete work
终端直接对话
# 基础对话 openclaw agent --agent main --message "今天天气怎么样?" # 指定会话 ID 继续对话 openclaw agent --session-id 1234 --message "继续上次的话题" # 指定思考级别 openclaw agent --message "分析代码性能" --thinking medium # 对话结果发送到 Telegram openclaw agent --message "生成周报" --deliver --channel telegram --reply-to "@mychat"
十二、会话管理(Sessions)
# 列出所有会话 openclaw sessions # 只看最近 2 小时活跃的会话 openclaw sessions --active 120 # 聚合所有 Agent 的会话 openclaw sessions --all-agents # JSON 格式输出 openclaw sessions --json
十三、记忆系统(Memory)
OpenClaw 内置语义记忆搜索,可以从历史对话和笔记中检索信息。
# 查看记忆索引状态 openclaw memory status # 重建索引 openclaw memory index openclaw memory index --force # 语义搜索 openclaw memory search --query "服务器配置"
记忆文件结构:
MEMORY.md— 长期记忆(手动维护)memory/YYYY-MM-DD.md— 每日笔记(自动/手动)
十四、定时任务(Cron)
让 AI 助手定时执行任务。
# 查看调度器状态 openclaw cron status # 列出所有定时任务 openclaw cron list # 添加定时任务(交互式) openclaw cron add # 手动触发任务 openclaw cron run <job-id> # 启用 / 禁用任务 openclaw cron enable <job-id> openclaw cron disable <job-id> # 编辑任务 openclaw cron edit <job-id> # 查看运行历史 openclaw cron runs <job-id>
常见用例:每天 9 点播报天气、每小时检查新邮件、每周一生成周报。
十五、浏览器自动化(Browser)
OpenClaw 可以控制无头浏览器,实现网页自动化操作。
# 查看状态 / 启动 openclaw browser status openclaw browser start # 打开网页 openclaw browser open https://example.com # 列出标签页 openclaw browser tabs # 截图 openclaw browser screenshot openclaw browser screenshot --full-page # 获取页面快照(AI 可读的结构化格式) openclaw browser snapshot # 点击元素(通过 ref 编号) openclaw browser click 12 # 输入文字 openclaw browser type 23 "hello" --submit # 按键 openclaw browser press Enter # 导航 openclaw browser navigate https://google.com
十六、多设备联动(Nodes)
# 查看已配对设备 openclaw nodes status # 查看节点能力 openclaw nodes describe <node-id> # 发送通知 openclaw nodes notify --node mac --body "任务完成!" # 远程拍照 openclaw nodes camera --node iphone --facing back # 获取设备位置 openclaw nodes location --node iphone # 远程执行命令 openclaw nodes run --node mac -- "ls -la ~/Desktop"
十七、诊断与排查
17.1 openclaw doctor(最重要的诊断命令)
# 运行环境诊断 openclaw doctor # 自动修复 openclaw doctor --fix # 深度扫描(含系统服务) openclaw doctor --deep # 生成 Gateway Token openclaw doctor --generate-gateway-token # 非交互模式 openclaw doctor --non-interactive
17.2 安全审计
# 本地安全审计 openclaw security audit # 深度审计(含 Gateway 探测) openclaw security audit --deep # 自动修复安全问题 openclaw security audit --fix
17.3 其他实用命令
# 查看整体状态 openclaw status openclaw status --all openclaw status --deep # 打开 Web 控制台 openclaw dashboard openclaw dashboard --no-open # 打开终端 TUI openclaw tui
十八、聊天斜杠命令
在聊天窗口(Telegram、Discord、Slack、WhatsApp 等)中使用的命令。
18.1 基础命令
| 命令 | 说明 | 示例 |
|---|---|---|
/new | 重置会话,清空历史 | /new |
/new <model> | 重置并切换模型 | /new claude-sonnet-4-20250514 |
/status | 查看会话状态、Token、成本 | /status |
/help | 查看所有斜杠命令 | /help |
/commands | 查看可用命令列表 | /commands |
18.2 模型与上下文管理
# 切换模型 /model deepseek/deepseek-chat # 列出可用模型 /models # 查看当前模型状态 /model-status # 压缩上下文(减少 Token 消耗) /compact /compact 保留代码相关的讨论,其他可以简化 # 查看用量 /usage off # 关闭显示 /usage tokens # 仅显示 Token 数 /usage full # 显示完整用量 /usage cost # 显示成本统计 # 查看上下文详情 /context /context list # 列出上下文组件 /context detail # 详细 Token 分布 /context json # JSON 格式
18.3 执行控制与安全
# 查看当前执行设置 /exec # 设置安全策略 /exec host=sandbox security=allowlist ask=always # 批准待执行操作 /approve <操作ID> allow-once # 仅允许本次 /approve <操作ID> allow-always # 永久允许 /approve <操作ID> deny # 拒绝 # 权限模式总开关 /elevated on # 开启提升权限 /elevated off # 关闭提升权限
/exec 参数说明:
| 参数 | 选项 | 说明 |
|---|---|---|
host | sandbox | Docker 沙箱执行(推荐) |
gateway | 网关主机执行 | |
node | 配对节点执行 | |
security | deny | 拒绝所有命令 |
allowlist | 仅允许白名单命令 | |
full | 允许所有命令(谨慎) | |
ask | off | 不询问,按策略执行 |
on-miss | 不在白名单时询问 | |
always | 每次都询问 |
18.4 语音控制(TTS)
/tts off # 关闭语音 /tts always # 所有回复语音播报 /tts inbound # 仅语音输入时回复语音 /tts tagged # 仅标记内容的语音播报 /tts status # 查看当前状态 /tts provider # 查看或切换 TTS 提供商
支持的 TTS 提供商:Edge TTS(免费默认)、OpenAI TTS、ElevenLabs。
18.5 子代理管理
/subagents list # 列出所有子代理 /subagents stop <id> # 停止子代理 /subagents log <id> # 查看日志 /subagents info <id> # 查看详情 /subagents send <id> <message> # 发送消息
十九、常见问题排查
19.1 命令名称错误
OpenClaw 的命名规范:顶级名词用复数形式(models、channels、skills、hooks、agents),少数核心命令用单数(gateway、doctor、config)。
# 错误写法 openclaw version # ✗ 不存在 openclaw model list # ✗ 不存在(提示 Did you mean models?) openclaw channel list # ✗ 不存在 openclaw skill list # ✗ 不存在 # 正确写法 openclaw --version # ✓ 使用标志 openclaw models list # ✓ 复数形式 openclaw channels list # ✓ 复数形式 openclaw skills list # ✓ 复数形式
19.2 Gateway 端口被占用
# 方式一:强制启动 openclaw gateway --force # 方式二:更换端口 openclaw gateway --port 18790 openclaw config set gateway.port 18790 # 方式三:查看占用进程 lsof -i :18789 # macOS/Linux netstat -ano | findstr :18789 # Windows
19.3 配置文件位置速查
| 文件 | 路径 |
|---|---|
| 主配置文件 | ~/.openclaw/openclaw.json |
| Agent 工作空间 | ~/.openclaw/agents/main/ |
| 认证配置 | ~/.openclaw/agents/main/agent/auth-profiles.json |
| Gateway 日志 | /tmp/openclaw/openclaw-YYYY-MM-DD.log |
19.4 遇到问题时
# 完整诊断 openclaw doctor --deep # 查看版本 openclaw --version # 查看 Gateway 状态 openclaw gateway status # 查看健康状态 openclaw gateway health
二十、每日核心命令速查表
日常使用掌握以下命令即可满足大部分需求:
# 1. 启动 Gateway openclaw gateway start # 2. 查看整体状态 openclaw status # 3. 管理 Channel openclaw channels status # 4. 管理模型 openclaw models status openclaw models set <model-name> # 5. 查看 Skills openclaw skills check # 6. 定期健康检查 openclaw doctor # 7. 查看日志 openclaw logs --follow # 8. 更新 OpenClaw openclaw update
到此这篇关于OpenClaw的常用命令大全以及使用新手指南(2026最新)的文章就介绍到这了,更多相关OpenClaw常用命令内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
