create-or-audit-claude-md
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate or audit a CLAUDE.md
创建或审核CLAUDE.md
Two modes, same skill: Mode 1 writes a new by reading the codebase and distilling ambient context an agent needs. Mode 2 audits an existing one against the quality gates.
CLAUDE.md同一技能包含两种模式:模式1通过读取代码库并提炼Agent所需的环境上下文来编写新的。模式2根据质量标准审核现有的。
CLAUDE.mdCLAUDE.mdBefore You Start
开始之前
- — the rule that drives
principles/02-dense-not-brief.mdlength. Load-bearing, not pad.CLAUDE.md - — the annotated root skeleton with required sections.
skills/meta/create-or-audit-claude-md/templates/CLAUDE.md - — the subdir skeleton + the four trigger criteria.
skills/meta/create-or-audit-claude-md/templates/CLAUDE.subdir.md - — the mechanical gate.
skills/meta/create-or-audit-claude-md/lib/validate.sh
- — 决定
principles/02-dense-not-brief.md篇幅的规则。内容需核心有用,而非冗余填充。CLAUDE.md - — 带注释的基础框架模板,包含必填章节。
skills/meta/create-or-audit-claude-md/templates/CLAUDE.md - — 子目录框架模板 + 四个触发条件。
skills/meta/create-or-audit-claude-md/templates/CLAUDE.subdir.md - — 自动化校验工具。
skills/meta/create-or-audit-claude-md/lib/validate.sh
Mode 1 — create a CLAUDE.md
模式1 — 创建CLAUDE.md
Step 1: discover the codebase
步骤1:探索代码库
bash
undefinedbash
undefinedTop-level shape
Top-level shape
ls -la
find . -maxdepth 2 -type d -not -path '/node_modules' -not -path '/.git'
ls -la
find . -maxdepth 2 -type d -not -path '/node_modules' -not -path '/.git'
Build/test/lint commands (look in all the usual places)
Build/test/lint commands (look in all the usual places)
cat package.json 2>/dev/null | jq '.scripts // {}'
cat pyproject.toml 2>/dev/null | grep -A 20 '[tool.' | head -40
cat Makefile 2>/dev/null | grep -E '^[a-zA-Z_-]+:'
cat justfile .justfile 2>/dev/null
ls .github/workflows/ 2>/dev/null
cat package.json 2>/dev/null | jq '.scripts // {}'
cat pyproject.toml 2>/dev/null | grep -A 20 '[tool.' | head -40
cat Makefile 2>/dev/null | grep -E '^[a-zA-Z_-]+:'
cat justfile .justfile 2>/dev/null
ls .github/workflows/ 2>/dev/null
Entry points
Entry points
git log --pretty=format: --name-only -200 | sort | uniq -c | sort -rn | head -30
undefinedgit log --pretty=format: --name-only -200 | sort | uniq -c | sort -rn | head -30
undefinedStep 2: identify subsystems
步骤2:识别子系统
Look at the top-level source tree. For each major directory (likely candidates: , , , , ), ask:
src/apps/packages/services/lib/- What does it own?
- How does it communicate with siblings?
- What language/framework does it use?
查看顶级源码目录。针对每个主要目录(典型候选:、、、、),思考:
src/apps/packages/services/lib/- 它负责什么功能?
- 它如何与其他子系统交互?
- 使用了哪种语言/框架?
Step 3: extract the "things to know"
步骤3:提炼“必备知识”
The most valuable section of a . These are the hidden invariants and gotchas — the things not obvious from the code but known by every veteran.
CLAUDE.mdMine them from:
bash
undefined这是中最有价值的章节。内容包括隐藏的约束条件和常见陷阱——这些信息无法从代码中直接看出,但每个资深开发者都知晓。
CLAUDE.md可通过以下方式收集:
bash
undefinedRecent bug fixes reveal invariants
Recent bug fixes reveal invariants
git log --oneline --all | grep -iE 'fix|bug' | head -30
git log --oneline --all | grep -iE 'fix|bug' | head -30
ADRs if they exist
ADRs if they exist
ls docs/adr docs/decisions docs/arc42/decisions 2>/dev/null
ls docs/adr docs/decisions docs/arc42/decisions 2>/dev/null
"Do not edit this" and "DANGER" comments in the code
"Do not edit this" and "DANGER" comments in the code
grep -rniE 'DO NOT|DANGER|CAREFUL|WARNING|HACK|FIXME|TODO' --include='.py' --include='.ts' --include='.js' --include='.go' --include='*.rs' | head -30
undefinedgrep -rniE 'DO NOT|DANGER|CAREFUL|WARNING|HACK|FIXME|TODO' --include='.py' --include='.ts' --include='.js' --include='.go' --include='*.rs' | head -30
undefinedStep 4: write the file using root.md.template
root.md.template步骤4:使用root.md.template
编写文件
root.md.templateCopy and fill in every section. Keep the section order from the template — agents rely on it.
skills/meta/create-or-audit-claude-md/templates/CLAUDE.mdSpecial discipline for each section:
- Quick Reference — real commands that actually run. If doesn't exist, don't list it.
pnpm test - Architecture — the longest section. 2–3 paragraphs overview + directory tree + per-subsystem deep-dives.
- Patterns and Conventions — only things a linter doesn't catch (principle 03).
- Things to Know — gotchas with structure: what happens → why → what to do. These are pure value for the agent.
- Security-Critical Areas — a short, honest list. Lying here will erode trust.
复制并填充所有章节。保持模板中的章节顺序——Agent依赖该顺序读取信息。
skills/meta/create-or-audit-claude-md/templates/CLAUDE.md各章节编写规范:
- 快速参考 — 列出实际可运行的命令。如果不存在,请勿列出。
pnpm test - 架构 — 篇幅最长的章节。2-3段概述 + 目录树 + 每个子系统的详细说明。
- 模式与约定 — 仅记录代码检查工具无法捕获的内容(原则03)。
- 必备知识 — 陷阱需按以下结构描述:现象 → 原因 → 解决方案。这对Agent来说是核心价值。
- 安全关键区域 — 简短、真实的列表。此处不实会破坏信任。
Step 5: create subdirectory CLAUDE.md files
步骤5:创建子目录CLAUDE.md文件
A subdirectory gets its own when ANY of the four criteria holds ( enumerates them): different language/framework, 3+ divergent patterns, own build commands, 10+ files with distinct conventions.
CLAUDE.mdskills/meta/create-or-audit-claude-md/SKILL.mdEach must be self-contained — a developer working in that directory should not need to flip back to root.
当满足以下四个条件中的任意一个时,子目录需要单独的(列出了具体条件):使用不同语言/框架、存在3种以上差异化模式、拥有独立构建命令、包含10个以上遵循独特约定的文件。
CLAUDE.mdskills/meta/create-or-audit-claude-md/SKILL.md每个子目录的必须独立完整——在该目录工作的开发者无需返回根目录查看文档。
CLAUDE.mdMode 2 — audit an existing CLAUDE.md
模式2 — 审核现有CLAUDE.md
Step 1: run the validator
步骤1:运行校验工具
bash
bash skills/meta/create-or-audit-claude-md/lib/validate.sh CLAUDE.mdFix errors before continuing.
bash
bash skills/meta/create-or-audit-claude-md/lib/validate.sh CLAUDE.md在继续下一步前修复所有错误。
Step 2: five quality gates
步骤2:五项质量标准
Gate 1 — density. Is every line load-bearing? Cut transitional prose ("In summary...", "As mentioned above..."), cut sections that have shrunk to a single sentence.
Gate 2 — evidence. Every declarative statement cites a file or a command. Run:
bash
grep -oE '`[a-zA-Z_./-]+/[a-zA-Z_.-]+`' CLAUDE.md | sort -u | while read p; do
path=$(echo "$p" | tr -d '`')
[ ! -e "$path" ] && echo "STALE: $p"
doneGate 3 — duplication. Scan for rules already enforced by tooling (linter rules, formatter rules, CI checks). Remove them; point at the tool instead.
Gate 4 — alternatives. Every prohibition (, , ) must have a nearby alternative (, , ). Validator enforces.
neverdon'tdo notinsteaduse X insteadpreferGate 5 — Things to Know. This section's presence is a strong signal the has earned its keep. If it's empty or trivial, interview the team: "What's the most surprising thing about this codebase?"
CLAUDE.md标准1 — 内容密度。每一行是否都有核心价值?删除过渡性文字(如“综上所述...”、“如前所述...”),删除已缩减为单句的章节。
标准2 — 依据充分。每个陈述性内容都需引用文件或命令。运行以下命令:
bash
grep -oE '`[a-zA-Z_./-]+/[a-zA-Z_.-]+`' CLAUDE.md | sort -u | while read p; do
path=$(echo "$p" | tr -d '`')
[ ! -e "$path" ] && echo "STALE: $p"
done标准3 — 无重复。检查是否存在已由工具(代码检查规则、格式化规则、CI检查)强制执行的规则。删除这些内容,改为指向对应工具。
标准4 — 替代方案。每个禁止性表述(、、)必须附带附近的替代方案(、、)。校验工具会强制要求这一点。
neverdon'tdo notinstead请改用X推荐标准5 — 必备知识。该章节的存在是具备价值的重要标志。如果该章节为空或内容无关紧要,请询问团队:“这个代码库最令人意外的地方是什么?”
CLAUDE.mdStep 3: report
步骤3:生成审核报告
markdown
undefinedmarkdown
undefinedCLAUDE.md Audit: {path}
CLAUDE.md审核报告: {path}
Verdict: APPROVE | REVISE | REJECT
结论: 通过 | 需要修订 | 拒绝
Gate results
质量标准检查结果
...
...
Stale references (must fix)
失效引用(必须修复)
{List of paths that no longer exist}
{不再存在的路径列表}
Duplicated tooling rules (remove these — point at the tool)
重复的工具规则(删除这些内容,改为指向工具)
...
...
Missing sections
缺失章节
...
...
Proposed additions to "Things to Know"
“必备知识”章节建议补充内容
{From your discovery in step 2}
undefined{来自步骤2的发现}
undefinedVerify
验证
bash
undefinedbash
undefinedValidator passes
Validator passes
bash skills/meta/create-or-audit-claude-md/lib/validate.sh CLAUDE.md
bash skills/meta/create-or-audit-claude-md/lib/validate.sh CLAUDE.md
Expected: VERDICT: PASS
Expected: VERDICT: PASS
No stale file references
No stale file references
grep -oE '' CLAUDE.md | tr -d '`' | while read p; do
[ ! -e "$p" ] && echo "STALE: $p"
done
[a-zA-Z_./-]+/[a-zA-Z_.-]+grep -oE '' CLAUDE.md | tr -d '`' | while read p; do
[ ! -e "$p" ] && echo "STALE: $p"
done
[a-zA-Z_./-]+/[a-zA-Z_.-]+Expected: empty output
Expected: empty output
undefinedundefinedCommon Mistakes
常见错误
| Mistake | Correction |
|---|---|
| Padding to reach a line count | Dense, not bulky. A 150-line file with every line load-bearing beats a 400-line mix. |
| Embedding a 30-line code snippet | Reference the file (principle 04): |
| Restating every linter rule | Point at the tool ( |
"Don't use | Pair with "Use |
| 错误 | 修正方案 |
|---|---|
| 为达到行数要求填充冗余内容 | 内容需精炼而非冗长。每行都有核心价值的150行文件优于400行的冗余文件。 |
| 嵌入30行代码片段 | 引用文件(原则04): |
| 重复列出所有代码检查规则 | 指向对应工具( |
只说“不要使用 | 搭配说明“请改用 |
What doesn't belong in CLAUDE.md
CLAUDE.md不应包含的内容
- Rules already enforced by tooling. If ESLint catches it, don't restate it (principle 03).
- Temporary state. Current sprint goals, "in-progress" features. That's issue-tracker territory.
- Long tutorials. If a walkthrough is >20 lines, it's a skill, not ambient context.
- Embedded code snippets over 10 lines. They rot. Reference the file instead (principle 04).
- 已由工具强制执行的规则。如果ESLint能捕获该问题,无需重复记录(原则03)。
- 临时状态。当前冲刺目标、“开发中”的功能。这些内容属于问题跟踪工具的范畴。
- 长篇教程。如果操作指南超过20行,应作为独立技能,而非环境上下文。
- 超过10行的嵌入代码片段。这类内容容易过时。请改为引用文件(原则04)。