chain-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chain Patterns

链式模式

Overview

概述

Foundation patterns for CC 2.1.71 pipeline skills. This skill is loaded via the
skills:
frontmatter field — it provides patterns that parent skills follow.
CC 2.1.71流水线Skill的基础模式。该Skill通过
skills:
前置字段加载——它提供父Skill遵循的模式。

Pattern 1: MCP Detection (ToolSearch Probe)

模式1:MCP检测(ToolSearch探测)

Run BEFORE any MCP tool call. Probes are parallel and instant.
python
undefined
在任何MCP工具调用之前运行。探测是并行且即时的。
python
undefined

FIRST thing in any pipeline skill — all in ONE message:

FIRST thing in any pipeline skill — all in ONE message:

ToolSearch(query="select:mcp__memory__search_nodes") ToolSearch(query="select:mcp__context7__resolve-library-id") ToolSearch(query="select:mcp__sequential-thinking__sequentialthinking")
ToolSearch(query="select:mcp__memory__search_nodes") ToolSearch(query="select:mcp__context7__resolve-library-id") ToolSearch(query="select:mcp__sequential-thinking__sequentialthinking")

Store results for all phases:

Store results for all phases:

Write(".claude/chain/capabilities.json", JSON.stringify({ "memory": true_or_false, "context7": true_or_false, "sequential": true_or_false, "timestamp": "ISO-8601" }))

**Usage in phases:**
```python
Write(".claude/chain/capabilities.json", JSON.stringify({ "memory": true_or_false, "context7": true_or_false, "sequential": true_or_false, "timestamp": "ISO-8601" }))

**各阶段用法:**
```python

BEFORE any mcp__memory__ call:

BEFORE any mcp__memory__ call:

if capabilities.memory: mcp__memory__search_nodes(query="...")
if capabilities.memory: mcp__memory__search_nodes(query="...")

else: skip gracefully, no error

else: skip gracefully, no error


Load details: `Read("${CLAUDE_SKILL_DIR}/references/mcp-detection.md")`

加载详情:`Read("${CLAUDE_SKILL_DIR}/references/mcp-detection.md")`

Pattern 2: Handoff Files

模式2:交接文件

Write structured JSON after every major phase. Survives context compaction and rate limits.
python
Write(".claude/chain/NN-phase-name.json", JSON.stringify({
  "phase": "rca",
  "skill": "fix-issue",
  "timestamp": "ISO-8601",
  "status": "completed",
  "outputs": { ... },           # phase-specific results
  "mcps_used": ["memory"],
  "next_phase": 5
}))
Location:
.claude/chain/
— numbered files for ordering, descriptive names for clarity.
Load schema:
Read("${CLAUDE_SKILL_DIR}/references/handoff-schema.md")
在每个主要阶段后写入结构化JSON。可在上下文压缩和速率限制下保留数据。
python
Write(".claude/chain/NN-phase-name.json", JSON.stringify({
  "phase": "rca",
  "skill": "fix-issue",
  "timestamp": "ISO-8601",
  "status": "completed",
  "outputs": { ... },           # phase-specific results
  "mcps_used": ["memory"],
  "next_phase": 5
}))
存储位置:
.claude/chain/
— 编号文件用于排序,描述性名称提升可读性。
加载Schema:
Read("${CLAUDE_SKILL_DIR}/references/handoff-schema.md")

Pattern 3: Checkpoint-Resume

模式3:断点续传

Read state at skill start. If found, skip completed phases.
python
undefined
在Skill启动时读取状态。如果找到状态,则跳过已完成的阶段。
python
undefined

FIRST instruction after MCP probe:

FIRST instruction after MCP probe:

Read(".claude/chain/state.json")
Read(".claude/chain/state.json")

If exists and matches current skill:

If exists and matches current skill:

→ Read last handoff file

→ Read last handoff file

→ Skip to current_phase

→ Skip to current_phase

→ Tell user: "Resuming from Phase N"

→ Tell user: "Resuming from Phase N"

If not exists:

If not exists:

Write(".claude/chain/state.json", JSON.stringify({ "skill": "fix-issue", "started": "ISO-8601", "current_phase": 1, "completed_phases": [], "capabilities": { ... } }))
Write(".claude/chain/state.json", JSON.stringify({ "skill": "fix-issue", "started": "ISO-8601", "current_phase": 1, "completed_phases": [], "capabilities": { ... } }))

After each major phase:

After each major phase:

Update state.json with new current_phase and append to completed_phases

Update state.json with new current_phase and append to completed_phases


Load protocol: `Read("${CLAUDE_SKILL_DIR}/references/checkpoint-resume.md")`

加载协议:`Read("${CLAUDE_SKILL_DIR}/references/checkpoint-resume.md")`

Pattern 4: Worktree-Isolated Agents

模式4:工作树隔离Agent

Use
isolation: "worktree"
when spawning agents that WRITE files in parallel.
python
undefined
当生成可并行写入文件的Agent时,使用
isolation: "worktree"
python
undefined

Agents editing different files in parallel:

Agents editing different files in parallel:

Agent( subagent_type="backend-system-architect", prompt="Implement backend for: {feature}...", isolation="worktree", # own copy of repo run_in_background=true )

**When to use worktree:** Agents with Write/Edit tools running in parallel.
**When NOT to use:** Read-only agents (brainstorm, assessment, review).

Load details: `Read("${CLAUDE_SKILL_DIR}/references/worktree-agent-pattern.md")`
Agent( subagent_type="backend-system-architect", prompt="Implement backend for: {feature}...", isolation="worktree", # own copy of repo run_in_background=true )

**何时使用工作树:** 带有Write/Edit工具且并行运行的Agent。
**何时不使用:** 只读Agent(头脑风暴、评估、评审)。

加载详情:`Read("${CLAUDE_SKILL_DIR}/references/worktree-agent-pattern.md")`

Pattern 5: CronCreate Monitoring

模式5:CronCreate监控

Schedule post-completion health checks that survive session end.
python
undefined
安排可在会话结束后继续运行的完成后健康检查。
python
undefined

Guard: Skip cron in headless/CI (CLAUDE_CODE_DISABLE_CRON)

Guard: Skip cron in headless/CI (CLAUDE_CODE_DISABLE_CRON)

if env CLAUDE_CODE_DISABLE_CRON is set, run a single check instead

if env CLAUDE_CODE_DISABLE_CRON is set, run a single check instead

CronCreate( schedule="*/5 * * * *", prompt="Check CI status for PR #{number}: Run: gh pr checks {number} --repo {repo} All pass → CronDelete this job, report success. Any fail → alert with failure details." )

Load patterns: `Read("${CLAUDE_SKILL_DIR}/references/cron-monitoring.md")`
CronCreate( schedule="*/5 * * * *", prompt="Check CI status for PR #{number}: Run: gh pr checks {number} --repo {repo} All pass → CronDelete this job, report success. Any fail → alert with failure details." )

加载模式:`Read("${CLAUDE_SKILL_DIR}/references/cron-monitoring.md")`

Pattern 6: Progressive Output (CC 2.1.76)

模式6:渐进式输出(CC 2.1.76)

Launch agents with
run_in_background=true
and output results as each returns — don't wait for all agents to finish. Gives ~60% faster perceived feedback.
python
undefined
使用
run_in_background=true
启动Agent,在每个Agent返回结果时立即输出——无需等待所有Agent完成。可将感知反馈速度提升约60%。
python
undefined

Launch all agents in ONE message with run_in_background=true

Launch all agents in ONE message with run_in_background=true

Agent(subagent_type="backend-system-architect", prompt="...", run_in_background=true, name="backend") Agent(subagent_type="frontend-ui-developer", prompt="...", run_in_background=true, name="frontend") Agent(subagent_type="test-generator", prompt="...", run_in_background=true, name="tests")
Agent(subagent_type="backend-system-architect", prompt="...", run_in_background=true, name="backend") Agent(subagent_type="frontend-ui-developer", prompt="...", run_in_background=true, name="frontend") Agent(subagent_type="test-generator", prompt="...", run_in_background=true, name="tests")

As each agent completes, output its findings immediately.

As each agent completes, output its findings immediately.

CC delivers background agent results as notifications —

CC delivers background agent results as notifications —

present each result to the user as it arrives.

present each result to the user as it arrives.

If any agent scores below threshold, flag it before others finish.

If any agent scores below threshold, flag it before others finish.


**Key rules:**
- Launch ALL independent agents in a single message (parallel)
- Output each result incrementally — don't batch
- Flag critical findings immediately (don't wait for stragglers)
- Background bash tasks are killed at 5GB output (CC 2.1.77) — pipe verbose output to files

**核心规则:**
- 在单条消息中启动所有独立Agent(并行执行)
- 逐步输出每个结果——不要批量等待
- 立即标记关键问题(不要等待滞后的Agent)
- 后台bash任务在输出达到5GB时会被终止(CC 2.1.77)——将详细输出管道到文件

Pattern 7: SendMessage Agent Resume (CC 2.1.77)

模式7:SendMessage Agent续传(CC 2.1.77)

Continue a previously spawned agent using
SendMessage
. CC 2.1.77 auto-resumes stopped agents — no error handling needed.
python
undefined
使用
SendMessage
继续之前生成的Agent。CC 2.1.77会自动恢复已停止的Agent——无需错误处理。
python
undefined

Spawn agent

Spawn agent

Agent(subagent_type="backend-system-architect", prompt="Design the API schema", name="api-designer")
Agent(subagent_type="backend-system-architect", prompt="Design the API schema", name="api-designer")

Later, continue the same agent with new context

Later, continue the same agent with new context

SendMessage(to="api-designer", content="Now implement the schema you designed")
SendMessage(to="api-designer", content="Now implement the schema you designed")

CC 2.1.77: SendMessage auto-resumes stopped agents.

CC 2.1.77: SendMessage auto-resumes stopped agents.

No need to check agent state or handle "agent stopped" errors.

No need to check agent state or handle "agent stopped" errors.

NEVER use Agent(resume=...) — removed in 2.1.77.

NEVER use Agent(resume=...) — removed in 2.1.77.

undefined
undefined

Pattern 8: /loop Skill Chaining (CC 2.1.71)

模式8:/loop Skill链式调用(CC 2.1.71)

/loop
runs a prompt or skill on a recurring interval — session-scoped, dies on exit, 3-day auto-expiry. Unlike
CronCreate
(agent-initiated),
/loop
is user-invoked and can chain other skills.
text
undefined
/loop
可按重复间隔运行提示或Skill——会话作用域,退出时终止,3天后自动过期。与
CronCreate
(由Agent发起)不同,
/loop
由用户调用且可链式调用其他Skill。
text
undefined

User types these — skills suggest them in "Next Steps"

User types these — skills suggest them in "Next Steps"

/loop 5m gh pr checks 42 # Watch CI after push /loop 20m /ork:verify authentication # Periodic quality gate /loop 10m npm test -- --coverage # Coverage drift watch /loop 1h check deployment health at /api/health # Post-deploy monitor

**Key difference from CronCreate:**
- `/loop` can invoke skills: `/loop 20m /ork:verify` (CronCreate can't)
- Both use the same underlying scheduler (50-task limit, 3-day expiry)
- Skills use `CronCreate` for agent-initiated scheduling
- Skills suggest `/loop` in "Next Steps" for user-initiated monitoring

**When to suggest /loop in Next Steps:**
- After creating a PR → `/loop 5m gh pr checks {pr_number}`
- After running tests → `/loop 10m npm test`
- After deployment → `/loop 1h check health at {endpoint}`
- After verification → `/loop 30m /ork:verify {scope}`
/loop 5m gh pr checks 42 # Watch CI after push /loop 20m /ork:verify authentication # Periodic quality gate /loop 10m npm test -- --coverage # Coverage drift watch /loop 1h check deployment health at /api/health # Post-deploy monitor

**与CronCreate的核心区别:**
- `/loop`可调用Skill:`/loop 20m /ork:verify`(CronCreate不支持)
- 两者使用相同的底层调度器(50任务限制,3天过期)
- Skill使用`CronCreate`进行Agent发起的调度
- Skill在「下一步」中建议用户使用`/loop`进行用户发起的监控

**何时在「下一步」中建议使用/loop:**
- 创建PR后 → `/loop 5m gh pr checks {pr_number}`
- 运行测试后 → `/loop 10m npm test`
- 部署后 → `/loop 1h check health at {endpoint}`
- 验证后 → `/loop 30m /ork:verify {scope}`

Rules

规则

RuleImpactKey Pattern
rules/probe-before-use.md
HIGHAlways ToolSearch before MCP calls
rules/handoff-after-phase.md
HIGHWrite handoff JSON after every major phase
rules/checkpoint-on-gate.md
MEDIUMUpdate state.json at every user gate
规则影响级别核心模式
rules/probe-before-use.md
调用MCP前必须执行ToolSearch
rules/handoff-after-phase.md
每个主要阶段后写入交接JSON
rules/checkpoint-on-gate.md
在每个用户交互节点更新state.json

References

参考资料

Load on demand with
Read("${CLAUDE_SKILL_DIR}/references/<file>")
:
FileContent
mcp-detection.md
ToolSearch probe pattern + capability map
handoff-schema.md
JSON schema for
.claude/chain/*.json
checkpoint-resume.md
state.json schema + resume protocol
worktree-agent-pattern.md
isolation: "worktree"
usage guide
cron-monitoring.md
CronCreate patterns for post-task health
progressive-output.md
Progressive output with run_in_background
sendmessage-resume.md
SendMessage auto-resume (CC 2.1.77)
tier-fallbacks.md
T1/T2/T3 graceful degradation
通过
Read("${CLAUDE_SKILL_DIR}/references/<file>")
按需加载:
文件内容
mcp-detection.md
ToolSearch探测模式 + 能力映射
handoff-schema.md
.claude/chain/*.json
的JSON Schema
checkpoint-resume.md
state.json Schema + 续传协议
worktree-agent-pattern.md
isolation: "worktree"
使用指南
cron-monitoring.md
任务后健康检查的CronCreate模式
progressive-output.md
结合run_in_background的渐进式输出
sendmessage-resume.md
SendMessage自动续传(CC 2.1.77)
tier-fallbacks.md
T1/T2/T3优雅降级

Related Skills

相关Skill

  • ork:implement
    — Full-power feature implementation (primary consumer)
  • ork:fix-issue
    — Issue debugging and resolution pipeline
  • ork:verify
    — Post-implementation verification
  • ork:brainstorm
    — Design exploration pipeline
  • ork:implement
    — 全功能特性实现(主要使用者)
  • ork:fix-issue
    — 问题调试与解决流水线
  • ork:verify
    — 实现后验证
  • ork:brainstorm
    — 设计探索流水线