优化 AGENTS.md:Claude Code 与 Codex 上下文管理技巧
Highly recommend slimming down your AGENTS.md. Claude Code's docs say to keep ea…
这篇稿子不仅指出了具体痛点,还给出了基于官方文档的机制解析和可执行的优化方案,结构清晰且有实操价值,值得创作者参考其技术深度与写作逻辑。
Highly recommend slimming down your AGENTS.md. Claude Code's docs say to keep each one 𝘂𝗻𝗱𝗲𝗿 𝟮𝟬𝟬 𝗹𝗶𝗻𝗲𝘀, since the longer it gets, the less Claude follows it. Codex reads 𝟯𝟮 𝗞𝗶𝗕 𝗮𝘁 𝗺𝗼𝘀𝘁 by default and skips anything past that.
强烈建议精简你的 AGENTS.md。Claude Code 的文档指出,每个文件应控制在 200 行以内,因为文件越长,Claude 遵循指令的效果就越差。Codex 默认最多读取 32 KiB 的内容,超出部分会被跳过。
Simply put, every time you start a session, Codex and Claude Code read your AGENTS.md into context, and it comes along on every turn after that. The longer it is, the more context it eats. After slimming, it looks like the image: only the main file gets read every time, and the rest only when the agent gets to that folder or needs it.
简而言之,每次启动会话时,Codex 和 Claude Code 都会将你的 AGENTS.md 加载到上下文中,并在随后的每一轮对话中保留它。文件越长,占用的上下文就越多。精简后效果如图片所示:每次只读取主文件,其余文件仅在代理进入该文件夹或需要时才读取。
The official docs have a few more things I didn't know: → Codex reads them once, when the session starts: the global one, plus every one from the project root down to the folder you launched in. It won't automatically reread them when you move to another folder → Claude Code works differently: it loads a subfolder's AGENTS.md only when it reads a file in that folder. So rules that only matter for one folder belong in that folder's own AGENTS.md → In Claude Code, @ imports only make the file look tidier. Imported files still load in full at launch, so they 𝘀𝗮𝘃𝗲 𝘇𝗲𝗿𝗼 𝘁𝗼𝗸𝗲𝗻𝘀 → In Claude Code, every installed skill's name and description takes up context on every turn, whether you use it or not. Run /skill-doctor to see what each one costs and how often it gets used, and turn off the ones you don't need → In Claude Code, run /doctor prompt-audit (v2.1.283 or later). It finds instructions written for older models, references to files that don't exist, and files that contradict each other, and changes nothing until you say yes
官方文档还有一些我不知道的细节: → Codex 仅在会话开始时读取一次:包括全局文件,以及从项目根目录到你启动所在的文件夹之间的所有文件。当你切换到其他文件夹时,它不会自动重新读取这些文件 → Claude Code 的工作方式不同:仅当它读取某个子文件夹中的文件时,才会加载该子文件夹的 AGENTS.md。因此,仅对特定文件夹重要的规则应放在该文件夹自己的 AGENTS.md 中 → 在 Claude Code 中,@ 引用导入仅使文件看起来更整洁。被导入的文件在启动时仍会完整加载,因此它们节省的 token 数为零 → 在 Claude Code 中,每个已安装技能的名称和描述都会在每一轮对话中占用上下文空间,无论你是否使用它。运行 /skill-doctor 可查看每个技能的成本和使用频率,并关闭你不需要的技能 → 在 Claude Code 中,运行 /doctor prompt-audit(v2.1.283 或更高版本)。它会找出为旧模型编写的指令、指向不存在文件的引用以及相互矛盾的指令,并在你确认之前不做任何更改
Send this prompt and the links below to Opus 5.5 👇
将此提示词及下方链接发送给 Opus 5.5 👇
"Read these two docs, then read my AGENTS.md (and CLAUDE.md, if the project has one) and the files it imports, and give me three ways to restructure them: 1. Delete instructions that do nothing: things Opus already does, and things it can tell from the code. Merge duplicates, and list any contradictions so I can choose. 2. Keep only the rules needed every time in the root AGENTS.md, under 200 lines. Move rules that only matter for one folder into that folder's own AGENTS.md, and other details into separate files. For both, say in the main file where they are and when to read them. Don't use @ imports for detail files, and keep the line in CLAUDE.md that imports AGENTS.md. Have three subagents each write one version, each more aggressive than the last. This step is proposals only, so don't change any files. For each version, list what was deleted, where things moved, and the main file's line count and size in KiB before and after. Don't lose a single useful rule. Show me the three versions side by side first, I'll pick one, and then open a PR." https://code.claude.com/docs/en/memory https://learn.chatgpt.com/docs/agent-configuration/agents-md
"阅读这两份文档,然后阅读我的 AGENTS.md(如果项目有的话还包括 CLAUDE.md)以及它所导入的文件,并给我三种重构它们的方案: 1. 删除无效的指令:即 Opus 已经具备的功能,以及它能从代码中推断出的内容。合并重复项,并列出任何矛盾之处以便我进行选择。 2. 仅在根目录的 AGENTS.md 中保留每次都需要使用的规则,且行数不超过 200 行。将仅对特定文件夹重要的规则移至该文件夹自己的 AGENTS.md 中,其他细节移至单独的文件中。对于这两种情况,在主文件中说明它们的位置以及何时需要阅读。不要使用 @ 导入来引用细节文件,并保留 CLAUDE.md 中导入 AGENTS.md 的那一行。 让三个子代理各自编写一个版本,每个版本比上一个更激进。此步骤仅为提案,因此不要更改任何文件。对于每个版本,列出被删除的内容、移动的位置,以及主文件在操作前后的行数和 KiB 大小。不要丢失任何有用的规则。首先让我并排查看这三个版本,我选择一个后,再打开 PR。" https://code.claude.com/docs/en/memory https://learn.chatgpt.com/docs/agent-configuration/agents-md"
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力