Claude 5 代模型的语境工程新规则
The new rules of context engineering for Claude 5 generation models

原始链接: https://claude.com/blog/the-new-rules-of-context-engineering-for-claude-5-generation-models

随着人工智能模型日趋成熟,传统的“上下文工程”最佳实践正从僵化的规则设定,演变为灵活、智能的引导。Anthropic 强调了优化 Claude 的几个转变: * **从规则到判断:** 不要强加死板的约束,应允许模型根据上下文进行调整,例如匹配现有的代码规范。 * **从示例到接口:** 不要提供限制创造力的死板示例,而应设计具有表现力的工具和参数,让 Claude 能有效地探索解决方案。 * **从一次性加载到渐进式披露:** 不要将所有信息堆砌在系统提示词中。使用模块化文件(如 Skills/CLAUDE.md),让 Claude 在需要时选择性地读取。 * **从手动记忆到自动记忆:** 相信模型能够自动识别并保留相关信息。 * **从简单规范到丰富参考:** 用高保真的参考资料(如 HTML 工件、测试套件或模块化代码块)取代基础的 Markdown 计划。 **核心建议:** 保持你的 `CLAUDE.md` 轻量化,仅关注项目特有的“注意事项”。利用渐进式披露使指令保持模块化,并优先使用高保真参考(如代码或原型图)而非描述性文本。归根结底,简化配置才能让模型的推理能力发挥最大作用。

这篇 Hacker News 的讨论批评了近期针对 Claude 5 等模型进行“上下文工程”(context engineering)的趋势。用户对日益复杂、“巴洛克式”的系统提示词和配置文件(如 `CLAUDE.md`)表示不满。 主要观点包括: * **对复杂性的质疑:** 许多评论者认为这些死板的指令集只是“业余爱好者的折腾”或不必要的开销,并主张人工交互更为有效。 * **供应商锁定:** 一些人推测,Anthropic 推动特定的配置工具是一种增加平台锁定(vendor lock-in)的策略。 * **性能忧虑:** Claude 5 的早期采用者报告了性能倒退,指出与以往版本相比,错误率增加、出现意外删除文件的情况,且 token 使用量更高。 * **存在主义反思:** 对话从技术优化转向了 AI 开发的“苦涩教训”(bitter lesson),一些用户讨论我们是否正在创造最终会完全无视人类指令、甚至产生自主且潜在危险“判断”的系统。 总的来说,社区内部存在分歧:一方试图将提示词工程标准化,另一方则认为该行业正在以自然语言提示为幌子,重蹈覆辙地重新发明编程语言。
相关文章

原文

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.

联系我们 contact @ memedata.com