安装方式
手动下载安装
下载 ZIP 后解压到技能目录即可安装。若在桌面客户端 WebView中直接下载出现异常,本站会改为提示页 + 原始链接,请按页内说明操作。
下载 ZIP (shub-claude-code-delegate-v1.0.0.zip)触发指令
/claude-code-delegate
跨平台安装指引
该技能声明兼容以下 1 个平台,将 ZIP 解压到对应目录即可被识别。
unzip shub-claude-code-delegate-v1.0.0.zip -d ~/.claude/skills/
mkdir -p 创建;启用 Skill 后请重启对应 Agent 让配置生效。
使用指南
Claude Code 任务委派
围绕 Claude Code 任务委派:将编程类任务交给 Claude Code CLI 执行,适合代码生成、修 bug、实现需求、简单审查与探索代码结构。 无需在每次任务前把零散英文说明手工拼进上下文,也 减少 与客户端默认行为脱节的试错;具体命令、钩子与 JSON 参数仍以 ZIP 包内 SKILL.md 为权威。下文结构与站内 MCP CLI 类专题稿相同:何时用、前置、流程、速查与故障。
何时使用
- 将编程类任务交给 Claude Code CLI 执行,适合代码生成、修 bug、实现需求、简单审查与探索代码结构
- 已获取本技能 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-delegate(安装命令以 SKILL.md / claw CLI 为准)。
cd "<project_dir>" && claude -p "<task_description>" --output-format text --max-turns 10 --permission-mode bypassPermissions
站内入库时的触发命令(完整语义见 ZIP):
# 使用本技能时可在对话中引用或执行上述指令;完整参数与示例见下载包内 SKILL.md。
/claude-code-delegate
最佳实践
- 先 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 Delegate
Delegate programming tasks to local Claude Code CLI.
**RULE: You NEVER write code directly. ALL programming goes through `claude -p`.**
## Prerequisites Check (Run Before First Use)
Before delegating any task, verify the environment is ready:
1. **Claude Code CLI installed**: Run `which claude` — if not found, tell user: `npm install -g @anthropic-ai/claude-code`
2. **API key configured**: Run `claude --version` — if it errors about auth, tell user to run `claude` and complete login
3. **Write-guard active (STRONGLY RECOMMENDED)**: Check if a write-guard plugin exists at `.openclaw/extensions/write-guard/`. If not, warn the user:
> ⚠️ No write-guard detected. The delegate uses `--permission-mode bypassPermissions` which grants full filesystem read/write access. It is strongly recommended to set up a write-guard plugin before running tasks. See README.md for setup instructions.
Only proceed with delegation after items 1 and 2 pass. Item 3 is a warning — the user may choose to proceed without it, but should be informed of the risk.
## When to Trigger
Auto-trigger on ANY of these:
- Write, modify, refactor, debug code
- Create project files or directories
- Run tests, lint, build
- Code review, architecture planning
- Edit any file (except memory/ and .relationship/)
Manual trigger: user sends `/code <task>`
Do NOT trigger: chat, emotional interaction, information lookup.
## Command Template
```bash
cd "<project_dir>" && claude -p "<task_description>" --output-format text --max-turns 10 --permission-mode bypassPermissions
```
### Parameters
| Param | Purpose | Required |
|-------|---------|----------|
| `-p` | Non-interactive mode | Yes |
| `cd "<dir>" &&` | Set working dir (no --cwd flag exists) | Yes |
| `--output-format text` | Plain text output | Recommended |
| `--max-turns 10` | Limit execution rounds | Recommended |
| `--permission-mode bypassPermissions` | Auto-accept file edits (**requires write-guard**, see Prerequisites) | Recommended |
| `--continue` | Resume previous session (for debugging/iteration) | When fixing bugs in same project |
**FORBIDDEN: `--dangerously-skip-permissions`**
### Timeout
Set exec timeout to `300` (5 minutes). The delegate needs time to write code.
## Async Flow (CRITICAL)
**The delegate MUST NOT block you.** You must remain responsive to the user at all times.
### Correct Flow
```
Step 1: exec claude -p "..." → get session ID (e.g. "marine-sage")
Step 2: IMMEDIATELY reply to user → "On it! Working on that now."
Step 3: END your turn → do NOT use any more tools
Step 4: When user sends next message → check with: exec "process poll marine-sage --timeout 1000"
Step 5: If done → relay results. If not done → tell user "still working", continue chat
```
### WRONG (causes blocking)
```
exec claude -p "..." → process poll → (BLOCKED! user waits with no response)
```
### Rules
1. After `exec claude -p`, you MUST reply to user and END your turn. No more tool calls.
2. NEVER use `process` tool directly. Use `exec "process poll <id> --timeout 1000"` on next user message.
3. Only check the delegate's status when the user sends a NEW message.
4. You can run multiple `claude -p` tasks in parallel.
## Task Description Rules
1. Clear objective: what to do, which file
2. Provide context: function names, error messages, expected behavior
3. Specify constraints: language, framework, code style
4. One task per call
## Debugging / Iteration
When user reports bugs in code the delegate previously wrote:
- Use `--continue` flag to resume the delegate's session context
- Same project directory + `--continue` = the delegate remembers what it wrote
- Translate user's feedback into clear bug description for the delegate
## Testing / Verification (Independent Review)
After the delegate writes code, use a **separate fresh session** (NO `--continue`) to test and verify it.
Why: The author has context bias. A fresh session reads the source code independently — like an external code reviewer. This catches issues the author missed.
### Flow
```
Step 1: claude -p "Write X in projects/X/" → Author session (can use --continue to iterate)
Step 2: claude -p "Run and test projects/X/, report bugs" → Tester session (ALWAYS fresh, NO --continue)
```
### Rules
1. **Author session**: writes code, can use `--continue` to iterate on bugs
2. **Tester session**: NEVER uses `--continue` — must read source fresh
3. Tester reports: what it ran, output, pass/fail, bugs found
4. If tester finds bugs → relay to user, then send fix task to author session (with `--continue`)
### When to Auto-Test
- User says "test it" or "run it" after writing → use fresh session
- User says "fix the bug" after testing → use `--continue` on author session
- User says "run hot_sectors.py" (existing program) → fresh session (no prior context needed)
## Session Decision Rule
| Scenario | `--continue`? |
|----------|---------------|
| Fix/iterate on code the delegate just wrote | Yes |
| Test/verify code the delegate just wrote | **No** (fresh session) |
| Run existing program | **No** (fresh session) |
| New project/task | **No** (fresh session) |
## Relaying Results
The delegate does not talk to the user directly. You relay all results.
When relaying:
1. Summarize what was done and which files changed
2. Add the delegate's personality (see PERSONA.md for character template)
3. Add your own reaction
Keep technical summary concise. Do not copy the delegate's full output verbatim.
## Error Handling
| Error | Action |
|-------|--------|
| `command not found` | Tell user to install: `npm install -g @anthropic-ai/claude-code` |
| Empty output | Ask user to clarify the task |
| Timeout | Suggest breaking into smaller tasks |
| Permission error | Ask user to check file path |
| API error | Ask user to run `claude` to check login status |
## Failure Rule
**If the delegate fails or times out, do NOT write code yourself.**
Tell the user: "The coding task didn't finish. Want me to try again?"
Retry with longer timeout or simpler task description. Only write code yourself if user explicitly says "you do it" (not recommended).
## Security Best Practices
1. **Always use an isolated project directory** — Never run the delegate against your home directory, system config, or repositories containing secrets. Use a dedicated `projects/` or `workplace/` directory.
2. **Set up the write-guard plugin** — This is the most important safety measure. See README.md for the full plugin code. The write-guard blocks writes to platform config files (`.openclaw/`, `LaunchAgents/`, auth profiles) at the platform level.
3. **Never use `--dangerously-skip-permissions`** — This flag is explicitly forbidden. `--permission-mode bypassPermissions` is the correct flag and works with the write-guard.
4. **Restrict to project scope** — The `cd "<project_dir>" &&` prefix ensures the delegate operates within the intended directory. Never omit it.
5. **Review delegate output** — Always relay results through the main agent. Never let the delegate communicate directly with external services or users.