claude-md

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/claude-md -- Audit and Improve CLAUDE.md Files

/claude-md —— 审计与优化CLAUDE.md文件

Naming exception (documented): skillforge's checklist forbids
claude
or
anthropic
in a skill name. This skill is a deliberate exception: it operates on the literal
CLAUDE.md
artifact, so the precision of the name is the value. Treat this as the only such exception in the library.
Two modes, one skill. Audit finds problems across many CLAUDE.md files (hygiene). Improve rewrites one file against best-practice rubric (structure). Both ground in the same core principle.
命名例外(已记录): skillforge的检查清单禁止在技能名称中使用
claude
anthropic
。本技能是特意设置的例外:它直接操作字面意义上的
CLAUDE.md
工件,因此名称的精准性是其价值所在。将其视为库中唯一此类例外。
一个技能,两种模式。审计模式可在多个CLAUDE.md文件中排查问题(卫生检查);优化模式会对照最佳实践准则重写单个文件(结构调整)。两者均基于同一核心原则。

Core Principle

核心原则

The removability test: "For every line in CLAUDE.md, ask — if I removed this, would Claude make a mistake? If not, remove it." — Anthropic, Claude Code Best Practices
This is the unifying rule. Audit mode flags lines that fail the test as drift / waste / duplicates. Improve mode proposes their removal. Same diagnostic, different scale.
A second invariant cuts across both modes: CLAUDE.md is tracked in git and visible to every agent that opens the repo. Pasted secrets are durable leaks. Both modes treat secret-leak detection as a P0 finding.
可移除性测试: "对于CLAUDE.md中的每一行,问自己——如果我删除这一行,Claude会犯错吗? 如果不会,就删除它。" —— Anthropic,Claude代码最佳实践
这是统一规则。审计模式会标记未通过该测试的行,将其视为偏差/冗余/重复内容;优化模式则建议移除这些行。诊断逻辑一致,只是适用范围不同。
两种模式还遵循另一项不变原则:CLAUDE.md需纳入git版本控制,且对所有打开仓库的Agent可见。粘贴的秘密信息会造成永久性泄露。两种模式均将秘密泄露检测列为P0级(最高优先级)问题。

Mode Dispatch

模式调度

InvocationModeWhat runs
/claude-md
(no args, in a project with
./CLAUDE.md
)
auto → improveImprove the local CLAUDE.md
/claude-md
(no args, no local file)
auto → auditScan all CLAUDE.md files under your projects roots (e.g.
~/Projects
)
/claude-md improve [path]
improveSingle-file structural rewrite (10-rule rubric)
/claude-md audit [project|all|path]
auditHygiene scan: secrets P0, drift, duplicates, budget
If both modes would apply (e.g.,
/claude-md improve
in a folder with no CLAUDE.md), the skill asks for clarification.
调用方式模式执行内容
/claude-md
(无参数,项目中存在
./CLAUDE.md
自动→优化优化本地CLAUDE.md文件
/claude-md
(无参数,无本地文件)
自动→审计扫描项目根目录下所有CLAUDE.md文件(如
~/Projects
/claude-md improve [路径]
优化单文件结构重写(基于10条准则)
/claude-md audit [项目|全部|路径]
审计卫生扫描:秘密泄露(P0级)、内容偏差、重复内容、指令预算
若两种模式均可适用(例如在无CLAUDE.md文件的文件夹中执行
/claude-md improve
),技能会请求用户明确指令。

Also applies to
AGENTS.md
(V2)

同样适用于
AGENTS.md
(V2版本)

AGENTS.md
is the cross-agent standard (Linux Foundation / Agentic AI Foundation; read by Codex, Cursor, Gemini, Copilot, and 30+ tools). Everything here — the rubric, the secret scan, drift detection, the budget — applies to
AGENTS.md
identically. When both exist, audit both and flag duplication: the right pattern is one source of truth (
AGENTS.md
) with
CLAUDE.md
as a thin alias/
@import
, not two drifting files. Treat a repo's nearest-scoped
AGENTS.md
(monorepos nest them) the same way.

AGENTS.md
是跨Agent标准(由Linux Foundation / Agentic AI Foundation制定;Codex、Cursor、Gemini、Copilot及30+工具均支持读取)。本文档中的所有内容——评估准则、秘密扫描、偏差检测、指令预算——均同样适用于
AGENTS.md
。若两者同时存在,会对两者进行审计并标记重复内容:正确的模式是单一事实来源
AGENTS.md
),而
CLAUDE.md
作为轻量别名/
@import
,而非两个内容偏差的文件。对于仓库中最近作用域的
AGENTS.md
(单体仓库可嵌套),处理方式相同。

Improve Mode

优化模式

Measure one CLAUDE.md against Anthropic's official best practices + community-validated guidance, then propose concrete rewrite diffs. Apply only after user approval.
One empirical caveat (Claude Code specifically). When the target file is short (<100 lines) and already aligned with Karpathy-style rules, adding more rules can regress Claude Code quality. Augment Code (April 2026) tested Karpathy rules across Auggie, Claude Code, and Codex on 40 OpenClaw PRs: speed and cost improved on all three (−3% to −8% on duration and tool calls), but Claude Code quality dropped 0.07 overall (correctness −0.07, completeness −0.06, code reuse −0.05). Auggie and Codex were stable. Their hypothesis: Claude Code's system prompt already encodes similar constraints; further layering reduces exploration. When the rubric scores 9/10 or 10/10 on a Claude Code target, the default recommendation is trim, not add.
对照Anthropic官方最佳实践及社区验证的指导规范评估单个CLAUDE.md文件,然后提出具体的重写差异。仅在用户批准后应用修改。
一个经验性注意事项(针对Claude Code):当目标文件较短(<100行)且已符合Karpathy风格规则时,添加更多规则可能会降低Claude Code的质量。Augment Code(2026年4月)在40个OpenClaw PR上针对Auggie、Claude Code和Codex测试了Karpathy规则:三者的速度和成本均有所提升(时长和工具调用减少3%-8%),但Claude Code的整体质量下降了0.07(正确性-0.07、完整性-0.06、代码复用性-0.05)。Auggie和Codex则保持稳定。他们的假设是:Claude Code的系统提示已包含类似约束,额外添加规则会减少探索性。当针对Claude Code的目标文件评估得分达到9/10或10/10时,默认建议是精简内容,而非添加规则。

The Rubric

评估准则

Ten checks, each backed by a primary source. Every recommendation cites the rule.
#RuleSource
R1Length under 200 lines. Longer reduces adherence.Anthropic — How Claude remembers your project
R2Removability test on every line.Anthropic — Claude Code Best Practices
R3Specificity: instructions concrete enough to verify. No "be a senior engineer."Anthropic — Memory docs
R4Emphasis on load-bearing rules.
IMPORTANT:
/
YOU MUST
/
NEVER
. Use sparingly — if every rule is IMPORTANT, none are.
Anthropic — Best Practices
R5Markdown structure: headers + bullets. Not dense paragraphs.Anthropic — Memory docs
R65 canonical sections present (Commands, Architecture, Rules, Workflow, Out-of-scope).Community consensus + Anthropic
/init
template
R7Hard Rules section ≤15 items. Beyond that, rules drop.Community (zodchiii thread, 1.3M views)
R83-tier hierarchy used correctly. Across files: global rules in
~/.claude/CLAUDE.md
, project in
./CLAUDE.md
(git), personal in
./CLAUDE.local.md
(gitignored). No duplication across tiers. Within a file: order by priority — hard non-negotiables at top, context-dependent rules middle, references/conveniences bottom. The instruction budget compresses lower-priority items first.
Anthropic — Best Practices; Fraser (Medium, May 2026)
R9Path-scoped rules in
.claude/rules/*.md
when instructions only apply to certain files.
Anthropic — Advanced Patterns PDF
R10No content auto memory will capture, and no standard-tool documentation. Don't waste lines on stack details Claude figures out from
package.json
, nor on standard tools Claude already knows (
git
,
gh
,
npm
,
pnpm
,
bun
,
cargo
,
python
,
node
,
tsc
,
eslint
,
prettier
,
make
). Document only custom wrappers or non-obvious project-specific invocations.
Community + Anthropic auto-memory docs; Fraser (Medium, May 2026)
共10项检查,每项均有主要来源支撑。所有建议均会引用对应规则。
编号规则来源
R1长度不超过200行。过长会降低指令遵循度。Anthropic —— Claude如何记忆你的项目
R2对每一行执行可移除性测试Anthropic —— Claude代码最佳实践
R3明确性:指令需具体到可验证。禁止使用类似"成为资深工程师"的表述。Anthropic —— 记忆文档
R4重点突出核心规则。使用
IMPORTANT:
/
YOU MUST
/
NEVER
等标识,但需谨慎使用——若所有规则都标记为IMPORTANT,就没有真正的重点了。
Anthropic —— 最佳实践
R5Markdown结构:使用标题+列表。避免密集段落。Anthropic —— 记忆文档
R6包含5个标准章节(命令、架构、规则、工作流、超出范围)。社区共识 + Anthropic
/init
模板
R7硬规则章节≤15条。超过此数量,规则的执行效果会下降。社区(zodchiii帖子,130万浏览量)
R8正确使用三层层级结构。跨文件层级:全局规则存于
~/.claude/CLAUDE.md
,项目规则存于
./CLAUDE.md
(纳入git),个人规则存于
./CLAUDE.local.md
(git忽略)。层级间禁止重复内容。文件内部层级:按优先级排序——顶部为硬性不可协商规则,中间为上下文相关规则,底部为参考/便利内容。指令预算会优先压缩低优先级内容。
Anthropic —— 最佳实践;Fraser(Medium,2026年5月)
R9路径范围规则存于
.claude/rules/*.md
,当指令仅适用于特定文件时使用。
Anthropic —— 高级模式PDF
R10不包含自动记忆可捕获的内容,也不包含标准工具文档。不要在文件中浪费篇幅记录Claude可从
package.json
中获取的栈信息,也不要记录Claude已熟知的标准工具(
git
gh
npm
pnpm
bun
cargo
python
node
tsc
eslint
prettier
make
)。仅记录自定义包装器或非显而易见的项目特定调用方式。
社区 + Anthropic自动记忆文档;Fraser(Medium,2026年5月)

Improve Mode Procedure

优化模式流程

Phase I-1: SCOPE

阶段I-1:范围确定

  1. Resolve the target file. If multiple candidates exist, list them and ask.
  2. Read the file in full. Note size (lines, characters).
  3. Read sibling files for cross-tier duplication detection:
    • ~/.claude/CLAUDE.md
      (if improving a project file)
    • ./CLAUDE.local.md
      (if present)
    • ./.claude/rules/*.md
      (path-scoping in use?)
  1. 确定目标文件。若存在多个候选文件,列出并询问用户选择。
  2. 完整读取文件,记录大小(行数、字符数)。
  3. 读取关联文件以检测跨层级重复内容:
    • ~/.claude/CLAUDE.md
      (若优化项目文件)
    • ./CLAUDE.local.md
      (若存在)
    • ./.claude/rules/*.md
      (是否使用路径范围规则?)

Phase I-2: MEASURE

阶段I-2:评估

Run the 10-rule rubric programmatically where possible:
bash
LINES=$(wc -l < "$TARGET")                                   # R1
grep -c -iE 'IMPORTANT|YOU MUST|NEVER' "$TARGET"             # R4
grep -c '^#' "$TARGET"                                       # R5
尽可能通过程序执行10条准则的检查:
bash
LINES=$(wc -l < "$TARGET")                                   # R1
grep -c -iE 'IMPORTANT|YOU MUST|NEVER' "$TARGET"             # R4
grep -c '^#' "$TARGET"                                       # R5

R10: cross-reference against package.json / pyproject.toml / Cargo.toml / etc.

R10: 与package.json / pyproject.toml / Cargo.toml等文件交叉验证


Produce a per-rule scorecard with line-level evidence.

生成包含行级证据的逐规则评分卡。

Phase I-3: PROPOSE

阶段I-3:提出建议

Three categories of change:
Deletions (lines failing R2 or R10):
- DELETE line N: "[content]"
  Reason: [R2 — would Claude actually make a mistake without this?]
  OR: [R10 — auto memory captures this from package.json]
Additions (missing canonical sections per R6):
+ ADD section "## [Section Name]" with:
  [proposed content based on actual project — read package.json, README, .git/config]
Rewrites (specificity R3 + emphasis R4):
~ REPLACE line N: "[vague content]"
  WITH: "[concrete, verifiable rewrite]"
  Reason: [R3: was vague | R4: high-impact rule needs IMPORTANT prefix]
三类修改建议:
删除(未通过R2或R10的行):
- 删除第N行:"[内容]"
  原因:[R2 —— 删除该行后Claude真的会犯错吗?]
  或:[R10 —— 自动记忆可从package.json中捕获此内容]
添加(缺少R6规定的标准章节):
+ 添加章节"## [章节名称]",内容如下:
  [基于实际项目的建议内容——读取package.json、README、.git/config]
重写(针对R3明确性 + R4重点突出):
~ 替换第N行:"[模糊内容]"
  为:"[具体、可验证的重写内容]"
  原因:[R3:原内容模糊 | R4:高影响规则需添加IMPORTANT前缀]

Phase I-4: PRESENT

阶段I-4:呈现建议

markdown
undefined
markdown
undefined

CLAUDE.md Improvement Proposal

CLAUDE.md优化提案

File: [path] Current size: N lines (R1 budget: 200) Rubric pass rate: M of 10
文件: [路径] 当前大小: N行(R1预算:200行) 准则通过率: 10项中通过M项

Summary

摘要

  • DELETE: K lines
  • ADD: L sections
  • REWRITE: J lines
  • Net change: ±N lines (final: M lines)
  • 删除:K行
  • 添加:L个章节
  • 重写:J行
  • 净变化:±N行(最终:M行)

Proposed Diff

建议差异

[full diff with reasons]
Apply these changes? (yes / partial / no)
undefined
[完整差异及原因]
是否应用这些修改?(是/部分应用/否)
undefined

Phase I-5: APPLY

阶段I-5:应用修改

Use the
Edit
tool for surgical changes — never overwrite the whole file with
Write
. Apply one change at a time. After all changes:
  1. Re-measure: print new size, new rubric pass rate.
  2. Suggest: "Run
    /claude-md audit
    afterward to verify no drift introduced."
  3. If the file now has obvious path-scoped subsections, suggest splitting them into
    .claude/rules/<topic>.md
    (R9).
使用
Edit
工具进行精准修改——绝不使用
Write
覆盖整个文件。逐个应用修改。完成所有修改后:
  1. 重新评估:打印新的文件大小和准则通过率。
  2. 建议:"之后运行
    /claude-md audit
    以验证未引入内容偏差。"
  3. 若文件现在存在明显的路径范围子章节,建议将其拆分到
    .claude/rules/<主题>.md
    (R9)。

The 5 Canonical Sections (R6 detail)

5个标准章节(R6细节)

A CLAUDE.md scoring well on R6 contains these sections. Suggest creating any that are missing:
  1. ## Project
    (1–2 lines: what this is, who uses it)
  2. ## Stack
    (1–3 lines: framework, language, deployment target)
  3. ## Commands
    (Build / Dev / Test single / Test all / Lint / Type check — short, exact)
  4. ## Architecture
    (folder → purpose mapping; not full directory listing)
  5. ## Rules
    (under 15 items; negative rules count; emphasis on the load-bearing one)
  6. ## Workflow
    (how the user wants Claude to approach tasks: minimal changes, ask vs act, commit conventions)
  7. ## Out of scope
    (files/integrations Claude should not touch)
在R6上得分较高的CLAUDE.md包含以下章节。建议创建所有缺失的章节:
  1. ## 项目
    (1-2行:项目简介、使用者)
  2. ## 技术栈
    (1-3行:框架、语言、部署目标)
  3. ## 命令
    (构建/开发/单测/全量测试/代码检查/类型检查——简短、精确)
  4. ## 架构
    (文件夹→用途映射;无需完整目录列表)
  5. ## 规则
    (不超过15条;包含禁止性规则;重点突出核心规则)
  6. ## 工作流
    (用户希望Claude处理任务的方式:最小化修改、询问 vs 直接操作、提交规范)
  7. ## 超出范围
    (Claude不应修改的文件/集成)

High-Impact Lines That Compound

可产生复合效果的高影响力规则

A menu to draw from when a file is genuinely missing a scope-control or safety rule. Subject to the trim-not-add caveat above: on an already-aligned Claude Code target scoring 9–10/10, do not bulk-add these — Claude Code's system prompt already encodes most of them, and layering regresses quality (Augment Code, April 2026). Add the one or two that close a real, observed gap; skip the rest.
Scope & safety (highest leverage — prevent expensive, hard-to-revert mistakes):
  • Only modify files, functions, and lines directly related to the current task. Do not refactor, rename, or reformat anything I did not ask you to change. Note other issues at the end; don't touch them.
  • Before any change that significantly alters existing content (rewriting sections, restructuring, changing tone): stop, describe what you're about to change and why, wait for confirmation.
  • Before deleting a file, overwriting code, dropping records, or removing dependencies: stop, list what will be affected, ask for explicit confirmation in the current message. "You mentioned this earlier" is not confirmation.
  • Production hard-stops requiring in-session confirmation: deploys/pushes, migrations or schema changes, outbound API calls, any command with irreversible side effects.
    (If a stop must hold 100% of the time, a PreToolUse hook is the real enforcement — CLAUDE.md compliance ceilings around 80%.)
  • After any coding task, end with: files changed, one-line summary per file, files intentionally not touched, follow-up needed.
  • NEVER commit .env files or secrets
  • NEVER run git push --force without explicit confirmation
Workflow:
  • IMPORTANT: run type check after every code change
  • Make minimal changes, don't refactor unrelated code
  • Create separate commits per logical change, not one giant commit
  • When unsure between two approaches, explain both and let me choose
  • For architecture decisions or non-trivial features: work through the problem step by step before writing code. Show reasoning and where you're uncertain, then implement.
Communication (lowest marginal value on Claude Code — its system prompt already does most of this; add only if you observe the specific failure):
  • Match response length to task complexity. Don't pad with restatements of the question or closing summaries.
  • If uncertain about a fact, statistic, date, or technical detail, say so explicitly rather than filling the gap with plausible-sounding content.
Wording sourced from the Karpathy-derived rule compilations (Fraser, May 2026; "Dep" thread, May 2026). Their headline stats ("65% → 94% accuracy", per-developer dollar figures, star counts) are illustrative marketing, not measured results — cite the rule wording, not the numbers.
当文件确实缺少范围控制或安全规则时,可从以下列表中选择添加。需遵循前文提到的"精简而非添加"注意事项:对于已符合要求、得分9-10/10的Claude Code目标文件,不要批量添加这些规则——Claude Code的系统提示已包含其中大部分内容,额外添加会降低质量(Augment Code,2026年4月)。仅添加1-2条填补实际观察到的漏洞的规则;其余规则跳过。
范围与安全(最高杠杆作用——防止昂贵、难以回滚的错误):
  • 仅修改与当前任务直接相关的文件、函数和代码行。不要重构、重命名或格式化任何我未要求修改的内容。在结尾处记录其他问题,但不要改动它们。
  • 在进行任何显著修改现有内容的操作(重写章节、调整结构、更改语气)之前:停止操作,描述你将要修改的内容及原因,等待确认。
  • 在删除文件、覆盖代码、删除记录或移除依赖之前:停止操作,列出受影响的内容,请求当前消息中的明确确认。"你之前提到过"不算确认。
  • 生产环境硬停止规则,需会话内确认:部署/推送、迁移或 schema 变更、对外API调用、任何具有不可逆副作用的命令。
    (若规则必须100%执行,PreToolUse钩子才是真正的执行保障——CLAUDE.md的合规率约为80%。)
  • 完成任何编码任务后,结尾需包含:修改的文件、每个文件的一行摘要、有意未修改的文件、后续需要处理的事项。
  • 绝不要提交.env文件或秘密信息
  • 绝不要在未获得明确确认的情况下运行git push --force
工作流:
  • 重要提示:每次代码修改后运行类型检查
  • 最小化修改,不要重构无关代码
  • 按逻辑拆分提交,不要合并成一个大提交
  • 当不确定两种方案时,解释两种方案并让我选择
  • 对于架构决策或非 trivial 功能:在编写代码前逐步分析问题。展示推理过程和不确定的地方,然后再实现。
沟通(对Claude Code边际价值最低——其系统提示已包含大部分内容;仅在观察到特定问题时添加):
  • 响应长度与任务复杂度匹配。不要重复问题或添加冗余的结尾总结。
  • 若不确定事实、统计数据、日期或技术细节,明确说明,不要用看似合理的内容填补空白。
规则措辞源自基于Karpathy规则的汇编(Fraser,2026年5月;"Dep"帖子,2026年5月)。他们的标题统计数据("准确率从65%提升至94%"、每位开发者成本数据、星标数量)仅为说明性营销内容,并非实测结果——引用规则措辞即可,不要引用数字。

What NOT to Include (anti-patterns)

不应包含的内容(反模式)

  • Personality instructions ("be a senior engineer")
  • Code-formatter rules the linter already handles
  • Duplicate rules across tiers
  • @-imports
    of full README / huge docs (they enter the context window at launch)
  • Anything Claude learns on its own via auto memory
  • (V2) Auto-generated bulk. Never
    /init
    -and-forget or paste an LLM-generated context file. Controlled study: a curated context file gives ~+4pp task quality at ~20% token overhead, but an auto-generated one reduces task success ~0.5–2% while raising cost 20–23%. Curate ruthlessly; more context is not better. (arXiv 2026, AGENTS.md efficiency study.)

  • 人格指令("成为资深工程师")
  • 代码格式化规则(应由linter处理)
  • 跨层级重复规则
  • @-import
    完整README或大型文档(它们会在启动时进入上下文窗口)
  • Claude可通过自动记忆自行学习的内容
  • (V2) 自动生成的批量内容。绝不要使用
    /init
    生成后就不管,也不要粘贴LLM生成的上下文文件。对照研究显示:精心整理的上下文文件可使任务质量提升约4个百分点,同时增加约20%的token开销;而自动生成的上下文文件会降低任务成功率0.5-2%,同时增加20-23%的成本。务必精心整理;更多上下文并不一定更好。(arXiv 2026,AGENTS.md效率研究。)

Audit Mode

审计模式

Lint and audit CLAUDE.md files across all projects. Flags drift (claimed facts no longer matching code), leaked secrets, duplicate blocks, descriptive-vs-prescriptive line balance, and files approaching the 150-200 instruction budget.
CLAUDE.md files rot. In practice, a portfolio audit will routinely surface several projects with drifted CLAUDE.md — and occasionally one with a leaked secret. This mode catches both shapes in one pass.
对所有项目中的CLAUDE.md文件进行代码检查和审计。标记内容偏差(文档声明的信息与代码实际情况不符)、秘密泄露、重复块、描述性与指令性内容比例失衡,以及接近150-200行指令预算的文件。
CLAUDE.md文件会逐渐失效。实际操作中,组合审计通常会发现多个项目的CLAUDE.md存在内容偏差——偶尔还会发现存在秘密泄露的文件。本模式可一次性排查这两类问题。

Audit Mode Procedure

审计模式流程

Phase A-1: DISCOVER

阶段A-1:发现文件

  1. Find every
    CLAUDE.md
    under your projects roots (adjust to where you keep code, e.g.
    ~/Projects
    ,
    ~/work
    ):
    bash
    find ~/Projects ~/work -name 'CLAUDE.md' \
      -not -path '*/node_modules/*' -not -path '*/.venv/*' -not -path '*/vendor/*' 2>/dev/null
  2. For each file, note the owning project and size (line count).
  1. 在项目根目录下查找所有
    CLAUDE.md
    文件(可调整为你的代码存储路径,如
    ~/Projects
    ~/work
    ):
    bash
    find ~/Projects ~/work -name 'CLAUDE.md' \
      -not -path '*/node_modules/*' -not -path '*/.venv/*' -not -path '*/vendor/*' 2>/dev/null
  2. 记录每个文件所属项目及大小(行数)。

Phase A-2: SECRET SCAN (ALWAYS RUN FIRST)

阶段A-2:秘密扫描(始终优先执行)

For each CLAUDE.md, grep for high-confidence secret patterns. This phase runs before any other audit because a leak is a P0 finding that interrupts the rest of the flow.
Patterns to flag:
  • (?i)(secret|token|api[_-]?key|password)\s*[:=]\s*['"]\S{8,}['"]
  • (?i)auth[_-]?secret\s*[:=]\s*\S{8,}
  • Base64-ish JWT prefixes:
    eyJ[A-Za-z0-9_-]{10,}
  • URLs with embedded credentials:
    https?://[^:/\s]+:[^@\s]+@
  • Stripe/OpenAI/Anthropic key prefixes:
    sk_live_
    ,
    sk_test_
    ,
    pk_live_
    ,
    sk-ant-
    ,
    sk-proj-
  • Supabase/Neon connection strings:
    postgres(ql)?://[^:]+:[^@]+@
If any match: mark file 🔴 P0 LEAK. Report the line, pattern matched, required remediation: rotate the secret in source system, edit CLAUDE.md to reference env var names only, scrub git history (
git filter-repo --path CLAUDE.md --invert-paths
or BFG).
对每个CLAUDE.md文件,使用grep查找高置信度的秘密模式。此阶段优先于其他审计步骤,因为泄露是P0级问题,会中断后续流程。
需标记的模式:
  • (?i)(secret|token|api[_-]?key|password)\s*[:=]\s*['"]\S{8,}['"]
  • (?i)auth[_-]?secret\s*[:=]\s*\S{8,}
  • Base64格式的JWT前缀:
    eyJ[A-Za-z0-9_-]{10,}
  • 包含嵌入式凭证的URL:
    https?://[^:/\s]+:[^@\s]+@
  • Stripe/OpenAI/Anthropic密钥前缀:
    sk_live_
    ,
    sk_test_
    ,
    pk_live_
    ,
    sk-ant-
    ,
    sk-proj-
  • Supabase/Neon连接字符串:
    postgres(ql)?://[^:]+:[^@]+@
**若发现匹配项:**标记文件为🔴 P0级泄露。报告行号、匹配模式及所需修复措施:在源系统中轮换秘密,将CLAUDE.md中的内容修改为仅引用环境变量名称,清理git历史(使用
git filter-repo --path CLAUDE.md --invert-paths
或BFG工具)。

Phase A-3: DRIFT DETECTION

阶段A-3:偏差检测

For each claim CLAUDE.md makes, verify against real code:
  1. MCP servers — diff against
    settings.json
    /
    .mcp.json
    /
    mcp.json
  2. API routes — grep for routes named in CLAUDE.md; verify each exists in
    src/app/api/
    or routes file
  3. Cron jobs — count asserted vs actual
    */cron*
    files /
    vercel.json
    crons /
    wrangler.toml
    triggers
  4. Env vars — every env var named should appear in
    .env.example
    or be read by code (
    process.env.<NAME>
    /
    os.environ["<NAME>"]
    )
  5. External services — flag contradictions ("uses Brevo SMTP" but code imports
    @getbrevo/brevo
    REST client)
  6. Directory structure — diff enumerated dirs against
    ls
    output
For each drift finding: report the CLAUDE.md line, the actual code fact, and the one-line edit that fixes it.
验证CLAUDE.md中声明的每项内容是否与实际代码一致:
  1. MCP服务器 —— 与
    settings.json
    /
    .mcp.json
    /
    mcp.json
    对比
  2. API路由 —— 查找CLAUDE.md中命名的路由;验证每个路由是否存在于
    src/app/api/
    或路由文件中
  3. 定时任务 —— 统计声明的定时任务与实际
    */cron*
    文件 /
    vercel.json
    定时任务 /
    wrangler.toml
    触发器的数量
  4. 环境变量 —— 每个命名的环境变量应出现在
    .env.example
    中或被代码读取(
    process.env.<NAME>
    /
    os.environ["<NAME>"]
  5. 外部服务 —— 标记矛盾内容(如"使用Brevo SMTP"但代码导入
    @getbrevo/brevo
    REST客户端)
  6. 目录结构 —— 将枚举的目录与
    ls
    输出对比
对于每个偏差发现:报告CLAUDE.md中的行号、实际代码情况以及一行修复建议。

Phase A-4: DUPLICATE + STRUCTURE CHECKS

阶段A-4:重复内容与结构检查

  1. Detect duplicate section headings (
    ^## 
    ,
    ^### 
    appearing ≥2 times)
  2. Detect near-duplicate paragraphs (same first 60 characters on two different lines)
  3. Report any line contradicting another line in the same file
  1. 检测重复的章节标题(
    ^## 
    ^### 
    出现≥2次)
  2. 检测近乎重复的段落(两行内容前60个字符相同)
  3. 报告文件中相互矛盾的行

Phase A-5: INSTRUCTION BUDGET + PRESCRIPTIVE RATIO

阶段A-5:指令预算与指令性比例

  1. Count instructions — any line starting with imperative verb (Always, Never, Use, Don't, Prefer, Avoid, Run, Check, Write, Edit, Follow) OR inside a bullet list under "Rules/Conventions/Do/Don't" heading
  2. Budget thresholds:
    • ≤ 100 instructions: 🟢 healthy
    • 100–200: 🟡 monitor
    • 200: 🟠 over budget — suggest splits or cuts
  3. Descriptive vs prescriptive classifier:
    • Descriptive = describes what code already shows ("this is a Next.js app with Postgres")
    • Prescriptive = tells Claude what to do ("when editing migrations, add both up and down") Report ratio. Descriptive lines are budget waste.
  1. 统计指令数量——任何以祈使动词开头的行(Always、Never、Use、Don't、Prefer、Avoid、Run、Check、Write、Edit、Follow)或位于"Rules/Conventions/Do/Don't"标题下的列表项
  2. 预算阈值:
    • ≤ 100条指令:🟢 健康
    • 100–200条指令:🟡 监控
    • 200条指令:🟠 超出预算——建议拆分或精简
  3. 描述性与指令性内容分类:
    • 描述性 = 描述代码已有的情况("这是一个使用Postgres的Next.js应用")
    • 指令性 = 告诉Claude要做什么("编辑迁移文件时,需同时添加up和down方法") 报告两者比例。描述性内容属于预算浪费。

Phase A-5.5: HOOK-CANDIDATE DETECTION

阶段A-5.5:钩子候选检测

CLAUDE.md instructions are advisory — community evidence puts compliance around 70–80%. Rules phrased as absolute commands fail this ceiling silently. Scan for deterministic-sounding rules and flag them for hook conversion.
Patterns to flag:
  • Lines starting with
    NEVER
    ,
    Never
    ,
    Always
    ,
    MUST
    ,
    Do not
    followed by a verb
  • Rules naming destructive commands:
    rm -rf
    ,
    git push --force
    ,
    git reset --hard
    ,
    DROP TABLE
    ,
    truncate
    ,
    vercel --prod
    ,
    gcloud ... delete
  • Rules requiring 100% pre-commit gates: lint, typecheck, test must pass before commit
For each match: report the line, classify as
hook-candidate
, and identify the right hook type:
  • Destructive command gates →
    PreToolUse
    hook returning exit code 2 to block
  • Pre-commit verification →
    PreToolUse
    on git commit or
    PostToolUse
    on file Edit/Write
  • Always-run-after-edit checks →
    PostToolUse
    hook
Report wording: "This rule reads as deterministic but lives in advisory territory. Convert to a hook in
.claude/settings.json
for 100% enforcement; keep the CLAUDE.md line as documentation of the hook's intent, or remove it." Cite Anthropic hooks docs and the ~80% advisory ceiling.
CLAUDE.md中的指令仅为建议——社区数据显示合规率约为70-80%。表述为绝对命令的规则会在这个合规率上限下失效。扫描确定性表述的规则并标记为可转换为钩子的候选。
需标记的模式:
  • NEVER
    Never
    Always
    MUST
    Do not
    加动词开头的行
  • 涉及破坏性命令的规则:
    rm -rf
    git push --force
    git reset --hard
    DROP TABLE
    truncate
    vercel --prod
    gcloud ... delete
  • 要求100%提交前检查的规则:提交前必须通过lint、类型检查、测试
对于每个匹配项:报告行号,分类为
hook-candidate
,并确定合适的钩子类型:
  • 破坏性命令拦截 → 返回退出码2的
    PreToolUse
    钩子
  • 提交前验证 → git提交时的
    PreToolUse
    钩子或文件编辑/写入后的
    PostToolUse
    钩子
  • 编辑后必须执行的检查 →
    PostToolUse
    钩子
报告措辞:"此规则表述为确定性命令,但仅属于建议范畴。将其转换为
.claude/settings.json
中的钩子可实现100%执行;可保留CLAUDE.md中的该行作为钩子意图的文档,或直接删除。"引用Anthropic钩子文档及约80%的建议合规率上限。

Phase A-6: REPORT

阶段A-6:生成报告

Output grouped by severity, per project:
undefined
按严重程度分组,按项目输出:
undefined

CLAUDE.md Audit Report — <timestamp>

CLAUDE.md审计报告 —— <时间戳>

Summary

摘要

  • 6 CLAUDE.md files scanned
  • 1 P0 LEAK (acme-web)
  • 2 projects with drift (data-pipeline, saas-app)
  • 0 over budget
  • 3 projects clean

  • 扫描了6个CLAUDE.md文件
  • 1个P0级泄露(acme-web)
  • 2个项目存在内容偏差(data-pipeline、saas-app)
  • 0个文件超出预算
  • 3个项目无问题

acme-web 🔴 P0 LEAK

acme-web 🔴 P0级泄露

File: ~/Projects/acme-web/CLAUDE.md (142 instructions)
文件: ~/Projects/acme-web/CLAUDE.md(142条指令)

Leaks (P0 — rotate before any other work)

泄露(P0级——优先处理,轮换秘密)

  • Line 38:
    AUTH_SECRET=...
    (value redacted in report)
    • Fix: replace with
      The AUTH_SECRET env var is required; see .env.example
    • Rotate the secret in production, then
      git filter-repo --path CLAUDE.md --invert-paths
  • 第38行:
    AUTH_SECRET=...
    (报告中已隐藏值)
    • 修复:替换为
      需要AUTH_SECRET环境变量;请查看.env.example
    • 在生产环境中轮换秘密,然后执行
      git filter-repo --path CLAUDE.md --invert-paths

Drift

内容偏差

  • Line 52: claims "Brevo SMTP" — code uses REST (
    @getbrevo/brevo
    at src/lib/email.ts:4)
    • Fix: change to "Brevo REST API via @getbrevo/brevo"
  • 第52行:声明"使用Brevo SMTP"——代码使用REST客户端(
    @getbrevo/brevo
    位于src/lib/email.ts:4)
    • 修复:修改为"通过@getbrevo/brevo使用Brevo REST API"

Duplicates

重复内容

  • "## Email" heading appears at lines 50 and 89
undefined
  • "## 邮件"标题出现在第50行和第89行
undefined

Phase A-7: OFFER FIXES (INTERACTIVE)

阶段A-7:提供修复选项(交互式)

After the report, ask: "Apply the suggested edits for <project X>? [y/N]". Apply only after confirmation. Do NOT apply P0 LEAK fixes automatically — they require secret rotation and git-history scrub the user must drive.

报告生成后,询问:"是否应用<项目X>的建议修改?[是/否]"。仅在确认后应用修改。不要自动应用P0级泄露的修复措施——用户必须自行处理秘密轮换和git历史清理。

Quality Bar (both modes)

质量标准(两种模式均适用)

A run passes if every check is true. Otherwise rewrite the offending recommendation.
  • Every deletion / drift finding cites the rule it enforces (R1–R10 in improve; specific drift type in audit)
  • Every addition uses real project data (read
    package.json
    ,
    pyproject.toml
    , etc.) — not generic placeholders
  • Every rewrite provides a concrete replacement, not "make this clearer"
  • No proposal uses "consider", "perhaps", "you might want to" — every suggestion is concrete and accept/reject-able
  • Summaries contain exact counts, not estimates
  • P0 LEAK findings always present before any other audit content (audit mode)
只有当所有检查均通过时,执行才算合格。否则需重写有问题的建议。
  • 每个删除/偏差发现均需引用其执行的规则(优化模式为R1–R10;审计模式为具体偏差类型)
  • 每个添加的内容均需使用实际项目数据(读取
    package.json
    pyproject.toml
    等)——不得使用通用占位符
  • 每个重写建议均需提供具体的替换内容,而非"使其更清晰"
  • 建议中不得使用"考虑"、"也许"、"你可能想要"等表述——每个建议都必须具体且可接受/拒绝
  • 摘要需包含精确计数,而非估算值
  • P0级泄露发现必须始终排在审计内容的最前面(审计模式)

Gotchas (both modes)

注意事项(两种模式均适用)

  • Do not auto-apply. Always present for approval. Surgical Edits only — never whole-file Write.
  • Do not invent project context. Read
    package.json
    /
    pyproject.toml
    /
    Cargo.toml
    /
    Gemfile
    /
    README.md
    to ground suggestions in actual project data.
  • Do not propose splitting into
    .claude/rules/
    automatically.
    Suggest it; the user decides.
  • Do not rotate secrets or scrub git history. Audit reports leaks and guides; user drives the rotation + history scrub.
  • Do not enforce a specific style across repos. Each repo's existing voice is respected. Improve mode rewrites for STRUCTURE, not VOICE.
  • Do not flag perfectly fine lines. A line that fails the removability test must actually fail it — not "could maybe be tighter."
  • Do not add a rule on first occurrence of a mistake. Log it in MEMORY.md or a scratch list. Promote to CLAUDE.md only after the second occurrence. Improves signal-to-noise; cuts noise rules that bloat the file without preventing real mistakes. (Source: Redreamality, April 2026.)
  • Do not hardcode user paths. Use
    $TARGET
    ,
    $HOME
    ,
    $1
    . Never
    /Users/<name>/...
    .
  • 不要自动应用修改。始终先呈现建议并等待批准。仅使用精准编辑——绝不覆盖整个文件。
  • 不要编造项目上下文。读取
    package.json
    /
    pyproject.toml
    /
    Cargo.toml
    /
    Gemfile
    /
    README.md
    以确保建议基于实际项目数据。
  • 不要自动建议拆分到
    .claude/rules/
    。仅提出建议;由用户决定是否执行。
  • 不要轮换秘密或清理git历史。审计报告仅指出泄露并提供指导;用户需自行处理秘密轮换和历史清理。
  • 不要在仓库间强制统一风格。每个仓库的现有风格需得到尊重。优化模式仅重写结构,而非风格。
  • 不要标记完全没问题的行。未通过可移除性测试的行必须确实不符合要求——而非"可能可以更简洁"。
  • 不要在首次出现错误时就添加规则。将错误记录在MEMORY.md或临时列表中。仅在第二次出现相同错误时才将规则添加到CLAUDE.md。这样可提升信噪比;减少无意义的规则,避免文件冗余且无法防止实际错误。(来源:Redreamality,2026年4月。)
  • 不要硬编码用户路径。使用
    $TARGET
    $HOME
    $1
    。绝不要使用
    /Users/<用户名>/...

Changelog

更新日志

V2 (2026-05-27)

V2(2026-05-27)

Optimized via
skillforge optimize
(outcome research on AI-native repo / AGENTS.md best practices).
  • AGENTS.md support — audit/improve the cross-agent standard, not just CLAUDE.md; flag CLAUDE.md/AGENTS.md duplication and recommend one-source-of-truth.
  • "Never auto-generate" anti-pattern with the controlled-study evidence (curated +4pp vs auto-generated −0.5–2% / +20–23% cost). Strengthens the existing trim-not-add doctrine.
  • Outcome target: the skill now improves the file that actually changes agent behavior across harnesses, and actively prevents the bloat that degrades it. Sources: AGENTS.md efficiency study (arXiv 2026); agents.md standard; Augment Code AGENTS.md guide.
通过
skillforge optimize
优化(基于AI原生仓库/AGENTS.md最佳实践的成果研究)。
  • 支持AGENTS.md —— 审计/优化跨Agent标准,而非仅CLAUDE.md;标记CLAUDE.md/AGENTS.md的重复内容并建议单一事实来源。
  • 添加"绝不自动生成"反模式及对照研究证据(精心整理的内容提升4个百分点,自动生成的内容降低0.5-2%成功率/增加20-23%成本)。强化了现有的"精简而非添加"原则。
  • 目标成果:本技能现在可优化实际影响多工具Agent行为的文件,并主动防止导致性能下降的冗余内容。来源:AGENTS.md效率研究(arXiv 2026)agents.md标准;Augment Code AGENTS.md指南。

Sibling Skills

关联技能

SkillWhen
/claude-md improve
One file, structural rewrite for best-practice alignment
/claude-md audit
Many files, hygiene / drift / secret scan
/init
(Anthropic built-in)
Generate a starter CLAUDE.md from current project state
compound-engineering:ce-compound-refresh
Same spirit, different target — refreshes
docs/solutions/
技能适用场景
/claude-md improve
单文件,为符合最佳实践进行结构重写
/claude-md audit
多文件,卫生检查/内容偏差/秘密扫描
/init
(Anthropic内置)
根据当前项目状态生成初始CLAUDE.md
compound-engineering:ce-compound-refresh
理念相同,目标不同——刷新
docs/solutions/

References

参考资料

Anthropic primary sources:
Community sources (consistent with primary):
Related discipline:
  • Strunk & White — The Elements of Style — Rule 17 ("Omit needless words") is the upstream principle behind Anthropic's removability test
Anthropic主要来源:
社区来源(与主要来源一致):
相关学科:
  • Strunk & White —— The Elements of Style —— 第17条规则("省略不必要的词")是Anthropic可移除性测试的上游原则

Testing

测试

Run the structural eval:
bash
bash tests/eval.sh
To verify behavior end-to-end:
  1. Improve:
    /claude-md improve
    in any project — verify rubric scorecard cites every R1–R10, every change cites its rule, "no" reply writes nothing, "yes" applies surgically
  2. Audit:
    /claude-md audit all
    — verify P0 LEAK section appears first when leaks present, drift findings cite specific code locations, instruction budget reported per file
  3. Auto-detect:
    /claude-md
    (no args) in a project with CLAUDE.md → improve runs; in
    ~/
    with no local file → audit runs
  4. Mode override:
    /claude-md audit ./CLAUDE.md
    → single-file audit (subset of audit, single target)
运行结构评估:
bash
bash tests/eval.sh
端到端验证行为:
  1. 优化:在任意项目中执行
    /claude-md improve
    ——验证评分卡引用了所有R1–R10规则,每个修改均引用对应规则,回复"否"时不写入任何内容,回复"是"时精准应用修改
  2. 审计:执行
    /claude-md audit all
    ——验证存在泄露时P0级泄露部分排在最前面,偏差发现引用具体代码位置,每个文件均报告指令预算
  3. 自动检测:在存在CLAUDE.md的项目中执行
    /claude-md
    (无参数)→ 运行优化模式;在
    ~/
    无本地文件时执行→运行审计模式
  4. 模式覆盖:执行
    /claude-md audit ./CLAUDE.md
    →单文件审计(审计模式的子集,仅针对单个目标)