Claude Code远程执行Skill——通过FastAPI/Redis/Screen三通道向远程机器派发指令,支持重试。触发词:派发给Claude Code、远程执行、让XX机器执行Claude Code、remote cc
通过三通道向远程机器上的 Claude Code 派发指令,支持重试机制。
text
我 (NAS/OpenClaw)
│
├─→ FastAPI:18900 ──→ Worker 监听 Redis ──→ Claude Code 执行
│ ↑
│ HTTP POST
│
└─→ Redis LPUSH ──→ Worker BLPOP ──→ Claude Code 执行
↑
直接写队列
远程机器需要运行:
在远程机器上运行:
bash
# 安装依赖
pip3 install redis uvicorn fastapi
# 启动 Worker(后台常驻)
nohup python3 cc_worker.py > worker.log 2>&1 &
# 启动 API
nohup python3 cc_api.py > api.log 2>&1 &
通道原理稳定性fastapiHTTP POST 到远程 API,Worker 执行⭐⭐⭐ 最稳定redis直接 LPUSH 到 Redis 队列⭐⭐screenSSH Screen 后台执行⭐ fallback
首次使用前,编辑 scripts/exec.py 顶部配置:
python
M1_HOST = "远程机器IP" # 如 "192.168.0.128"
M1_API_PORT = 18900 # FastAPI 端口
REDIS_HOST = "Redis服务器IP" # 如 "192.168.0.107"
REDIS_PORT = 11980 # Redis 端口
bash
python3 scripts/exec.py "你的指令"
参数说明prompt要执行的指令(必须)--task-id指定任务ID--timeout超时秒数(默认300)--channel强制指定通道(fastapi/redis/screen)
bash
# 基本用法(自动选择通道)
python3 scripts/exec.py "say hello"
# 强制用 fastapi
python3 scripts/exec.py "say hello" --channel fastapi
# 指定任务ID,方便查结果
python3 scripts/exec.py "修改 index.html" --task-id fix001
bash
# 查看进程
ssh 远程机器 "ps aux | grep cc_"
# 重启 Worker
ssh 远程机器 "pkill -f cc_worker; nohup python3 ~/cc_worker.py > ~/worker.log 2>&1 &"
# 重启 API
ssh 远程机器 "pkill -f cc_api; nohup python3 ~/cc_api.py > ~/api.log 2>&1 &"
任务提交成功但没结果:
ssh 远程机器 "tail worker.log"curl http://远程机器IP:18900/healthredis-cli -h Redis服务器 -p 端口 LLEN claude_tasksFastAPI 连不上:
Worker 不处理队列:
发给 Claude Code 的指令要清晰:
好例子:
text
修改 /path/to/project/web/index.html:
1. 找到 body 样式部分
2. 添加背景色:background: #f5f5f5
3. 确保在移动端也生效(响应式)
注意:先备份原文件。
文件功能exec.py三通道执行器(核心)deploy_m1.py远程机器一键部署脚本deploy_ssh.pySSH 强化配置(连接池复用)