乐于分享
好东西不私藏

OpenClaw命令行速查手册:200+命令按场景分类整理

OpenClaw命令行速查手册:200+命令按场景分类整理

大家好,我是苍一,一个干了13年的后端开发,正在探索AI编程,从产品到开发的全生命周期最佳实践,如果您感兴趣,欢迎关注👇,看我如何自我革命。

这篇文章把OpenClaw日常用到的命令按实际操作场景做了分类。从第一次安装到线上排障,覆盖了完整的使用链路。

安装与环境准备

1️⃣ Node.js安装

确认Node.js版本,OpenClaw要求Node 22或更高:

node --version

macOS用Homebrew:

brew install node
brew upgrade node

Windows用winget:

winget install OpenJS.NodeJS.LTS

Linux(Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

2️⃣ OpenClaw安装与验证

npm install -g openclaw@latest
openclaw --version

初始化与首次运行

3️⃣ 启动配置向导

openclaw onboard --install-daemon
openclaw config get tools.profile
openclaw config set tools.profile "coding"

向导会引导完成模型选择、Channel接入等基础配置。–install-daemon同时把Gateway装成系统服务。

4️⃣ Daemon安装失败

sudo loginctl enable-linger $USER
systemctl --user status

跳过daemon手动管理:

openclaw onboard --skip-daemon
openclaw health

5️⃣ 查看当前状态

openclaw status

排障时第一个跑它。

安装阶段常见问题

6️⃣ command not found

npm装了但shell找不到命令,PATH没包含npm全局bin目录:

npm prefix -g
echo $PATH | grep $(npm prefix -g)

zsh环境:

echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

7️⃣ 权限问题

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

8️⃣ 端口冲突

openclaw gateway run --port 18790

9️⃣ 网络问题

npm config set registry https://registry.npmmirror.com
npm install -g openclaw@latest

🔟 认证失败

openclaw config get models
openclaw onboard

1️⃣1️⃣ Agent无响应

openclaw status
openclaw logs
openclaw doctor
openclaw gateway stop
openclaw gateway start

1️⃣2️⃣ Windows用户

OpenClaw在Windows上通过WSL运行:

wsl --install

飞书Channel接入

13️⃣ 配置飞书连接

openclaw channels list
openclaw channels add

14️⃣ 配对与审批

openclaw pairing approve feishu <配对码>

15️⃣ 飞书排障

openclaw status
openclaw channels list
openclaw pairing list feishu
openclaw logs --follow

配置管理

16️⃣ 日志查看

openclaw logs --follow
openclaw logs --limit 100

17️⃣ 查看与修改配置

openclaw config get gateway.port
openclaw config set gateway.port 18790 --json
openclaw configure

修改前备份:

cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup

18️⃣ 环境变量与敏感信息

临时设置:

export KIMI_API_KEY="sk-xxxxxxxxxxxxx"
openclaw gateway start

持久设置:

echo 'export KIMI_API_KEY="sk-xxxxxxxxxxxxx"' >> ~/.zshrc
source ~/.zshrc

19️⃣ 配置变更后验证

openclaw config set gateway.port 18790 --json
openclaw gateway restart
openclaw status
openclaw doctor

模型配置与切换

openclaw models set kimi-coding/k2p5
openclaw models set minimax/MiniMax-M2.5
openclaw models set zai/glm-5

对话中输入/model切换当前会话模型。

安全与审批

20️⃣ 审批策略

openclaw approvals get
openclaw approvals set --file ./exec-approvals.json
openclaw approvals allowlist add "~/Projects/**/bin/rg"

21️⃣ 凭证管理

openclaw secrets audit --check
openclaw secrets configure
openclaw secrets reload

Skills管理

22️⃣ 搜索与安装

npm install -g clawhub
clawhub login
clawhub search 日报
clawhub install daily-report
clawhub update --all
clawhub list

23️⃣ 自定义Skill

mkdir -p ~/.openclaw/workspace/skills/daily-report
openclaw skills check
openclaw skills info daily-report

24️⃣ 发布到ClawHub

cd ~/.openclaw/workspace/skills/daily-report
clawhub publish

Gateway服务管理

openclaw gateway install --force
systemctl --user status openclaw-gateway.service
sudo systemctl restart openclaw-gateway.service
sudo journalctl -u openclaw-gateway.service -f

备份与恢复

openclaw gateway stop
cp -r ~/backups/openclaw-20260228/config ~/.openclaw/
openclaw gateway start

版本升级

npm install -g openclaw@latest
openclaw doctor

回退:

npm install -g openclaw@2026.3.2

速查:救命八连

排障时依次执行:

openclaw --version
openclaw status
openclaw doctor
openclaw logs --follow
openclaw gateway status
openclaw channels status --probe
openclaw sessions --json
openclaw health

如果嫌文章太长、怕后面走丢,可以关注下面的ima知识号,让这篇文章成为你的知识顾问,随时随地等候你的提问。

知识号中内容会以笔记形式分享,可以根据大家反馈和实测情况,实时更新,保证最新方案的稳定、可用。

【ima 知识库】