Anthropic 的 Claude Code 负责人 Boris Cherny 刚刚在 Opus 5.5 发布前分享了一条官方建议 再给提示词之前,Claude Code 需要先有一个失败的测试 Anthropic 在其 Claude Code 最佳实践中将验证放在首位 为你的 GitHub 仓库进行配置很简单 给 Claude 项目规则、一个可复现的失败,以及一种检查自身修复结果的方法 下面图示中的结账示例让这件事变得具体 预期总额 10800 美分 实际总额 11000 美分 计算时先计税,再减去折扣 你只需在仓库中打开 Claude Code: claude 具体分工如下: → CLAUDE.md 提供约束条件——以整数美分表示金额、先折扣后计税、只做针对性修改、先做回归检查再运行完整测试套件 → Read 和 Grep 定位计算逻辑、调用它的位置以及现有的结账测试 → Edit 在一个文件中修改计税基数,而不是重写结账模块 → Bash 重新运行失败用例,然后检查折扣、计税顺序、舍入以及测试套件的其余部分 你不用再反复解释同一个 bug,因为这个会话已经有了一个明确的目标结果 人工审查有三个问题: → 测试是否复现了原始失败 → 补丁是否修复了计算逻辑,且没有无关修改 → 最终 diff 是否与测试证据一致 上下文负责解释 · 工具负责修改 · 测试负责验证 有趣的是,一旦理解了失败原因,最终补丁就会变得非常小 在这个演示中,删除的一行变成了两行,先减去折扣,再计税 16 项检查通过 1 个文件发生更改 结账总额变成 10800 美分 完整工作流程 阅读项目规则 定位计算逻辑及其调用位置 复现错误总额 修改计税基数 重新运行回归测试 运行其余检查 展示 diff 和执行证据 把这段粘贴到 Claude Code 中 ↓ "调查此仓库中结账总额不一致的问题 阅读 CLAUDE.md 以及相关实现、调用位置和测试 先复现失败,并解释计算错误 在编辑前展示你建议的修复方案,等待我的批准 获得批准后,做出最小且正确的补丁 金额保持使用整数美分,并在计税前应用折扣 添加或更新一个在原始实现上会失败的回归测试 运行该测试,然后运行相关测试套件 返回最终 diff、执行过的命令、测试结果以及任何尚存的不确定性 不要提交或推送" ↳ https://code.claude.com/docs/en/best-practices 在下次开始“修复这个 bug”的会话前,先收藏这条
看原文
Boris Cherny, Head of Claude Code at Anthropic, just shared an official tip before Opus 5.5 ships Claude Code needs a failing test before another prompt Anthropic puts verification first in its Claude Code best practices The setup for your GitHub repo is simple Give Claude the project rules, a reproducible failure, and a way to check its own fix The illustrated checkout example below makes it concrete Expected total 10800 cents Actual total 11000 cents The calculation applies tax before subtracting the discount You just open Claude Code inside your repository: claude here's the split: → CLAUDE.md supplies the constraints — integer cents, discount before tax, focused edits, regression checks before the full suite → Read and Grep locate the calculation, its callers, and the existing checkout tests → Edit changes the taxable base in one file instead of rewriting the checkout module → Bash reruns the failing case, then checks discounts, tax ordering, rounding, and the rest of the suite You stop explaining the same bug repeatedly because the session has an exact result to work toward The human review has three questions: → did the test reproduce the original failure → does the patch fix the calculation without unrelated changes → does the final diff agree with the test evidence Context explains · Tools change · Tests verify The interesting part is how small the final patch becomes once the failure is understood In this demo, one removed line becomes two lines that subtract the discount before applying tax 16 checks pass 1 file changes The checkout total becomes 10800 cents the full workflow Read the project rules Locate the calculation and its callers Reproduce the incorrect total Change the taxable base Rerun the regression Run the remaining checks Present the diff and execution evidence paste this into Claude Code ↓ "Investigate the checkout total mismatch in this repository Read CLAUDE.md and the relevant implementation, callers, and tests First reproduce the failure and explain the calculation error Show your proposed fix before editing and wait for my approval After approval, make the smallest correct patch Keep money in integer cents and apply discounts before tax Add or update a regression test that fails on the original implementation Run that test, then the relevant suite Return the final diff, commands executed, test results, and any remaining uncertainty Do not commit or push" ↳ https://code.claude.com/docs/en/best-practices bookmark this before your next “fix this bug” session