安装方式
手动下载安装
下载 ZIP 后解压到技能目录即可安装。若在桌面客户端 WebView中直接下载出现异常,本站会改为提示页 + 原始链接,请按页内说明操作。
下载 ZIP (shub-claude-code-bridge-v0.3.0.zip)触发指令
/claude-code-bridge
跨平台安装指引
该技能声明兼容以下 1 个平台,将 ZIP 解压到对应目录即可被识别。
unzip shub-claude-code-bridge-v0.3.0.zip -d ~/.claude/skills/
mkdir -p 创建;启用 Skill 后请重启对应 Agent 让配置生效。
使用指南
OpenClaw 与 Claude Code 桥接
围绕 OpenClaw 与 Claude Code 桥接:将 QQ、Telegram、微信等通道与后台 tmux 中持久运行的 Claude Code 会话连接;可启动/停止/查看状态,并在聊天中批准工具调用,支持沙盒目录与多语言触发语。 无需在每次任务前把零散英文说明手工拼进上下文,也 减少 与客户端默认行为脱节的试错;具体命令、钩子与 JSON 参数仍以 ZIP 包内 SKILL.md 为权威。下文结构与站内 MCP CLI 类专题稿相同:何时用、前置、流程、速查与故障。
何时使用
- 将 QQ、Telegram、微信等通道与后台 tmux 中持久运行的 Claude Code 会话连接
- 可启动/停止/查看状态,并在聊天中批准工具调用,支持沙盒目录与多语言触发语
- 已获取本技能 ZIP,并准备在 Claude Code / OpenClaw 中按 SKILL.md 挂载。
- 希望用中文专题稿快速判断「该不该启用」,再深入英文 SKILL 查参数与边界。
- 需要与团队对齐同一套触发方式、目录约定或回调格式时。
前置条件
- 通用:可运行 Claude Code 或文档要求的客户端;有可读写的项目工作区(或 SKILL.md 指定的沙箱目录)。
- 权威细节:API Key / OAuth、钩子路径、环境变量以 ZIP 内 SKILL.md 为准。
典型流程
- 从 ClawHub / 站内分发获取技能 ZIP,校验版本与校验和(若提供)。
- 阅读 SKILL.md 的安装段落:目录落点、客户端类型(Claude Code / OpenClaw / 脚本)。
- 用文档中的最小示例完成第一次调用(单文件修改、单次查询或单次委派)。
- 确认工作目录、权限边界与输出路径后,再处理多文件或长耗时任务。
- 需要回调 / Webhook / 通知时,按 SKILL.md 配置端点并在测试环境先验通。
与 ZIP / SKILL.md 的关系
站内专题稿与 MCP CLI 类 oss 稿同样:概括何时用、怎么接、怎么排错;命令模板、钩子名、JSON 字段、版本矩阵一律以 ZIP 内 SKILL.md 与 ClawHub 上游为准。
命令示例(摘自包内 SKILL.md)
以下为从上游 SKILL.md(或入库正文)自动抽取的终端/脚本片段;路径、环境变量与参数以当前 ZIP 与官方说明为准。
ClawHub slug:claude-code-bridge(安装命令以 SKILL.md / claw CLI 为准)。
~/.openclaw/workspace/skills/claude-code-bridge/scripts/claude-code-bridge.sh "<SESSION_ID>" status
SCRIPT="$HOME/.openclaw/workspace/skills/claude-code-bridge/scripts/claude-code-bridge.sh"
"$SCRIPT" "<ID>" start '/path/to/workdir' # 在指定目录启动
"$SCRIPT" "<ID>" start --sandbox # 沙盒模式启动
"$SCRIPT" "<ID>" send '<message>' # 发送(90s 超时)
"$SCRIPT" "<ID>" send '<message>' --long # 长任务(5min 超时)
"$SCRIPT" "<ID>" approve 1 # 审批:选 Yes
"$SCRIPT" "<ID>" approve 2 # 审批:选 Allow always
"$SCRIPT" "<ID>" approve 3 # 审批:选 No
"$SCRIPT" "<ID>" approve esc # 审批:取消
"$SCRIPT" "<ID>" stop # 停止(沙盒自动清理)
"$SCRIPT" "<ID>" restart # 重启(保留原工作目录)
"$SCRIPT" "<ID>" restart '/new/path' # 重启到新目录
"$SCRIPT" "<ID>" status # 状态(含工作目录信息)
"$SCRIPT" "<ID>" workdir # 查询当前工作目录
"$SCRIPT" "<ID>" peek # 原始终端画面
"$SCRIPT" "<ID>" history 200 # 最近 200 行历史
站内入库时的触发命令(完整语义见 ZIP):
# 使用本技能时可在对话中引用或执行上述指令;完整参数与示例见下载包内 SKILL.md。
/claude-code-bridge
最佳实践
- 先 SKILL.md 再猜参数;站内专题稿不替代 schema 与必填字段说明。
- 委派任务时写清验收标准(命令、文件路径、测试命令),减少来回追问。
- 长任务用文档推荐的回调 / 日志落盘代替高频轮询,省 Token 也省机器负载。
- 多技能同时启用时,注意钩子加载顺序与重复工具调用(以 SKILL.md 冲突说明为准)。
调试与排错
- 打开 stderr 与客户端日志;PTY/tmux 场景同时看面板最后几十行输出。
- 参数错误时对照 SKILL.md 中的 JSON/CLI 示例(引号、转义、工作目录)。
- 网络类失败:查代理、防火墙、MCP 传输方式(stdio / HTTP / SSE)。
速查
| 动作 | 说明 |
|------|------|
| 获取技能包 | ClawHub / 站内 ZIP,核对版本 |
| 权威步骤 | 优先阅读 ZIP 内 SKILL.md |
| 首次试跑 | 使用 SKILL.md 最小示例 |
| 验收 | 对照路径、测试命令或回调负载 |
常见故障
- 无输出或立即退出 → 工作目录错误、依赖未装、或 Claude Code 未登录;按 SKILL.md 自检清单执行。
- 权限被拒绝 → 检查沙箱路径、
--permission-mode与工具白名单。 - 与简介不符 → 以英文 SKILL 与上游仓库为准,站内稿仅作结构化导读。
# Claude Code Bridge
Bridge every incoming message to a live, persistent `claude` CLI process running
in a background tmux session. The user interacts via QQ/Telegram/any channel;
Claude Code responds as if they were typing in a real terminal.
## Session State Detection (CRITICAL — CHECK EVERY TURN)
**At the start of EVERY incoming message**, determine session state:
```bash
~/.openclaw/workspace/skills/claude-code-bridge/scripts/claude-code-bridge.sh "<SESSION_ID>" status
```
- `✅ Claude Code 会话运行中` → **CC mode active**, route message to CC
- `⭕ 没有活跃` → **CC mode off**, respond normally
- `⚠️ CC 正在等待审批` → tell user and await their approval choice
Construct `<SESSION_ID>` as `<channel>_<chat_id>` using only `[a-zA-Z0-9_]`.
## Routing Logic
```
Every incoming message:
1. Run status check
2. Is it a CC control command?
──── Startup (with workdir) ────
"在 <path> 打开cc" → start <path>
"沙盒打开cc" / "沙盒模式" → start --sandbox
"启动cc"(no path) → ASK workdir first (see Startup Flow below)
──── Other controls ────
"关闭cc" → stop
"重启cc" → restart
"cc状态" → status
"cc在哪" / "cc目录" → workdir
"/cc peek" → peek
"/cc history [N]" → history
3. Is CC in approval-waiting state?
YES → parse user's intent (y/n/1/2/3) → approve
4. Is CC session active?
YES → forward as send
NO → respond normally as OpenClaw agent
```
## Startup Flow — Working Directory
When the user wants to start Claude Code **without specifying a directory**:
1. Ask briefly: `"工作目录放哪?发路径就在那里打开,不指定就用临时沙盒。"`
2. Parse the reply:
- User sends a path (e.g. `~/projects/paper`) → `start ~/projects/paper`
- User says "沙盒" / "随便" / "临时" / doesn't specify → `start --sandbox`
When the user specifies a directory **in the startup command itself**:
- "在 ~/Documents/Code 打开cc" → extract the path → `start ~/Documents/Code`
- "沙盒打开cc" / "沙盒模式启动cc" → `start --sandbox`
**Do NOT ask if the path is already provided in the command.**
## Executing Actions
```bash
SCRIPT="$HOME/.openclaw/workspace/skills/claude-code-bridge/scripts/claude-code-bridge.sh"
"$SCRIPT" "<ID>" start '/path/to/workdir' # 在指定目录启动
"$SCRIPT" "<ID>" start --sandbox # 沙盒模式启动
"$SCRIPT" "<ID>" send '<message>' # 发送(90s 超时)
"$SCRIPT" "<ID>" send '<message>' --long # 长任务(5min 超时)
"$SCRIPT" "<ID>" approve 1 # 审批:选 Yes
"$SCRIPT" "<ID>" approve 2 # 审批:选 Allow always
"$SCRIPT" "<ID>" approve 3 # 审批:选 No
"$SCRIPT" "<ID>" approve esc # 审批:取消
"$SCRIPT" "<ID>" stop # 停止(沙盒自动清理)
"$SCRIPT" "<ID>" restart # 重启(保留原工作目录)
"$SCRIPT" "<ID>" restart '/new/path' # 重启到新目录
"$SCRIPT" "<ID>" status # 状态(含工作目录信息)
"$SCRIPT" "<ID>" workdir # 查询当前工作目录
"$SCRIPT" "<ID>" peek # 原始终端画面
"$SCRIPT" "<ID>" history 200 # 最近 200 行历史
```
**IMPORTANT — message quoting**: Use `tmux send-keys -l` (literal mode) so
special characters (`$`, `!`, `\`) are sent verbatim. The script handles this
internally; just pass the raw message as argument 3.
## CC Slash Commands — Direct Passthrough
CC's own slash commands work by sending them via `send`:
| User says | Forward as |
|-----------|-----------|
| `/plan` | `send '/plan'` |
| `/model sonnet` | `send '/model sonnet'` |
| `/compact` | `send '/compact'` |
| `/cost` | `send '/cost'` |
| `/help` | `send '/help'` |
| `/clear` | `send '/clear'` |
| `/diff` | `send '/diff'` |
| `/fast` | `send '/fast'` |
| `/vim` | `send '/vim'` |
| `/context` | `send '/context'` |
| `/export` | `send '/export'` |
| `/copy` | `send '/copy'` |
| `/rewind` | `send '/rewind'` |
| `/fork` | `send '/fork'` |
| `/permissions` | `send '/permissions'` |
| `/tasks` | `send '/tasks'` |
| `/status` | `send '/status'` |
| `/stats` | `send '/stats'` |
| `/review` | `send '/review'` |
| `/theme` | `send '/theme'` |
| `/sandbox` | `send '/sandbox'` |
| Any `/xxx` command | `send '/xxx'` |
These are NOT OpenClaw commands — forward them verbatim to CC.
All CC slash commands work via passthrough, including ones not listed above.
## Handling CC Approval Prompts
When CC encounters a tool it needs permission to run, it shows a TUI selection
menu (arrow-key navigation, not text input). The `approve` action handles this:
```
CC shows:
Do you want to proceed?
❯ 1. Yes
2. Yes, allow from this project
3. No
```
The user's reply should be interpreted:
- "y" / "是" / "好" / "1" / "同意" → `approve 1`
- "2" / "允许" / "一直允许" → `approve 2`
- "n" / "否" / "不" / "3" / "拒绝" → `approve 3`
- "取消" / "cancel" → `approve esc`
## Long Tasks & Streaming
For tasks that take a long time (refactoring, writing large codebases):
1. Detect intent: if the user's message implies a large task (e.g. "重构整个项目",
"帮我写一个完整的 XXX"), use `--long` flag (5-minute timeout)
2. If the output is empty after timeout, use `peek` to check CC's current state
3. If CC is still working, inform the user: `CC 仍在处理中,稍后再查`
4. Then use `peek` or `history` to get progress updates
## Formatting — Seamless Mode
**Goal: make the user feel like they're talking to Claude Code directly.**
When CC session is active:
- **Do NOT prefix every reply with `🤖 CC →`** — just relay CC's output directly
- Only add brief status markers for:
· Session startup / shutdown
· Approval prompts (show the options)
· Errors / timeouts
- CC's code blocks, file paths, tool output → relay as-is, no reformatting
- Empty output → brief `CC 处理中...` then try `peek` after 3s
- Output >3000 chars → show last 2000 chars, note `/cc history` for full output
- Approval prompt → show options directly, minimal decoration
## Error Handling
| Situation | Action |
|-----------|--------|
| `send` returns empty | Wait 3s, run `peek`, relay result |
| Session not found | Inform user, offer to `start` |
| Session crashed | Detect via `status`, offer `restart` |
| CC shows error | Relay error verbatim |
| Timeout on long task | Inform user, suggest `peek` or `history` |
## Additional Resources
- **`scripts/claude-code-bridge.sh`** — Full session management (start/send/approve/stop/restart/status/workdir/peek/history)
- **`references/usage.md`** — User-facing help text and example conversations