核心结论:很多人把规则、SOP、工作流全写进 Memory(记忆),但 Claude 和 Codex 的 Memory 都有硬上限——CLAUDE.md 建议控制在 200 行以内,200K 上下文窗口里它每次都会占掉约 40000 字符空间。规则一多,AI 执行任务时会把一堆规则都读一遍,既挤占上下文,又相互干扰。正确的做法只有一句话:让 Memory 做索引,让 Skill 存规则。Memory 只负责告诉 AI「这个任务该读哪个 Skill」,具体的规则、SOP、操作手册全部写进 Skill,不写进 Memory。这样规则不容易被挤掉,工作流之间也不会互相干扰。
目录
- Memory 到底有没有上限:把数字摆出来
- 规则全塞进 Memory 的两种代价
- 核心解法:Memory 做索引,Skill 存规则
- Skill 的加载机制:为什么规则不会挤掉
- 可运行的判断函数:这行规则该进 Memory 还是 Skill
- 对照表:症状 → 原因 → 解法
- 结论:该用 / 不该用的判据
1. Memory 到底有没有上限:把数字摆出来
先别争论「Memory 有没有上限」这个哲学问题,直接把官方给出的约束数字摆出来。
CLAUDE.md 的推荐行数:Anthropic 官方明确建议每个 CLAUDE.md 文件控制在 200 行以内。超过这个长度,官方原话是「consume more context and reduce adherence」——占更多上下文、降低遵守度。这不是审美建议,是实测后的工程约束。
200K 上下文窗口对应多少字符:在默认的 200K 上下文窗口里,CLAUDE.md 的可用空间约 40000 个字符(1M 上下文窗口的模型则是 200000/150000 字符)。这意味着如果规则写得又长又密,单靠一个文件就能吃掉接近整窗的几分之一。
MEMORY.md 的加载限制:自动记忆(auto memory)的索引文件 MEMORY.md,每次会话开始时只加载前 200 行,或前 25KB,哪个先到取哪个。超过的部分本次会话根本读不到——你写了,但 AI 看不见。
Skill 的加载成本:真正按需加载的是 Skill(技能)。Skill 启动时只加载它的 name + description(约 100 token),完整 SKILL.md 正文(<5k token)只有在技能被触发时才进入上下文。
把四个数字放在一起,结论就清楚了:Memory 是「常驻内存」,Skill 是「按需读取」。常驻的东西一多,每轮任务都要为无关规则买单。
参考资料:
- How Claude remembers your project -- Claude Code Docs ⭐值得阅读
- Extend Claude Code -- Claude Code Docs ⭐值得阅读
- Give Claude context: CLAUDE.md and better prompts -- Claude Help Center
- Agent Skills -- Claude API Docs
2. 规则全塞进 Memory 的两种代价
规则一多、全塞进 Memory,会付出两种实实在在的代价。这两种代价不是「性能差一点」,而是会直接让 AI 干不好活。
代价一:规则被挤掉(被截断)。Memory 有 200 行 / 25KB 的加载门槛,规则写多了,靠后的规则在会话里根本加载不进去。你以为写了「必须先审代码再提交」,但因为太长排在后面,AI 这轮可能根本没看到。规则没有消失,只是「在窗外的角落里躺着」,而 AI 不会去翻。
代价二:工作流互相干扰。当几十条不同主题的规则(数据库迁移、发布清单、代码审查规范)全部塞进同一份 Memory,AI 每次执行任务都要把它们从头到尾读一遍。这会产生两类干扰:一是无关规则抢占 attention(注意力),让该执行的规则被稀释;二是规则之间可能相互矛盾,AI 在矛盾中来回摇摆。
打个比方 🎭:Memory 像电脑的常驻内存,开机就占着;Skill 像按需加载的软件,你点开才载入。把所有软件都做成开机自启,内存很快爆掉,还互相抢资源——这跟规则全塞 Memory 是一个道理。
参考资料:
- Claude Code usage limits and token optimization -- TechRounder
- Your CLAUDE.md Is Too Long: What to Cut So Claude Code Follows It -- DEV Community
3. 核心解法:Memory 做索引,Skill 存规则
既然 Memory 是稀缺的常驻资源,解决思路就一句话:Memory 只做索引,具体的规则和 SOP 全部交给 Skill。
Memory 负责什么:只记录「这个项目有哪些 Skill、每个 Skill 是干嘛的、什么时候该调用某个 Skill」。它是一张索引卡片,告诉 AI「这个任务该读哪个 Skill」。核心是 signal-dense(信号密集)——每一行都要值回它占用的上下文。
Skill 负责什么:具体的规则、SOP、操作手册、检查清单。比如数据库迁移流程、发布 checklist、代码审查规范、某种框架的 API 用法。这些内容只在触发时才加载,不挤占常驻上下文。
为什么这么分是成立的:因为 Skill 天然支持 progressive disclosure(渐进式披露)。Skill 的 name 和 description 常驻(约 100 token),正文按需加载。规则放进 Skill,等于让「该读的规则」在需要时才进上下文,平时不占空间。
判断口诀:如果一条内容「AI 每轮都必须知道」→ 放 Memory;如果「只有某种任务才需要」→ 放 Skill;如果是「多步流程 / 操作手册」→ 一定放 Skill。
参考资料:
- Steering Claude Code: skills, hooks, rules, subagents and more -- Claude ⭐值得阅读
- Equipping agents for the real world with Agent Skills -- Anthropic ⭐值得阅读
- How to remember: CLAUDE.md vs skills -- Claude Docs
4. Skill 的加载机制:为什么规则不会挤掉
有人会问:「把规则挪进 Skill,万一 AI 想不起来读呢?」答案是:Skill 有自动触发与按需加载机制,它不怕「被挤掉」,因为它在会话里占的坑极小。
Skill 的三级加载(progressive disclosure):
为什么这能解决「规则被挤掉」:Skill 的正文平时根本不加载,所以不存在「写太多被截断」的问题。真正占上下文的是 Level 1 的 name + description(每个约 100 token),而这部分恰恰是最精简的索引——它只告诉你「有这个技能、什么时候用它」。
怎么触发:Skill 可以被路径命令显式调用(如 /code-review),也可以由任务自动匹配。一旦触发,AI 会把完整 SKILL.md 读进上下文,临时获得全部规则。
参考资料:
- Agent Skills -- Claude API Docs ⭐值得阅读
- Skill authoring best practices -- Claude Platform Docs
- How Claude Code works -- Claude Code Docs
5. 可运行的判断函数:这行规则该进 Memory 还是 Skill
下面这段代码把「该进 Memory 还是 Skill」的判断规范化成 4 个问题。运行不需要任何外部依赖,复制即跑:
def classify_rule_entry(
always_needed: bool, # 这条内容 AI 是否每轮都必须知道
is_workflow: bool, # 是否属于多步流程 / 操作手册
task_specific: bool, # 是否只有某个特定任务才需要
) -> str:
"""判断一条规则应该放在 Memory(索引)还是 Skill(正文).
参数:
always_needed: 内容是否每次会话都必须常驻(如项目约定、命名规范)
is_workflow: 是否属于多步流程、SOP、操作手册
task_specific: 是否只在某个特定任务场景下才需要
返回:
推荐存放位置: memory / skill
"""
# 1) 多步流程 / 操作手册 -> 一定放 Skill,避免挤占常驻上下文
if is_workflow:
return "skill(Skill): 流程/手册按需加载,不挤占常驻上下文"
# 2) 每轮必须知道 -> 放 Memory,作为常驻索引
if always_needed:
return "memory(Memory): 常驻索引,确保每次会话都加载"
# 3) 只在特定任务需要 -> 放 Skill,用 description 做自动触发
if task_specific:
return "skill(Skill): 任务触发时加载,用 description 匹配"
# 4) 都不满足 -> 默认放 Skill,最保守
return "skill(Skill): 默认按需加载,避免冗余"
# 示例:判断「数据库迁移流程」该放哪
if __name__ == "__main__":
print(classify_rule_entry(
always_needed=False, # 迁移流程不是每轮都要
is_workflow=True, # 它是多步操作手册
task_specific=False,
))
# 输出: skill(Skill): 流程/手册按需加载,不挤占常驻上下文
这段代码把判断逻辑浓缩成一条可执行的决策路径。核心原则:能进 Skill 的尽量进 Skill,Memory 只留必须常驻的索引。
6. 对照表:症状 → 原因 → 解法
7. 结论:该用 / 不该用的判据
什么时候该用:规则是「每轮都必须知道的约定」(命名规范、构建命令、基础项目结构)→ 放 Memory(CLAUDE.md);规则是「多步流程、SOP、操作手册」→ 放 Skill(按需加载)。判断标准就一条——这条规则 AI 是不是每轮都要看,是就进 Memory,否就进 Skill。
什么时候不该用:不要把所有规则都塞进 Memory,尤其不要塞多步流程和长手册;不要让 Memory 超过 200 行 / 25KB;不要用大量内容撑满上下文窗口,那只会降低规则的遵守度。规则一多,该做的是拆分到 Skill,而不是继续堆进 Memory。
本专栏《AI Agent 工具专栏》从工具调用、记忆管理、Skill 路由一路讲到规则治理与上下文上限,每篇都配可运行的代码与一张对照表,聚焦生产落地的真实取舍,每周更新一篇。想在 Agent 工程里少踩坑,可在专栏页订阅。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Core conclusion: Many people write about the rules, SOP, workflow in Memoory, but Claude and Codex's Memoory have a hard ceiling — CLAUDE.md recommends to be contained within 200 lines, and 200 K context window takes up approximately 40000 characters each time. With more than one rule, AI will read a whole bunch of rules in the course of a mission, both crowding out context and interfering with each other. The correct approach is only one sentence: let memory index, let Skill save the rules. Memory is only responsible for telling AI which Skill is to read on this mission. Specific rules, SOP, operating manuals are all written in Skill, not Memory. The rules would not be easily squeezed out and there would be no interference between workflow.
Contents
- Is there a ceiling on that?
- It's the rules, it's the two costs of memory.
- Core solution: memory index, Skyll saving rules
- Skill's loading mechanism: Why don't the rules get squeezed out?
- Runable judgmental function: this line of rules should go into Memoory or Skyll
- Checklist: Symptoms, causes, solutions
- Conclusions: Should / Should not be used
1. Is there a ceiling on memory?
Let's not argue about the philosophical question of whether "Memory has a ceiling" and put out the official binding figures.
CLUDE.md 's recommended lines: Anthropic official explicitly recommends that each CLUDE.md file be within 200 lines. More than this, the official phrase is "consume more contact and reduce compliance" — more context and lower compliance. This is not an aesthetic proposal, but a realistic project.
200K context window corresponds to the number of characters: in the default 200K context window, approximately 40000 characters (1M context window model is 200000/15000 characters) are used in the usable space of CLAUDE.md. This means that if the rules are long and secret, a single document can eat one-hundredth of the whole window.
MAMORY.md 's loading limit: The index file for automory (EMORY.md) only loads the first 200 lines at the beginning of each session, or the first 25KB, which comes first. More than one part of this session can't read -- you wrote it, but AI can't see it.
Skill: The real load on demand is Skill. Skill only loads its name + description (approximately 100 token), and the full SKILL.md text (<5k token) enters context only when skills are triggered.
If you put four numbers together, the conclusion is clear: Memoory is "resident memory" and Skyll is "read on demand". Every assignment has to pay for a non-relevance rule.
References:
- How Claude remembers your project...
- Extend Claude Code -- Claude Code Docs is worth reading.
- Give Claude context: CLAUDE.md and better prompts -- Claude Help Center
- Agent Skills -- Claude API Docs
2. Both costs of putting the rules in Memoory
There are two real costs involved in putting more than one rule, all into memory. These two costs are not "defunct performance," but they will simply make AI work poorly.
Cost one: Rules are squeezed out (cut off). Memoory has 200 rows / 25KB loading threshold, rules are written, and the back rules are not even loaded in the session. You think you wrote "the code has to be reviewed before submission", but because it's too long to be in the back, AI might not have seen it at all. The rules didn't disappear, they were just "sliding in the corner outside the window" and AI wouldn't turn.
Cost two: workflow interferes with each other. When dozens of rules on different subjects (database migration, publish lists, code review specifications) are all inserted into the same Memoory, AI reads them from scratch to the end of each mission. There are two types of interference: one is irrelevant rule-taking, which dilutes the enforcement rule; and the other is possible conflict between rules, in which AI moves back and forth.
Example: Memoory, like a permanent memory of a computer, takes over; Skyll, like a load on demand software, you click to load. All the software was turned on, the memory went off quickly, and they robbed each other of resources. - It's one thing to do with the rules all over Memoory.
References:
- Claude Code usage limits and token optimization -- TechRounder
- Your CLAUDE.md Is Too Long: What to Cut So Claude Code Follows It -- DEV Community
3. Core solution: Memoory indexing, Skyll saving rules
Now that memory is a scarce resident resource, the solution is just one thing: memory only indexes, the specific rules and the SOP go to Skyll.
Memoory is responsible for what: "What is this project, Skill, each Skill doing, and when should a Skill call?" It's an index card that says to AI, "Who should read Skill on this mission." The core is signal-dense - each line is worth the context it occupies.
Skill is responsible for what: specific rules, SOP, operating manual, checklist. For example, the database migration process, publish checklist, code review specifications, some framework API usage. These elements are loaded only when triggered and do not crowd into the permanent context.
Why is that so? Because Skill naturally supports progressive disclosure. Skill's name and location permanent (approximately 100 token), text load on demand. Putting the rules in Skill is tantamount to allowing the "rules of reading" to enter context when needed, and usually not in space.
Critics: If one of the contents, "AI must know" and "Memory" were to be put; if "only for some task" was to be placed; if "multi-step process / operating manual" was to be placed.
References:
Steering Claude Code: skills, faces, debates and more...
- Equipping treaties for the real world with Agent Skills--
- How to remember: CLAUDE.md vs skills -- Claude Docs
4. Skill 's loading mechanism: Why the rules are not squeezed out
One would ask, "Skill, if AI can't read it?" The answer is: Skill has an automatic trigger and Z27Z mechanism, which is not afraid of being "squeezed off" because it has a very small pit in the conversation.
Skill's third stage load:
Why does this solve the problem of "rules being squeezed out": Skill's text is not always loaded, so there is no question of "writing too much of it cut off" The real share of context is the name of Level 1 + definition (about 100 token each), which is the simplest index - it only tells you "when to use this skill."
How to trigger: Skill can be explicitly called by a path command (e. g. /code-review) or automatically matched by a task. Once triggered, AI will read the whole SKILL.md into context, temporarily get all the rules.
References:
- Agent Skills-- Claude API Docs is worth reading.
- Skill authoring best practices -- Claude Platform Docs
- How Claude Code works -- Claude Code Docs
5. Runable judgement function: This line of rules should go into memory or Skyll
The code below makes four questions of the judgment that "should go into Memoory or Skill" Run without any external dependence, copy and run:
def classify_rule_entry(
# Does AI have to know every round
is workflow: bool, # Is it a multi-step process / operations manual
task specific: bool, # Is only a specific task required
) -> str:
""judges whether a rule should be placed in Memoory or Skill.
Parameters:
Always ned: Whether content must be permanent at each session (e.g. project engagement, naming specifications)
is workflow: is a multi-step process, SOP, operations manual
task specific: Is it only necessary in a given task scenario
Return:
Recommended location: memory / skill
"""
#1) Multistep / Operations Manual - > Always Skill, avoid crowding in to context
if is_workflow:
Return "skill" (Skill): Process/Manual load on demand, does not crowd context"
#2) Every round must know - # Put memory, as a resident index
if always_needed:
Return "Memory": Resident index to ensure that every session is loaded
#3) Only needed for a given mission - > Play Skill, auto-activate with description
if task_specific:
Turn "skill(Skill): Load when task triggers, match with description"
#4) Unsatisfactory - # Default Skill, most conservative
Turn "skill": Default load on demand, avoid redundancy
# Example: determine where the database migration process should be
if __name__ == "__main__":
print(classify_rule_entry(
# The migration process is not always required
# It's a multistep manual
task_specific=False,
))
# Output: Skill (Skill): Process/Manual load on demand, does not crowd in context
The code condensed the judgement logic into an enforceable decision path. Core principle: Skill, Memory only keeps a permanent index to get into Skill.
6. Comparison table: symptoms causes
7. Conclusion: Shouldn 't use / Shouldn 't use
When should it be used: the rules are "an agreement that must be known for each round" (name code, build order, basic project structure) and "mory" (CLAUDE.md); the rules are "multi-step process, SOP, operating manual" and "kill" (load on demand). There's only one test -- this is the rule of AI, is it every round, is it in Memory, or is it in Skill.
When should it not be used: do not put all the rules in Memory, especially not a multi-step process and a long manual; do not let Memory exceed 200 lines/ 25KB; do not fill context window with a lot of content, which would only reduce compliance. Rule number one, split to Skill, instead of continuing to pile in memory.
This column, " AI Agent Tools ", from tool call, Memory Management, Skyll Roadway to rule governance and context caps, each with a runable code and a checklist, focuses on real trade-offs for production sites and updates on a weekly basis. You can subscribe to the column page if you want to reduce the pits in the Agent project.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.