CLAUDE.md template

    一份能保持 lintable的 CLAUDE.md 模板。

    从一份紧凑 skeleton 开始:project facts、硬规则、沟通方式、原则和 enforcement。填完后,把不会让 agent 更可靠的东西删掉。

    01 / 可复制 skeleton
    CLAUDE.md
    # CLAUDE.md
    
    ## Project
    - Name: [project name]
    - Purpose: [one sentence about what this repo ships]
    - Primary users: [who depends on this working]
    - Stack: [frameworks, runtime, package manager, database]
    - Source root: [main app directory]
    - Test command: [exact command]
    - Build command: [exact command]
    - Local run command: [exact command]
    
    ## Non-negotiables
    - Preserve user work. Do not overwrite unrelated local changes.
    - Do not print secrets, tokens, customer data, or private keys.
    - Do not run destructive data commands without explicit approval.
    - Keep edits scoped to the requested behavior.
    - Prefer the existing architecture before adding new abstractions.
    - Fix root causes rather than masking failing tests.
    - If two materially different fixes fail, stop and report what was tried.
    
    ## Language & Style
    - Match the surrounding code style and naming.
    - Keep comments sparse and useful.
    - Use TypeScript types already present in the codebase.
    - Avoid broad refactors unless the task requires them.
    - Keep user-facing copy direct and concrete.
    - Code, comments, and commits stay in English unless requested otherwise.
    - Do not introduce new dependencies without a clear reason.
    
    ## Operational Notes
    - Package manager: [npm/pnpm/yarn/bun]
    - Node version: [version or .nvmrc]
    - Environment file: [where env vars are documented]
    - CI source of truth: [workflow path]
    - Formatting command: [exact command]
    - Lint command: [exact command]
    - Database migration command: [exact command or none]
    - Generated files: [paths agents should not hand edit]
    - Release branch: [branch or release process]
    
    ## Communication
    - Start by stating the concrete files or systems being inspected.
    - For implementation work, make the smallest complete change.
    - Report verification commands and their results.
    - When blocked, name the blocker and the next useful choice.
    - Do not claim a command passed unless it was run in this session.
    - Keep summaries short and focused on behavior changed.
    
    ## Principles
    - Evidence beats assurance.
    - Durable rules belong in code, tests, CI, or this file.
    - Repo-specific instructions beat generic agent advice.
    - Prefer reversible changes with clear verification.
    - Keep the harness short enough that agents can actually use it.
    
    ## Enforcement
    - Required before handoff: [test command]
    - Required before UI handoff: [build or screenshot command]
    - Required before release changes: [release checklist command]
    - Security-sensitive paths: [paths needing extra review]
    - Protected commands: [commands requiring explicit approval]
    - If verification cannot run, explain why and name the residual risk.
    
    02 / 怎么填

    命令必须精确。

    把每个方括号里的命令换成新人能在 repo root 直接跑的命令。如果命令依赖 setup,就在 Operational Notes 里说清楚。

    Non-negotiables 要少。

    这一节只放保护用户工作、数据、发布或 repo 完整性的硬规则。偏好放到 style section 或本地 docs。

    能检查的事实要靠近 enforcement。

    如果一条规则可以被 CI、hook 或 script 检查,就写出那个机制。只有文字、没有 enforcement 的规则会弱很多。

    删掉过期例子。

    模板只有在保持新鲜时才有用。历史说明、旧 package manager、迁移残留,一旦不再指导工作,就删掉。

    填完之后,用 AgentLint 跑一遍。

    skeleton 只是起点。AgentLint 会检查最终 harness 是否具体、一致、可执行,而且没有过期;如果同一套规则还同步到 AGENTS.md 或 Cursor 规则(.cursor/rules),也要一起检查。

    安装 AgentLint