Q&A · Answers from real-world tests on X

How to Write CLAUDE.md?

Not in your language? Paste the link or the text into your AI and let it read it for you.

6 source posts · 6 creatorsLast updated Nov 3
Short answerHands-on experiences from multiple bloggers point in the same direction: CLAUDE.md should be short. Only write what the project does, which package manager to use, and a few key commands, plus the special pitfalls in the repo that are not easy to infer from the code. Too many rules conflict with each other and also take up context in every request. Auto-generating it with /init is not recommended, because much of its content the agent can discover from the code itself. Others also write specific behavioral rules into it, such as searching open-source projects on GitHub first for unfamiliar features.

How to do it

Click an avatar to see the source post
  1. 1

    Start with the three basics: one sentence explaining what the project does, which package manager to use, and which few key commands exist. Move everything else out and let the agent look it up on its own when needed.

  2. 2

    Don't use /init to auto-generate it, because it stuffs in the project structure, tech stack, and code paths. Most of this can be discovered on its own, and it easily goes out of date.

  3. 3

    Keep only the pitfalls in the repo that are truly special and hard to discover directly from the code. Too many rules easily conflict with each other, and Claude then has to first decide which one to follow.

  4. 4

    You can directly copy ready-made rules, such as OpenCode's 4 rules: validate external data only once at the entry point, and don't extract logic used only once into a function early.

  5. 5

    Adding an on-demand search rule is also effective: don't write unfamiliar features from scratch. First search open-source projects on GitHub to compare approaches before starting. The author says coding became smoother.

  6. 6

    When a team uses multiple agents at the same time, note that Claude Code currently mainly reads CLAUDE.md, not AGENTS.md, so the two sets of rules need to be kept in sync.

What people on X saySorted by usefulness

01鸟哥08-19ZHDon't Make Rules Files Too Long, Keep Only the Project Overview, Package Manager, and Commands#1看了篇《完整的 AGENTS.md 指南》,越读越觉得很多人搞反了。 你是不是也觉得,AGENTS.md 写得越长越细,Agent 就越听话?恰恰相反。Claude CodeImageOriginal post111KLikes 4
02Kevin Ma08-13ZHDon't Use /init to Auto-Generate; Only Write Information That Is Hard to Infer from the Code#2如果你也在考虑精简自己的 AGENTS.md,很推荐读一下 @mattpocockuk 的这篇文章,里面还附了一个可以直接让 Agent 帮你重构 AGENTS.md 的 Prompt:Claude CodeOriginal post70KLikes 619
03Xudong Han07-25ZHCLAUDE.md Should Only Keep the Special Pitfalls in the Repo That Are Hard to Discover#3这篇文章,我真心建议所有使用 Claude Code 或者 Codex 的人都看一遍。 我之前写过几次类似的感受:模型能力提升后,我们还在沿用旧模型时代的提示习惯,给 Agent 塞满规则、示例和各种「不要做什么」,很多时候反而会限制它。Claude CodeOriginal post136KLikes 558
04越川10-25ZHFour OpenCode Rules That You Can Copy Directly into CLAUDE.md用 Codex 写代码,最烦的就是它爱加防御代码:改一个小功能,加了十几层判空和 try/catch,再防一个几乎不可能发生的并发问题,代码量翻一倍。 OpenCode(开源的编程 agent)仓库里有一份 AGENTS.md,专门有一条治这个。Claude CodeOriginal post127KLikes 1.5K
05琳小航10-26ZHAdd a Rule to CLAUDE.md to Search Open-Source Projects on GitHub First最近用ClaudeCode写代码越来越丝滑 很大部分原因是我在CLAUDE.md加了这条规则Claude CodeOriginal post143KLikes 1.7K
06Max For AI08-26ZHClaude Code Only Reads CLAUDE.md, So Teams Using Multiple Tools Need to Keep Them in Sync🚨突发,Shopify CEO Tobi Lütke 公开向 Anthropic 施压! Tobi称 如果 Claude Code 继续拒绝读取 AGENTS.md 和 .agents/skills,Claude CodeOriginal post153KLikes 508
No matching posts or creators found

Everything here comes from real-world tests by users on X. Rules and products change often, so always check the latest. If you know a better way, we'd love to hear it.

Related questions

How do beginners get started with Claude Code?5 postsHow do you save quota and tokens in Claude Code?5 postsHow to Use Claude Code's Subagent (Subagent)?5 postsView all 13 questions