跳到正文
小马哥的博客
返回

给 Claude 反馈环

来源:https://academy.claude.com/courses/ai-native-sdlc-playbook/give-claude-a-feedback-loop 读这篇之前:可直接读;07 的 verifier subagent 不要跟这课搞混 不确定:ZH 是 Clint 译官方英文课体,不是 Anthropic 中文。

本课词汇

English中文怎么记
feedback loop反馈环任务全程可反复跑的自检:测试、构建、截图
verifier subagent验证子代理活干完后开新上下文做终检
screenshot diff截图对比UI 活让 Claude 看见结果

对照正文

先让它自己验 / Let it check itself

EN Always give Claude a way to verify its own work, whether tests, a build, or a screenshot diff. A session checks its own work and fixes its own mistakes before an engineer sees them.

ZH 永远给 Claude 一条自检的路:测试、构建、或截图对比。会话自己查、自己改错,工程师再看到。

EN The feedback loop should not be confused with a verifier subagent (Stage 3: Build). The feedback loop runs through the whole task as many times as the work requires. The verifier subagent, on the other hand, is one way to package the final check by running a fresh context window once the session believes the work is done. This way the verdict is not colored by the assumptions that produced the code.

ZH 别把反馈环跟 verifier subagent(Stage 3: Build)搞混。反馈环贯穿整件任务,需要跑几遍就几遍。Verifier subagent 是另一种包装终检的方式:会话自以为干完后,开一扇新的上下文窗口。这样结论不会被写出代码时的假设染色。

什么变了 / What changes

EN

TraditionalAI-native
The signal that code works arrives late. CI minutes later, a tester days later, production weeks later. With an agent producing the code, a late signal means a person has to check all of its output, and that person becomes the bottleneck.The session is given a way to check its own work before a person sees it. Run the tests, run the build, take the screenshot. Claude iterates until the check passes, so what reaches the engineer has already passed it. Setting the loop up falls to the engineer running the session, and the steps below are written for them.

ZH

传统AI-native
「代码能用」的信号来得晚。CI 几分钟后,测试人员几天后,生产几周后。代码是 agent 产的,信号晚到意味着人得查完全部产出,人就成了瓶颈。会话在人看到之前有办法自检。跑测试、跑构建、截图。Claude 迭代到检查通过,到工程师手里的已经过关。把环搭起来是跑会话的工程师的事,下面步骤写给他们。

怎么起步 / Getting started

EN Prerequisites: None.

Infrastructure: A test suite and a build that run locally with one command each. For the UI work, a way for Claude to see the result is crucial, either a browser tool or a screenshot utility wired in via MCP.

ZH 先决条件:无。

基础设施:测试套件和构建,本地各一条命令能跑。做 UI 时,Claude 得看见结果:浏览器工具,或经 MCP 接上的截图工具。

怎么做 / How to execute it

EN 1. If checking the work today takes a sequence of commands and some environment knowledge, wrap it in a single target such as make test or npm test that exits non-zero on failure.

ZH 1. 如果今天验收要一串命令加一点环境知识,包成一个目标,失败就非零退出。

EN 2. In the CLAUDE.md’s Commands section, list each command with an example of a healthy output.

ZH 2. 在 CLAUDE.md 的 Commands 一节列出每条命令,并给一段健康输出的样子。

EN 3. State a target and make it quantifiable so Claude can check the work without asking you, for example: “All tests in test_status.py pass,” “the screenshot matches the attached mock,” or “the endpoint returns 200 with the new field.”

ZH 3. 把目标说成可量化的,Claude 才不用问你。

EN 4. For bug fixes, write the failing test first. Ask Claude to reproduce the bug as a test, run it, and confirm it fails for the reason you expect. Commit that test. Only then ask Claude to make it pass without editing the test, with the test-file hook from the final step enforcing the restriction. A test that existed before the fix, and that the agent couldn’t rewrite, is proof the bug is gone.

ZH 4. 修缺陷:先写失败测试并提交,再让它通过且不准改测试。

EN 5. For UI work, close the loop with a visual check. Give Claude a browser or screenshot tool, give it the mock, and let it iterate. Implement, screenshot, compare, and adjust. Two or three rounds is normal, and the result should improve with each one.

ZH 5. UI 活用视觉检查闭合:实现、截图、对比、调整,两三轮正常。

EN 6. Make verification part of “done.” The instruction lives in CLAUDE.md: “Run the tests before reporting a task complete, and show the output.”

ZH 6. 把验收写进做完:报告完成前先跑测试并贴输出。

EN 7. Finally, the loop itself needs protecting, because an agent fixing code must not be able to weaken the check on that code. A hook that blocks edits to test files during a fix task does this. The alternative is to check the diff in review and reject any change that touches a test.

ZH 7. 保护这个环:修代码时不准削弱检查;可用 hook 拦住改测试文件,或审查时拒碰测试的 diff。

长什么样 / What it looks like

EN CLAUDE.md verification block:

ZH CLAUDE.md 验收块:

## Verifying your work

- Build: make build (must finish with "Build succeeded")
- Test: make test (all green; never skip or delete a failing test)
- Lint: make lint (zero warnings)

Run all three before reporting any task complete, and paste the output.
If a test fails, fix the code, not the test.

ZH 官方示例,保持英文。报告完成前跑构建、测试、lint;测试失败改代码,不改测试。

治理 / Governance considerations

EN What is enforced: Verification before a task is reported done, and the block on the agent editing test files during a fix, both implemented as hooks where the organization wants them guaranteed.

ZH 强制什么:报告完成前先验收;修缺陷时拦住 agent 改测试文件。组织要保证的,做成 hooks。

EN What the evidence is: The literal output of make test, the build log, or the screenshot diff that Claude ran and pasted, so the evidence comes from the toolchain.

ZH 证据是什么:Claude 跑完贴出来的测试命令原文、构建日志、或截图对比。证据来自工具链。

EN Where it is logged: In the session transcript, which the OpenTelemetry export forwards to the organization’s observability stack, and in the PR’s check run, where the reviewer and any later auditor can both see it.

ZH 记在哪:会话记录(OpenTelemetry 转到组织可观测栈),以及 PR 的 check run,审查者和后来的审计都能看。

EN Who approves: The code owner reviewing the PR, who can concentrate on intent and risk because the mechanical evidence is already attached.

ZH 谁批:审 PR 的 code owner。机械证据已经附上,人可以盯意图和风险。

怎么衡量 / How to measure it

EN Leading indicator: First-pass CI success rate for agent-written changes, which the CI system already supports.

ZH 领先指标:agent 写的改动第一次过 CI 的成功率,CI 系统已经能给。

EN Lagging indicator: Review time per PR (from the PR metadata), which should fall once the tests catch what reviewers used to catch, and the change failure rate from an incident tracker.

ZH 滞后指标:每个 PR 的审查时间(PR 元数据),测试开始抓住审查者以前才抓的东西之后应下降;以及事故追踪里的变更失败率。

读完能记住的三句话

EN Give Claude a one-command check. What reaches you should already have passed it. ZH 给 Claude 一条命令就能跑的检查。到你手里的应该已经过关。

EN The feedback loop is not the verifier subagent. The loop runs throughout; the verifier is a fresh final check. ZH 反馈环不是 verifier subagent。环贯穿全程;verifier 是开新窗口做终检。

EN Protect the loop: an agent fixing code must not be able to weaken the test. ZH 保护这个环:修代码的 agent 不能削弱测试。


分享这篇文章:

上一篇
并行会话和 subagent
下一篇
CI 里持续做 eval