claude-delegate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude Delegate

Claude 委托机制

You are the orchestrator. Delegate one bounded coding task to a separate implementer — a Claude Code CLI session — then review what it produced and land it yourself. You write the brief and own the judgment; the separate Claude session edits the working tree; you verify and commit.
This skill is not a signal for the current Claude to implement directly. Use it only after the human explicitly asks for delegation to another Claude Code process or session.
你作为协调方,将一个限定范围的编码任务委托给独立的实现方——一个Claude Code CLI会话——然后审核其产出内容并自行完成提交。由你撰写任务简报并负责判断;独立的Claude会话负责修改工作树;你进行验证并提交。
该技能并非让当前Claude直接实现任务的信号。仅当用户明确要求委托给另一个Claude Code进程或会话时,才可使用该技能。

When not to use this

禁用场景

  • The human asked the current agent to implement the task directly.
  • The task is small enough to do inline and the human did not request delegation.
  • The
    claude
    CLI is missing or unauthenticated (
    claude auth status
    ).
  • The task needs a stronger host boundary than Claude Code's tool permissions and shell-only sandbox provide. Use an isolated container or VM for that requirement.
  • 用户要求当前Agent直接实现任务。
  • 任务规模小到可以直接完成,且用户未要求委托。
  • claude
    CLI缺失或未认证(执行
    claude auth status
    查看)。
  • 任务需要比Claude Code的工具权限和仅沙箱Shell更强的主机隔离边界。此类需求请使用独立容器或虚拟机。

Prerequisites

前置条件

  1. claude --version
    succeeds.
  2. claude auth status
    reports an authenticated session.
  3. The target repository is the directory passed with
    --cd
    .
  4. On Linux/WSL2, Claude's sandbox dependencies are installed. The normal relay profile is configured to fail when the sandbox is unavailable instead of silently running shell commands unsandboxed. Existing merged settings can still affect the effective boundary.
  1. claude --version
    执行成功。
  2. claude auth status
    显示已认证会话。
  3. 目标仓库是通过
    --cd
    参数指定的目录。
  4. 在Linux/WSL2系统中,已安装Claude沙箱依赖项。正常中继配置会在沙箱不可用时直接失败,而非静默运行未沙箱化的Shell命令。已合并的设置仍会影响实际隔离边界。

The loop

工作流程

1. Write the brief

1. 撰写任务简报

The separate session has no orchestrator chat history. It receives the brief on stdin and can inspect the target working tree.
Claude Code automatically discovers the target project's
CLAUDE.md
and normal local Claude configuration because the relay does not use
--bare
. It does not generically auto-load
AGENTS.md
. Read
AGENTS.md
yourself and copy every load-bearing constraint and the real gate commands into the brief. Tell the implementer not to commit. Keep one task per brief.
Template and details: references/writing-the-brief.md.
独立会话没有协调方的聊天历史。它会通过标准输入接收任务简报,并可检查目标工作树。
Claude Code会自动发现目标项目的
CLAUDE.md
和常规本地Claude配置,因为中继不会使用
--bare
参数。但它不会自动加载通用的
AGENTS.md
。你需要自行读取
AGENTS.md
,并将所有关键约束和实际验证命令复制到任务简报中。告知实现方不要提交。每份简报对应一个任务。
模板及详细说明:references/writing-the-brief.md

2. Dispatch

2. 分发任务

bash
node "<skill-dir>/scripts/relay.mjs" --brief brief.txt --cd /path/to/repo
bash
node "<skill-dir>/scripts/relay.mjs" --brief brief.txt --cd /path/to/repo

review/diagnosis only: add --read-only

仅用于审核/诊断: 添加 --read-only

continue the latest session: add --resume-last

继续最近的会话: 添加 --resume-last

continue the recorded session: add --session <id>

继续指定记录的会话: 添加 --session <id>

choose limits: add --max-turns 40 --max-budget-usd 10

设置限制: 添加 --max-turns 40 --max-budget-usd 10

hard relay deadline: add --timeout 2h

设置中继硬截止时间: 添加 --timeout 2h

inspect every option: node .../relay.mjs --help

查看所有选项: node .../relay.mjs --help


`<skill-dir>` is this installed skill directory, the folder containing this `SKILL.md`.

The relay runs `claude -p --output-format stream-json --verbose`, sends the brief through stdin, and
writes artifacts under the system temp directory by default. It never uses `--bg` or `--bare`, and it
never commits. See [references/dispatch-and-poll.md](references/dispatch-and-poll.md).

`<skill-dir>`是该已安装技能的目录,即包含此`SKILL.md`的文件夹。

中继会运行`claude -p --output-format stream-json --verbose`,通过标准输入发送任务简报,并默认将产物写入系统临时目录。它绝不会使用`--bg`或`--bare`参数,也绝不会执行提交操作。详情请见[references/dispatch-and-poll.md](references/dispatch-and-poll.md)。

3. Wait

3. 等待执行

The relay blocks until Claude exits. Use the orchestrator's background-command facility, or run it in the foreground and wait. Completion means the process exited and
result.json
exists.
  • A pre-run usage error exits 2 and writes no
    result.json
    .
  • A missing
    claude
    exits 127 and writes
    status: "claude_unavailable"
    .
  • Timeout and caught relay signals terminate the whole implementer process tree and preserve an outcome artifact.
Read
finalMessage
,
touchedFiles
,
resultSubtype
, and the raw artifact paths from
result.json
.
中继会阻塞直到Claude退出。可以使用协调方的后台命令功能,或在前台运行并等待。完成意味着进程已退出且
result.json
文件存在。
  • 预运行使用错误会以状态码2退出,且不会生成
    result.json
  • 缺失
    claude
    会以状态码127退出,并写入
    status: "claude_unavailable"
  • 超时和捕获到的中继信号会终止整个实现方进程树,并保留结果产物。
result.json
中读取
finalMessage
touchedFiles
resultSubtype
以及原始产物路径。

4. Review

4. 审核内容

Treat the implementer's report and gate outcomes as claims:
  • Review edits to existing tests before a green gate means anything.
  • Re-run the project's actual gates yourself.
  • Read the complete diff against the brief, starting with
    touchedFiles
    .
  • Inspect untracked and staged content as well as the ordinary diff.
  • Run relevant guard skills if installed.
Full checklist: references/review-and-land.md.
将实现方的报告和验证结果视为待确认的声明:
  • 在验证通过前,先审核对现有测试的修改。
  • 自行重新运行项目的实际验证流程。
  • 对照任务简报查看完整差异,从
    touchedFiles
    开始。
  • 除常规差异外,还要检查未跟踪和已暂存的内容。
  • 如果已安装相关防护技能,请运行它们。
完整检查清单:references/review-and-land.md

5. Land

5. 完成提交

The orchestrator commits only after the gates pass and the diff holds. For rework, resume the same Claude session with a delta brief:
bash
echo "Keep the implementation, replace the mocked DB test with the migrated fixture, and remove the
unused import." | node "<skill-dir>/scripts/relay.mjs" --session <id> --cd /path/to/repo
Review a resumed run exactly like the first run.
只有在验证通过且差异符合要求后,协调方才可执行提交。如需返工,请使用增量简报恢复同一个Claude会话:
bash
echo "保留现有实现,将模拟数据库测试替换为迁移后的测试夹具,并移除未使用的导入。" | node "<skill-dir>/scripts/relay.mjs" --session <id> --cd /path/to/repo
恢复后的运行审核流程与首次运行完全相同。

Permission profiles

权限配置文件

The normal profile is deliberately explicit:
  • acceptEdits
    permission mode.
  • Built-in tools restricted to Read, Glob, Grep, Edit, Write, and the platform shell.
  • On macOS, Linux, and WSL2, Claude's shell sandbox is enabled with startup failure on missing dependencies and no unsandboxed retry. Commands that stay sandboxed are auto-approved so ordinary gates can run headlessly. The sandbox governs shell processes and their children only; merged local or managed sandbox settings can add effective paths or exclusions.
  • Configured MCP discovery and Claude.ai connectors are disabled, all MCP tools are denied, and skills, commands, and Claude's Agent tool are unavailable to the child. Project
    CLAUDE.md
    , hooks, normal authentication, session persistence, and other local settings still load.
  • String rules deny common direct shell forms of
    git commit
    ,
    git push
    , and nested
    claude
    , plus any command containing
    claude-delegate
    . Aliases, scripts, and wrappers can bypass them, so they are only a speed bump; the brief's no-commit instruction and orchestrator review remain the boundary.
Native Windows does not support Claude's shell sandbox. The relay restricts the tool surface and pre-approves PowerShell so the run remains non-interactive, but that shell is not OS-isolated. Native
claude.exe
and npm
claude.cmd
launch paths are implemented; Windows verification is pending.
--read-only
uses
plan
mode with only Read, Glob, and Grep. It removes edit, write, and shell paths, then compares git porcelain before and after.
readOnlyViolation
is
true
when that snapshot changed,
false
when it did not, and
null
when git could not report. This is not an OS boundary: an edit inside an already-dirty file can leave porcelain unchanged, local hooks run outside the restricted tool surface, and unrelated host processes can write.
--dangerously-skip-permissions
is an explicit opt-in to Claude's
bypassPermissions
mode. The restricted tool surface, direct commit/push deny rules, and supported-platform shell sandbox remain, but direct file tools can cross normal permission boundaries. Use it only with the human's explicit acceptance.
常规配置文件设计得非常明确:
  • acceptEdits
    权限模式。
  • 内置工具限制为Read、Glob、Grep、Edit、Write以及平台Shell。
  • 在macOS、Linux和WSL2系统中,Claude的Shell沙箱已启用,若依赖项缺失则启动失败,且不会重试未沙箱化的操作。保持沙箱化的命令会自动批准,以便常规验证流程可以无头运行。沙箱仅管控Shell进程及其子进程;合并后的本地或托管沙箱设置可添加实际路径或排除项。
  • 已禁用配置的MCP发现和Claude.ai连接器,拒绝所有MCP工具,子进程无法使用技能、命令和Claude的Agent工具。项目的
    CLAUDE.md
    、钩子、常规认证、会话持久化及其他本地设置仍会加载。
  • 字符串规则禁止
    git commit
    git push
    和嵌套
    claude
    等常见直接Shell形式,以及任何包含
    claude-delegate
    的命令。别名、脚本和包装器可以绕过这些规则,因此它们只是一个防护措施;任务简报中的禁止提交指令和协调方审核仍是核心边界。
原生Windows不支持Claude的Shell沙箱。中继会限制工具范围并预先批准PowerShell,以保持运行非交互式,但该Shell并未进行系统隔离。已实现原生
claude.exe
和npm
claude.cmd
的启动路径;Windows验证仍在进行中。
--read-only
参数使用
plan
模式,仅允许Read、Glob和Grep操作。它会移除编辑、写入和Shell路径,然后比较前后的git状态。当快照发生变化时
readOnlyViolation
true
,未变化时为
false
,git无法报告时为
null
。这并非系统级边界:对已脏文件的编辑可能不会改变git状态,本地钩子会在受限工具范围外运行,无关的主机进程也可能写入内容。
--dangerously-skip-permissions
是明确选择启用Claude的
bypassPermissions
模式。受限工具范围、禁止直接提交/推送规则和支持平台的Shell沙箱仍然保留,但直接文件工具可以跨越常规权限边界。仅当用户明确同意时才可使用。

Complementary to native Claude features

与Claude原生功能的互补性

Claude subagents, agent teams, and background sessions are useful when the current Claude environment is already the orchestrator and native coordination is the goal. This skill is complementary: it provides a cross-orchestrator contract — self-contained brief → dispatch → artifacts → review → land — and keeps the commit with the orchestrator.
当当前Claude环境已作为协调方且目标是原生协作时,Claude子Agent、Agent团队和后台会话非常有用。本技能是一种补充:它提供跨协调方的约定——独立简报→任务分发→产物生成→审核→提交——并由协调方负责提交操作。

References

参考资料

  • references/writing-the-brief.md — context,
    CLAUDE.md
    versus
    AGENTS.md
    , real gates, report contract, and delta briefs.
  • references/dispatch-and-poll.md — flags, profiles, artifacts,
    result.json
    , polling, and failure recovery.
  • references/review-and-land.md — generated-code review, the commit boundary, and session rework.
  • references/multi-task-queues.md — sequential queues, progress tracking, constraint carry-forward, and final coherence.
  • references/writing-the-brief.md — 上下文信息、
    CLAUDE.md
    AGENTS.md
    的区别、实际验证流程、报告约定及增量简报。
  • references/dispatch-and-poll.md — 参数、配置文件、产物、
    result.json
    、轮询及故障恢复。
  • references/review-and-land.md — 生成代码审核、提交边界及会话返工。
  • references/multi-task-queues.md — 顺序任务队列、进度跟踪、约束传递及最终一致性。