外部精选
The new rules of context engineering for Claude 5 generation models
本文来自外部来源,不是黄奕彬的原创文章。本站提供原文入口,并在采集端生成 AI 结构化摘要、解读与中文翻译(如有),一切以原文为准。
阅读原文(claude.dev)结构化摘要 AI 生成
背景与问题
面向使用 Claude Code 或自建 agent 的开发者。问题:发给 Claude 的 prompt 只占其上下文的一小部分,大量上下文由 system prompt、Skills、CLAUDE.md、memory 等拼装而成(即 context engineering)。
上下文需跨多次请求通用,无法像单条 prompt 那样具体;且模型能力演进使旧的 context engineering 实践失效,如何为未知的用户 prompt 构建通用指导成为难点。
方法或内容
文章总结 Anthropic 在 Claude Code 上的内部实践:为 Claude Opus 5、Claude Fable 5 等 5 代模型大幅精简上下文,梳理出 6 组 Then/Now 新旧实践对比:规则→判断力、示例→接口设计、全部前置→渐进式披露、重复指令→简洁工具描述、CLAUDE.md 手动记忆→自动记忆、简单 spec→丰富引用。
并给出 system prompt、CLAUDE.md、Skills、References 四类上下文的落地建议,发布 claude doctor(Claude Code 内 /doctor)帮助自动精简。
关键发现 / 结果
- 移除 Claude Code 系统提示超 80%(针对 Claude Opus 5、Claude Fable 5 等),在其编码评测上无可测损失
- 注释规则从「默认不写注释、最多一行」改为「写出与周围代码一致的代码:匹配其注释密度、命名与惯用法」
- 验证与 code review 从系统提示移入可按需调用的 skills
- 部分工具改为 deferred loading,需经
ToolSearch检索完整定义后才能使用(如 Task tools),不用时不占用上下文 - 记忆从用户按
#热键手动写入CLAUDE.md改为 Claude 自动保存相关记忆 - 引用载体从 markdown 文件扩展到 HTML artifacts、详细测试套件或可移植函数、rubrics + verifier agents
结论与意义
结论:新一代模型判断力更强,应删减过度约束,让模型依据周围上下文自行判断。CLAUDE.md 保持轻量、token 主要花在代码库 gotchas 上;Skills 做渐进式披露并拆分文件;References 优先用代码文件(HTML mockup 优于文字描述或截图)。
边界:结论针对 Claude 5 代模型与 Claude Code 场景;自建 agent harness 的 system prompt 仍需投入大量精力。
AI 解读 AI 生成
方法:按「时空变量」分析(时间 / 空间 / 变量,严格区分包含、相关与因果),对象包括原文作者、署名人员与关键技术及其实际原理;结论用「元反空」(元思考、反思考、空思考、综合)整理。
时间:何时发生,现在是否仍成立
来源日期为 2026-07-24 20:00(北京时间,Asia/Shanghai)。主张针对 Claude Opus 5、Claude Fable 5 等 5 代模型及当时的 Claude Code 形态。
原文自身承认上一代最佳实践已成 myth,暗示新规则同样可能随模型继续演进而失效;「无可测损失」基于其内部编码评测,评测细节与时间跨度原文未说明,后续是否仍成立无法判断。
空间:谁的环境 / 场景
适用环境:Claude Code(涉及 CLAUDE.md、Skills、memory、artifacts、plan mode、/doctor)以及自建 agent harness 的开发者。涉及模型:Claude Opus 5、Claude Fable 5 等 Claude 5 代模型。
明确不适用于旧模型:原文说明旧模型没有这些 guardrails 时注释会大量出错,当时只能接受该折中。价格、部署形态原文未说明。
变量:实际改变了什么
- Claude Code 系统提示删减超 80%
- 注释类硬规则改为「匹配周围代码风格」的软指导
- 工具使用说明从「系统提示与工具描述重复出现」改为只放在工具描述中
- 记忆从用户手动
#写入CLAUDE.md改为模型自动保存 - plan/spec 载体从 markdown 文件扩展到 HTML artifacts、测试套件、rubrics
- 新增
claude doctor命令;工具支持 deferred loading(ToolSearch)
区分:包含 ≠ 相关 ≠ 因果
有明确因果表述的:给示例会把模型约束到特定探索空间(作者断言);旧模型无 guardrails 时注释在很多情况下会出错;相互冲突的指令使 Claude 必须更谨慎思考后才能决策(原文直接陈述)。属包含/结构关系而非因果的:system prompt、Skills、CLAUDE.md、memory 是上下文的组成部分。
属相关性或经验陈述而非严格因果证明的:删减 80% 系统提示与编码评测无可测损失(仅内部评测);HTML mockup「一般」比描述或截图产生更好结果。
对象:作者/署名与关键技术原理
署名作者(仅取自结构化作者字段):Thariq Shihipar(该字段重复出现两次)。关键技术及原文描述的原理:
- context engineering:prompt 只是一小部分,上下文由 system prompt、Skills、
CLAUDE.md、memory 等拼装,跨请求通用 - progressive disclosure:在合适时机加载合适上下文;部分工具 deferred loading,经
ToolSearch获取完整定义 - auto-memory:Claude 自动保存与工作及用户相关的记忆
- artifacts:Claude 可引用其生成的 HTML artifacts 作为丰富参考
- rubrics + verifier agents:用动态工作流启动校验代理,验证特定领域的「品味」(如好的 API 设计)
claude doctor//doctor:自动精简 skills 与CLAUDE.md的命令
元反空综合结论
元:本质在解决「通用上下文如何随模型能力升级重新分配控制权」——从人写死规则转向模型判断力加按需加载的结构设计。
反:最可能失效或有边界的部分:a)「让 Claude 用判断力」绑定 5 代模型能力,换旧模型或安全关键场景即不成立;b)「无可测损失」仅覆盖其内部编码评测,其它任务类型未验证;c) Then/Now 结论来自内部使用转录的归纳,原文未给出受控实验或量化数据。
空:去掉宣传叙事后剩下的必要事实:系统提示删减超 80%、六组具体实践更替(含新旧提示词原文对照)、deferred loading 工具与 ToolSearch、auto-memory、claude doctor 命令存在。
综合:对使用 Claude 5 代模型与 Claude Code 的开发者,这是一份可直接照做的上下文精简指南;跨模型、跨产品套用时因果证据不足,需自行验证。
中文译文 AI 生成
我之前写过如何为最新一代 Claude 5 模型编写最佳提示词,以及如何与它们迭代协作来发现你想要构建的东西。
但当你向 Claude 发送消息时,提示词只是它获得的上下文中的一小部分。你的上下文大部分由系统提示词、Skills、CLAUDE.md 文件、memory 以及其他来源组装而成。
我们称之为上下文工程(context engineering),它对你使用 Claude Code 或构建自己的 agent 时所产生的结果有着重大影响。
与提示词不同,上下文通常会在许多请求中被通用使用,因此无法那么具体。你如何为 Claude 构建这些通用的提示和指引,尤其是在你不知道用户的提示词可能是什么的情况下?
随着 Claude 自身能力的演进,这件事可能出奇地困难。最近,我们注意到我们为最新一代 Claude 模型编写提示词的方式出现了巨大跃升。我们为 Claude Opus 5 和 Claude Fable 5 等模型删除了 Claude Code 系统提示词中超过 80% 的内容,而在我们的编码评估中没有可衡量的损失。
以下是我们在对这类新模型进行提示方面学到的东西,以及你如何利用它来更新你的上下文工程。我们已将这些最佳实践放进了 claude doctor;在 Claude Code 中使用命令 /doctor 来合理调整你的 skills 和 CLAUDE.md 文件。
解除 Claude 的束缚
总体而言,我们发现我们对 Claude Code 设限过度,无论是通过系统提示词,还是在 CLAUDE.md 文件和 skills 中。
例如,当我们阅读自己内部使用 Claude Code 的对话记录时,会看到单个请求中出现多条相互冲突的消息,比如“酌情保留文档”或“不要(DO NOT)添加注释”,这是我们的系统提示词、skills 和用户请求相互冲突的结果。
一般来说,Claude 能够解读用户意图以得出正确答案,但 Claude 必须更仔细地思考这些重叠且冲突的消息,然后才能决定怎么做。
虽然这些约束曾经是避免最坏情况所必需的,但我们后来发现可以删除其中许多,让模型改用周围的上下文和判断力。
此外,Claude Code 现在拥有多得多的工具。Claude 过去依赖 CLAUDE.md 作为 memory、信息和指引的来源。现在我们有了 memory、artifacts 和 skills,Claude 可以用它们创造出跨会话加载和共享上下文的新方式。
过去与现在
过去有不少上下文工程的最佳实践已经变成了迷思。其中包括:
- 过去:给 Claude 规则
- 现在:让 Claude 运用判断
当我们最初推出 Claude Code 时,我们需要确保 Claude 避免最坏情况,比如删除文件。这意味着我们会给出特别强硬、但可能并不总是正确的指引。例如,我们过去在系统提示词中说:
在代码中:默认不写注释。绝不编写多段 docstring 或多行注释块——最多一行简短内容。除非用户要求,否则不要创建规划、决策或分析文档——基于对话上下文工作,而不是中间文件。
但对于某一部分提示词,这条指引会是错误的。就文档而言,用户可能有自己的偏好,或者非常复杂的代码的特定部分可能需要多行注释块。
尽管如此,如果没有这些针对旧模型的护栏,Claude 写出的注释在很多情况下会是错误的,我们不得不接受这种权衡。但更新的模型拥有更好的判断力,无需显式规则也能很好地处理这些决策。
在新的系统提示词中我们说:编写读起来与周围代码一致的代码:匹配其注释密度、命名和惯用写法。
- 过去:给 Claude 示例
- 现在:设计接口
工具使用的头号规则曾是给 Claude 提供如何使用它们的示例。对于我们的最新模型,我们发现给出示例实际上会把它们限制在某个探索空间内。
与其使用示例,不如多思考你的工具、脚本和文件的设计——Claude 拥有哪些参数,以及如何让它们更具表达力?
例如,在 Todo 工具的例子中,仅将 status 列为 pending、in_progress 和 completed 之间的枚举,就能向 Claude 暗示如何使用它。关于保持一项处于 in_progress 的说明有助于定义我们要求的行为。
- 过去:把所有内容前置
- 现在:使用渐进式披露
由于 Claude Code 专注于编码,我们的系统提示词包含如何进行代码评审和验证的详细信息。这些信息并不总是需要,但一旦需要,就是至关重要的信息。
从那以后,Claude Code 已经非常善于使用渐进式披露——在恰当的时机加载恰当的上下文。例如,我们把验证和代码评审移入了各自的 skills,Claude Code 可以有选择地调用它们。
但渐进式披露不仅适用于 skills,我们也将其用于工具。我们的一些工具是“延迟加载”的,这意味着 agent 在使用它们之前必须使用 ToolSearch 搜索其完整定义。这让我们可以拥有更多工具(比如我们的 Task 工具),在需要之前它们不占用上下文。
同样的做法也可以应用到你自己的 CLAUDE.md 和 Skill.md 文件。一个常见的迷思是,你会想把这些文件做成一个涵盖你可能遇到的每种已知实践的中央仓库,因为否则 Claude 就找不到。相反,可以考虑建立一个文件树,在恰当的时机加载。
- 过去:重复自己
- 现在:简单的工具描述
早期的 Claude 模型有时可能需要重复的指令,或者更有可能听取上下文窗口末尾的指令而非开头的指令。这意味着我们的系统提示词有时会在主系统提示词中包含对工具的引用,同时在工具描述中也包含指令。
我们发现可以删除这些重复的示例,把如何使用工具的指令放在工具描述中,而不是系统提示词中。
- 过去:
CLAUDE.md文件中的 memory
现在:Auto-memory
我们过去常常鼓励用户将内容保存到 Claude 的记忆中,方法是通过 # 热键自动写入他们的 CLAUDE.md。取而代之的是,Claude 现在会自动保存与工作相关以及与你相关的记忆。
过去:简单 specs
现在:丰富的参考
在 plan mode 下,Claude Code 在很大程度上依赖于包含计划的 markdown 文件。将这些文件作为计划存储,有助于 Claude 在需要时进行参考。另一个类似的最佳实践是将 specs 存储在代码库中,供 Claude 在跨较长期项目工作时参考。
但我们发现,Claude 能够处理越来越复杂的参考内容。Claude 不再局限于简单的 markdown 文件,而是可以引用由我们全新的 artifacts 功能创建的 HTML artifacts。
你也可以以代码的形式为 Claude 提供参考。一份 spec 也可以是一套详细的测试套件,或者是 Claude 可能会移植的另一个代码库中的某个函数。
Rubrics 是另一种形式的参考。通过使用动态工作流,并基于这些 rubrics 启动 verifier agents,Rubrics 让 Claude 能够尝试验证你在特定领域的品味(例如,好的 API 设计是什么样子)。
将这些应用到你的上下文
把这一切综合起来,当你组装自己的上下文时,这会是什么样子?
System prompt
System prompt 与产品上下文紧密相关。它会告诉 Claude 它正在什么产品中运行、正在做什么。对于 Claude Code,你很可能永远不需要修改它,但如果你正在构建自己的 agent harness,这就是你应该投入大量时间的地方。
CLAUDE.md
保持你的 CLAUDE.md 轻量,并简要说明你的 repo 的用途,但要把大部分 token 花在代码库内部的 gotcha(易错陷阱)上。例如,你可能会这样组织代码:将类型集中保存在一个大一统的文件中,而不放在其他任何地方。避免陈述那些 Claude 通过查看你的文件系统或 repo 就应当知道的“显而易见”的内容。
大量使用渐进式披露(progressive disclosure),例如,如果你有多条关于如何验证工作的独特说明,可以创建一个验证 skill,并在 CLAUDE.md 中引用它。
Skills
把 skills 看作轻量级的指南,让 Claude 在需要时查找信息。避免对它们施加过多约束,除非是在高度重要的领域。
对于较长的 skills,请尽量使用渐进式披露——将其拆分为多个文件并分开存放。
最好的情况是,skills 中编码了专门针对你、你的团队或你的产品的特定观点、知识或最佳实践。
References
你可以通过 @ 提及文件,将其作为参考纳入。References 让 Claude 能够查阅关于当前计划的深入信息。
这些信息可能存在于 specs 文件、mockups(设计稿)之中,甚至是整个代码库。一般来说,你应该优先选择代码形式的文件,因为它能以 Claude 非常熟悉的语言,为其提供清晰、高保真的指令。例如,设计的 HTML mockup 通常会比该设计的文字描述或截图产生更好的效果。
尝试简化
在你的 system prompt、skills 和 CLAUDE.md 文件中,你可能需要像我们一样进行简化。我们推出了一项名为 claude doctor 的新命令,它也能帮助你自动完成这项工作。有关针对更高级模型进行提示的更多细节,请查阅我们的 Fable field guide。
展开原文提取正文(采集端自动提取,可能有缺失)
I’ve written previously about how to best prompt the newest generation of Claude 5 models and work with them iteratively to discover what you want to build. But when you send a message to Claude, the prompt is only a small part of the context it gets. Much of your context is assembled from your system prompt, Skills, CLAUDE.md files, memory, and other sources. We call this context engineering, and it makes a big impact on the results you generate when using Claude Code or in building your own agents. Unlike a prompt, context is used generally across many requests, so it cannot be as specific. How do you build these general prompts and guidance for Claude, especially when you don’t know what a user’s prompt might be? This can be surprisingly difficult as Claude’s own capabilities evolve. Most recently, we noticed a large jump in the way we prompt the newest generation of Claude models. We removed over 80% of Claude Code’s system prompt for models like Claude Opus 5 and Claude Fable 5 with no measurable loss on our coding evaluations. Here’s what we’ve learned about prompting this new class of models, and how you can utilize it to update your context engineering. We’ve put these best practices in claude doctor; use the command /doctor in Claude Code to rightsize your skills, and CLAUDE.md files. UNHOBBLING CLAUDE Overall, we found that we were overconstraining Claude Code, both through our system prompt and in our CLAUDE.md files and skills. For example, when we read transcripts of our own internal usage of Claude Code, we see several conflicting messages in a single request like “leave documentation as appropriate,” or “DO NOT add comments” as our system prompt, skills, and user requests clash with each other.
Generally, Claude can interpret the user’s intent to get to the right answer, but Claude must think more carefully about these overlapping and conflicting messages before deciding what to do. And while these constraints were once needed to avoid worst case scenarios, we have since found we can delete many of them and let the model use surrounding context and judgement instead. Additionally, Claude Code now has many more tools. Claude used to rely on CLAUDE.md as a source of memory, information, and guidance. Now we have memory, artifacts, and skills, which Claude can use to create new ways of loading and sharing context across sessions. THEN AND NOW There were a number of previous context engineering best practices that had become myths. Including:
Then: Give Claude rules Now: Let Claude use judgement When we first rolled out Claude Code, we needed to be sure that Claude avoided worst case scenarios, such as deleting files. This meant we would give particularly strong guidance that might not always be true. For example, in the system prompt we used to say: In code: default to writing no comments. Never write multi-paragraph docstrings or multi-line comment blocks — one short line max. Don't create planning, decision, or analysis documents unless the user asks for them — work from conversation context, not intermediate files. But for a certain subset of prompts, this guidance would be wrong. In the case of documentation, the user may have their own preferences, or specific parts of very complex code might need multi-line comment blocks. Still, without these guardrails for older models, the comments Claude wrote would be incorrect in many cases and we had to accept this tradeoff. But newer models have better judgement and can handle these decisions well without explicit rules. In the new system prompt we say: Write code that reads like the surrounding code: match its comment density, naming, and idiom. Then: Give Claude examples Now: Design interfaces The number one rule for tool usage was to give Claude examples on how to use them. With our newest models, we’ve found that giving examples actually constrains them to a certain exploration space.
Instead of using examples, think more about the design of your tools, scripts and files- what parameters does Claude have and how can they be more expressive? For example, in the Todo tool example, just listing status as an enumeration between pending, in_progress, and completed, hints to Claude about how to use it. The instruction on keeping one item in_progress helps define our requested behavior. Then: Put it all upfront Now: Use progressive disclosure Because Claude Code was focused on coding, our system prompt included detailed information on how to do code review and verification. These were not always needed, but when they were, it was crucial information. Since then, Claude Code has gotten very competent at using progressive disclosure- loading the right context at the right times. For example, we moved verification and code review into their own skills that Claude Code could selectively call. But progressive disclosure is not just for skills, we also use it for tools. Some of our tools are ‘deferred loading,’ which means the agent must search for their full definitions using ToolSearch before using them. This allows us to have more tools (such as our Task tools) that don’t take up context until they’re needed. The same can be applied to your own CLAUDE.md and Skill.md files. A common myth is that you want to make these a central repository for every known practice that you might run into, because Claude would not find it otherwise. Instead, consider having a tree of files that can be loaded at the right time. Then: Repeat yourself Now: Simple tool descriptions Earlier Claude models could sometimes need repeated instructions or be more likely to listen to instructions at the end of their context window than at the start. This meant our system prompt would sometimes have references to tools in the main system prompt as well as instructions in the tool description. We found we could delete these repeat examples and put instructions on how to use tools in the tool descriptions rather than the system prompt. Then: Memory in CLAUDE.md files Now: Auto-memory We used to encourage users to save things to Claude’s memory, by using the # hotkey to write to their CLAUDE.md automatically. Instead, Claude now automatically saves memories that are relevant to the work and to you. Then: Simple specs Now: Rich references In plan mode, Claude Code has heavily relied on markdown files with plans. Storing these files as plans helped Claude refer to them when needed. Another similar best practice was to store specs in the codebase for Claude to refer to while working across longer projects. But we’ve found that Claude can handle increasingly more complicated references. Instead of simple markdown files, Claude can reference HTML artifacts created by our new artifacts feature. You may also give Claude references in the form of code. A spec may also be a detailed test suite, or a function in a different codebase that Claude might port. Rubrics are another form of references. Rubrics allow Claude to try and verify your taste in a particular field (e.g. what does a good API design look like) by using dynamic workflows and spinning up verifier agents with those rubrics. APPLYING THIS TO YOUR CONTEXT Pulling this all together, what does this look like when you assemble your context?
System prompt A system prompt is heavily tied to the product context. It tells Claude what product it’s operating in and what it’s doing. For Claude Code, you will likely never modify this, but if you are building your own agent harness, this is where you should spend a lot of time. CLAUDE.md Keep your CLAUDE.md lightweight and briefly describe what your repo is for, but spend most of the tokens on gotchas inside of the codebase. For example, you may organize your code to keep types in one monolithic file and nowhere else. Avoid stating ‘the obvious’ things Claude should know by looking at your file system or your repo. Use progressive disclosure heavily, for example if you have several unique instructions on how to verify your work, create a verification skill and reference it from your CLAUDE.md. Skills Think of skills as lightweight guides to let Claude find information when needed. Avoid making them overconstrained, except in highly important areas. For long skills, try and use progressive disclosure as much as possible- divide it into many files and split them out. It’s best when skills encode particular opinions, knowledge, or best practices that are particular to you, your team, or product. References You can @ mention files to include them as references. References allow Claude to refer to in-depth information about the current plan. This might be in specs files, mockups, or even entire codebases. Generally you should prefer files that are in code as it provides clear, high-fidelity instructions to Claude in a language it knows very well. For example, a HTML mockup of a design will generally produce better results than a description of the design or a screenshot. TRY SIMPLIFYING Across your system prompt, skills, and CLAUDE.md files, you may need to simplify just like we did. We rolled out a new command called claude doctor, which will help you do this automatically as well. For more details on prompting more advanced models specifically, check out our Fable field guide. This article was written by Thariq Shihipar, member of technical staff, Anthropic.
原文入口
阅读原文(claude.dev)原文将在新窗口打开。收录时间不是内容更新时间;正文、译文与解读的版权归原作者/来源所有,本站仅作个人阅读辅助并保留原文入口;页面时间均为北京时间。
了解来源批准与收录规则