Openclaw CLI 命令参考
核心命令
agent 命令
# 启动代理
openclaw agent start
# 停止代理
openclaw agent stop
# 重启代理
openclaw agent restart
# 查看代理状态
openclaw agent status
# 列出所有代理
openclaw agent list
config 命令
# 查看配置
openclaw config view
# 设置配置项
openclaw config set server.port 8080
# 获取配置值
openclaw config get server.port
# 验证配置
openclaw config validate
# 导出配置
openclaw config export --format yaml
channels 命令
# 列出频道
openclaw channels list
# 启用频道
openclaw channels enable slack
# 禁用频道
openclaw channels disable discord
# 测试频道连接
openclaw channels test telegram
系统管理命令
daemon 命令
# 启动守护进程
openclaw daemon start
# 停止守护进程
openclaw daemon stop
# 重启守护进程
openclaw daemon restart
# 查看守护进程状态
openclaw daemon status
health 命令
# 健康检查
openclaw health
# 详细健康信息
openclaw health --verbose
# 指定端点检查
openclaw health --endpoint http://localhost:3000
logs 命令
# 查看日志
openclaw logs
# 实时跟踪日志
openclaw logs --follow
# 指定日志级别
openclaw logs --level error
# 查看特定组件日志
openclaw logs --component agent
开发相关命令
plugins 命令
# 列出插件
openclaw plugins list
# 安装插件
openclaw plugins install @openclaw/plugin-name
# 卸载插件
openclaw plugins uninstall plugin-name
# 更新插件
openclaw plugins update plugin-name
skills 命令
# 列出技能
openclaw skills list
# 创建新技能
openclaw skills create my-skill
# 测试技能
openclaw skills test my-skill
# 打包技能
openclaw skills package my-skill
实用工具命令
update 命令
# 检查更新
openclaw update check
# 执行更新
openclaw update apply
# 强制更新
openclaw update --force
cron 命令
# 列出定时任务
openclaw cron list
# 添加定时任务
openclaw cron add "0 9 * * *" "openclaw agent report"
# 删除定时任务
openclaw cron remove task-id
命令选项和参数
通用选项
# 帮助信息
openclaw --help
openclaw command --help
# 版本信息
openclaw --version
# 详细输出
openclaw command --verbose
# 静默模式
openclaw command --quiet
# 配置文件指定
openclaw --config /path/to/config.yaml command
环境变量
# 设置环境变量影响命令行为
export OPENCLAW_CONFIG=/path/to/config.yaml
export OPENCLAW_LOG_LEVEL=debug
export OPENCLAW_DATA_DIR=/custom/data/path
使用示例
完整工作流示例
# 1. 初始化配置
openclaw config set server.port 3000
openclaw config set agents.default.primary
# 2. 启动服务
openclaw daemon start
# 3. 启用频道
openclaw channels enable slack
openclaw channels enable discord
# 4. 监控运行状态
openclaw health
openclaw logs --follow
# 5. 管理插件
openclaw plugins install @openclaw/analytics
openclaw plugins list
故障排除示例
# 检查配置问题
openclaw config validate --verbose
# 查看详细错误日志
openclaw logs --level error --component gateway
# 测试连接
openclaw channels test all
# 重启服务
openclaw daemon restart
脚本化使用
Shell 脚本示例
#!/bin/bash
# deploy.sh
set -e
echo "🚀 部署 OpenClaw..."
# 检查配置
openclaw config validate
# 停止现有服务
openclaw daemon stop || true
# 更新插件
openclaw plugins update --all
# 启动服务
openclaw daemon start
# 等待启动完成
sleep 10
# 健康检查
openclaw health
echo "✅ 部署完成!"
自动化脚本
# backup.sh
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backup/openclaw/$DATE"
mkdir -p $BACKUP_DIR
# 备份配置
openclaw config export > $BACKUP_DIR/config.yaml
# 备份数据
cp -r ~/.openclaw/data $BACKUP_DIR/
# 备份日志
cp -r ~/.openclaw/logs $BACKUP_DIR/
echo "备份完成: $BACKUP_DIR"
权限和安全
权限管理
# 以特定用户运行
sudo -u openclaw openclaw daemon start
# 设置配置文件权限
chmod 600 ~/.openclaw/config.yaml
chown openclaw:openclaw ~/.openclaw/config.yaml
安全考虑
# 避免在命令行中暴露敏感信息
# 使用环境变量或配置文件
export OPENCLAW_API_KEY="your-api-key"
openclaw agent start
# 或使用配置文件
echo "api_key: your-api-key" > ~/.openclaw/secrets.yaml
openclaw --config ~/.openclaw/secrets.yaml agent start
官方文档: https://docs.openclaw.ai/cli/