Anthropic推荐的Claude Code工程循环:从「猜」变成「计划→检查→自我修复」 顶级工程师在让Claude Code碰仓库之前,都会先套一层完整的工程循环,而不是直接说“fix this bug”。 🔎核心拆成两层: 1. 循环——保证单个任务正确 ・产出 → 检查 → 修正 → 重复直到通过 ・最关键的是先写好「可失败的检查条件」,而不是先干活再让另一个模型来看 ・没有真正能失败的检查,就只是调度器,不是循环 2. 图——决定任务怎么拆、怎么并行 ・节点 = 一个有边界的工作单元 ・边 = 真正有数据流动的依赖 ・很多“然后”其实是假边,删掉后速度直接翻倍 ・循环住在节点内部,图负责节点之间的拆分、并行、合并和回流 额外关键原则: ・只返回失败的那个单元,不要把整个批次打回去 ・用「出错代价」而不是「模型自信度」决定是否放行 ・有两条回流路径:短的修正当前运行,长的把约束写回拆分规则,让系统越跑越聪明 下图是完整的图工程指南
完整内容(AI 读出来的中文全文)
作者 牧枫 @mr_mofun
原文 ``` Anthropic推荐的Claude Code工程循环:从「猜」变成「计划→检查→自我修复」
顶级工程师在让Claude Code碰仓库之前,都会先套一层完整的工程循环,而不是直接说“fix this bug”。
🔎核心拆成两层:
1. 循环——保证单个任务正确
・产出 → 检查 → 修正 → 重复直到通过 ・最关键的是先写好「可失败的检查条件」,而不是先干活再让另一个模型来看 ・没有真正能失败的检查,就只是调度器,不是循环
2. 图——决定任务怎么拆、怎么并行
・节点 = 一个有边界的工作单元 ・边 = 真正有数据流动的依赖 ・很多“然后”其实是假边,删掉后速度直接翻倍 ・循环住在节点内部,图负责节点之间的拆分、并行、合并和回流
额外关键原则:
・只返回失败的那个单元,不要把整个批次打回去 ・用「出错代价」而不是「模型自信度」决定是否放行 ・有两条回流路径:短的修正当前运行,长的把约束写回拆分规则,让系统越跑越聪明
下图是完整的图工程指南 ``` 译文:原文为中文
配图 一张米色底的文档页:左上角橙色星标旁写着 Claude,中间是标题与编号公式,下方灰框是一段模板,页脚有 Listing 说明。图中可读文字如下:
Claude
A Unified Framework for Self-Verifying Agent Loops in Claude Code
Let T denote the target task, M the model and H the harness around it. We construct a standardized agent loop as follows. Each component removes one way the agent fails without anyone noticing:
Context is fixed before any work starts, so every run reads the same ground rules:
S = CLAUDE.md ⊕ rules(T) (1)
The task is decomposed into k ordered, atomic steps:
I = {i₁, i₂, …, iₖ}, k ≤ 7 (2)
Each step is owned by exactly one builder subagent:
aⱼ = builder(iⱼ | S), j = 1,…,k (3)
Verification is external to the builder and never self-graded:
vⱼ = verify(aⱼ) ∈ {pass, fail} (4)
Failed steps are retried with the error in context, at most three times:
aⱼᵗ⁺¹ = M(P, aⱼᵗ, error(aⱼᵗ)), t ≤ 3 (5)
State persists outside the chat window between steps:
progress.md ← progress.md ∪ {(iⱼ, vⱼ)} (6)
Any failure seen twice is promoted into a permanent rule:
CLAUDE.mdₙ₊₁ = CLAUDE.mdₙ ⊕ rule(fail) (7)
The complete harness is the ordered concatenation of all components:
H = S ⊕ I ⊕ A ⊕ V ⊕ R (8)
The loop terminates once every step has passed or is marked blocked:
∀j : vⱼ = pass ∨ blocked(iⱼ) (9)
The resulting template, applied verbatim:
<role>You are a senior {{FIELD}} engineer in Claude Code.</role> <context>Read CLAUDE.md and progress.md first.</context> <instructions> 1. Split the task into at most 7 steps. 2. One subagent builds, another runs verify. 3. Max 3 fixes per step, then mark it blocked. 4. Turn every repeated failure into a rule. </instructions> <format>Done only when verify passes.</format>
Listing 1: Canonical harness structure, H = S ⊕ I ⊕ A ⊕ V ⊕ R
要点 - Anthropic推荐的Claude Code工程循环,是从「猜」变成「计划→检查→自我修复」。 - 顶级工程师会在让Claude Code碰仓库之前先套完整工程循环,而不是直接说“fix this bug”。 - 核心拆成两层:循环保证单个任务正确,图决定任务怎么拆、怎么并行。