claude-md-authoring
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCLAUDE.md Authoring
CLAUDE.md编写
Quickstart
快速开始
- Determine scope: User-level () or project-level (
~/.claude/)?.claude/ - Apply WHAT/WHY/HOW framework (project-level only)
- Keep instructions under budget: ~50 for user-level, ~100 for project-level
- Never use Claude as a linter: Style rules belong in tooling, not CLAUDE.md
- Validate with quality checklist before finalizing
- 确定适用范围: 用户级别()还是项目级别(
~/.claude/)?.claude/ - 应用WHAT/WHY/HOW框架(仅项目级别适用)
- 将指令控制在预算内: 用户级别约50条,项目级别约100条
- 切勿将Claude用作linter: 样式规则属于工具配置范畴,不应写在CLAUDE.md中
- 最终确定前用质量检查清单验证
Core Principle
核心原则
"The only thing that the model knows about your codebase is the tokens you put into it."
CLAUDE.md is the highest-leverage point for context transfer. Every instruction competes for limited attention. Include only what Claude cannot infer and must apply universally.
"模型对你的代码库的所有认知都来自你输入的token。"
CLAUDE.md是上下文传递的最高效支点。每条指令都在抢占有限的注意力资源。仅包含Claude无法推断且必须普遍适用的内容。
Scope Decision
适用范围判定
User-Level (~/.claude/CLAUDE.md
)
~/.claude/CLAUDE.md用户级别(~/.claude/CLAUDE.md
)
~/.claude/CLAUDE.mdApplies to ALL projects. Include only:
- Personal working style preferences
- Relationship dynamics (pushback, honesty, communication)
- Universal philosophy (YAGNI, root-cause debugging)
- Proactiveness boundaries
Never include:
- Project-specific commands (build, test, lint)
- Tech stack details
- Style rules that vary by project
- Tool/framework references that don't exist everywhere
适用于所有项目。仅可包含:
- 个人工作风格偏好
- 互动模式(反馈方式、诚实度、沟通规则)
- 通用开发理念(YAGNI、根因调试等)
- 主动操作边界
切勿包含:
- 项目专属命令(构建、测试、lint)
- 技术栈细节
- 因项目而异的样式规则
- 并非所有环境都存在的工具/框架引用
Project-Level (.claude/CLAUDE.md
)
.claude/CLAUDE.md项目级别(.claude/CLAUDE.md
)
.claude/CLAUDE.mdApplies to ONE project. Use the WHAT/WHY/HOW framework:
WHAT (2-5 lines)
- Project purpose in one sentence
- Primary language/framework
- Key directories and their purposes
WHY (optional, 2-3 lines)
- Non-obvious architectural decisions
- Constraints that affect implementation choices
HOW (3-7 lines)
- Essential commands: build, test, lint, run
- Any project-specific workflows
- Where to find more documentation
适用于单个项目。使用WHAT/WHY/HOW框架:
WHAT(2-5行)
- 一句话说明项目用途
- 主要语言/框架
- 核心目录及其用途
WHY(可选,2-3行)
- 不符合直觉的架构决策
- 影响实现选择的约束条件
HOW(3-7行)
- 核心命令:构建、测试、lint、运行
- 所有项目专属工作流
- 更多文档的查找位置
Instruction Budget
指令预算
LLMs reliably follow ~150-200 instructions. Claude Code's system prompt uses ~50, leaving limited budget.
| Scope | Target | Maximum |
|---|---|---|
| User-level | ~30-40 | 60 |
| Project-level | ~50-80 | 120 |
| Combined | ~80-120 | 150 |
Counting instructions: Each actionable directive counts as one instruction.
- "NEVER skip tests" = 1 instruction
- "Use TypeScript for new files" = 1 instruction
- A 5-item list = 5 instructions
LLM可稳定遵循约150-200条指令。Claude Code的系统提示词已占用约50条,剩余预算有限。
| 适用范围 | 目标值 | 最大值 |
|---|---|---|
| 用户级别 | ~30-40 | 60 |
| 项目级别 | ~50-80 | 120 |
| 合计 | ~80-120 | 150 |
指令计数规则: 每条可执行的指令计为1条。
- "NEVER skip tests" = 1条指令
- "Use TypeScript for new files" = 1条指令
- 一个包含5项的列表 = 5条指令
Anti-Pattern: Claude as Linter
反模式:将Claude用作Linter
❌ Never rely on Claude for style enforcement:
- Naming conventions with specific examples
- Comment formatting rules
- Whitespace/indentation requirements
- File header requirements (ABOUTME, copyright)
✓ Use deterministic tools instead:
- ESLint/Biome for JavaScript/TypeScript style
- Black/Ruff for Python formatting
- Pre-commit hooks for file headers
- Claude Code Hooks to run formatters
Why this matters: LLMs follow style rules inconsistently. A linter fails deterministically; Claude fails silently and unpredictably.
Exception: High-level philosophy is acceptable:
- ✓ "Names should describe purpose, not implementation"
- ❌ "Never use names like ZodValidator or MCPWrapper"
❌ 切勿依赖Claude执行样式校验:
- 带具体示例的命名规范
- 注释格式规则
- 空格/缩进要求
- 文件头要求(ABOUTME、版权信息)
✓ 请使用确定性工具替代:
- ESLint/Biome用于JavaScript/TypeScript样式校验
- Black/Ruff用于Python格式化
- Pre-commit hooks用于文件头校验
- Claude Code Hooks用于运行格式化工具
为什么这很重要: LLM对样式规则的遵循并不一致。Linter会明确报错;而Claude会悄无声息地出错,结果不可预测。
例外情况: 高层级的理念是允许的:
- ✓ "名称应描述用途,而非实现细节"
- ❌ "切勿使用ZodValidator或MCPWrapper这类名称"
Progressive Disclosure
渐进式披露
For complex guidance, don't embed everything in CLAUDE.md.
Pattern: Reference external docs, let Claude decide relevance.
markdown
undefined对于复杂指引,不要把所有内容都写在CLAUDE.md里。
最佳实践: 引用外部文档,让Claude自行判断相关性。
markdown
undefinedReference Documentation
参考文档
- Code conventions: See
docs/conventions.md - API patterns: See
docs/api-design.md - Testing philosophy: See
docs/testing.md
Read these when the task involves the relevant area.
**Benefits**:
- Keeps CLAUDE.md focused
- Claude reads docs only when relevant
- Easier to maintain separate concerns- 代码规范: 见
docs/conventions.md - API模式: 见
docs/api-design.md - 测试理念: 见
docs/testing.md
当任务涉及相关领域时请阅读这些文档。
**优势**:
- 保持CLAUDE.md内容聚焦
- Claude仅在相关时才读取文档
- 更易实现关注点分离维护Structure Template
结构模板
User-Level
用户级别
markdown
[Opening persona/philosophy - 1-2 lines]markdown
[开篇角色定位/开发理念 - 1-2行]Working Together
协作规则
[Relationship dynamics, communication preferences]
[互动模式、沟通偏好]
Proactiveness
主动操作边界
[When to proceed vs. pause for confirmation]
[什么情况可直接执行,什么情况需要暂停确认]
Development Philosophy
开发理念
[Universal principles: YAGNI, debugging approach, etc.]
[通用原则:YAGNI、调试方法等]
Guardrails
约束规则
[Version control, testing principles - kept brief]
undefined[版本控制、测试原则 - 保持简洁]
undefinedProject-Level
项目级别
markdown
undefinedmarkdown
undefinedProject Overview
项目概览
[WHAT: Purpose, stack, structure]
[WHAT: 用途、技术栈、结构]
Development
开发指南
[HOW: Build, test, lint commands]
[HOW: 构建、测试、lint命令]
Architecture
架构说明
[WHY: Key decisions, constraints - if non-obvious]
[WHY: 关键决策、约束 - 非显而易见的内容]
Conventions
规范指引
[Brief pointers to detailed docs if needed]
undefined[如有需要,简要指向详细文档]
undefinedQuality Checklist
质量检查清单
Before finalizing, verify:
最终确定前,请验证:
Universal Applicability
普遍适用性
- Every instruction applies to every session (user-level) or every task in project (project-level)
- No project-specific commands in user-level config
- No tool references that may not exist
- 每条指令都适用于所有会话(用户级别)或项目内的所有任务(项目级别)
- 用户级别配置中没有项目专属命令
- 没有引用可能不存在的工具
Instruction Economy
指令精简性
- Under instruction budget (count them)
- No redundancy with Claude Code's built-in behaviors
- Examples trimmed or moved to reference docs
- 未超出指令预算(手动计数)
- 没有与Claude Code内置行为冗余的内容
- 示例已精简或移动到参考文档中
No LLM-as-Linter
无LLM作为Linter的问题
- No specific naming convention examples
- No comment formatting rules
- No file header requirements
- Style guidance limited to philosophy, not specifics
- 没有具体的命名规范示例
- 没有注释格式规则
- 没有文件头要求
- 样式指引仅限定于理念层面,无具体规则
Progressive Disclosure
渐进式披露
- Complex topics reference external docs
- Main file under 100 lines (user) or 150 lines (project)
- Examples in reference files, not inline
- 复杂主题引用了外部文档
- 主文件长度低于100行(用户级别)或150行(项目级别)
- 示例放在参考文件中,而非内联
Clarity
清晰度
- Consistent heading hierarchy
- No conflicting instructions
- Actionable directives, not vague guidance
- 标题层级一致
- 没有冲突的指令
- 都是可执行的指令,无模糊指引
Common Pitfalls
常见误区
- Over-specification: Including every preference instead of universally critical ones
- Style enforcement: Detailed naming/comment rules that Claude follows inconsistently
- Stale commands: Build/test commands that drift from actual tooling
- Auto-generation: Using instead of hand-crafting
/init - Tool assumptions: Referencing MCP servers or tools that aren't always available
- Conflicting rules: "Match surrounding style" + "Never use X pattern"
- Instruction inflation: Adding rules after each frustration instead of fixing root cause
- 过度规范: 包含所有偏好,而非普遍关键的规则
- 样式强制: Claude无法稳定遵循的详细命名/注释规则
- 命令过时: 构建/测试命令与实际工具配置不一致
- 自动生成: 使用自动生成而非手动编写
/init - 工具假设: 引用并非始终可用的MCP服务器或工具
- 规则冲突: 同时要求"匹配周边风格" + "切勿使用X模式"
- 指令膨胀: 每次遇到问题就加规则,而非修复根因
When to Skip This Skill
无需使用本规范的场景
- Quick one-off projects (just use defaults)
- Projects with existing, well-maintained CLAUDE.md
- When the team already has established patterns
- 快速的一次性项目(直接使用默认配置即可)
- 已有维护良好的CLAUDE.md的项目
- 团队已经有成熟规则的场景
Example: Before/After
示例:优化前后对比
Before (problematic user-level):
markdown
undefined优化前(存在问题的用户级别配置):
markdown
undefinedNaming
命名规则
NEVER use names like ZodValidator, MCPWrapper, JSONParser...
[20 more lines of specific examples]
切勿使用ZodValidator, MCPWrapper, JSONParser这类名称...
[20多行具体示例]
Comments
注释规则
All files MUST start with ABOUTME: header...
**After** (improved user-level):
```markdown所有文件必须以ABOUTME: 开头...
**优化后**(改进的用户级别配置):
```markdownCode Style
代码风格
Names should describe purpose, not implementation details.
Use project linters for formatting; don't rely on manual enforcement.
*Why better*: Philosophy over specifics. Linter handles enforcement deterministically.名称应描述用途,而非实现细节。
使用项目linter处理格式化,不要依赖手动校验。
*优化原因*: 优先理念而非具体规则,由Linter确定性地执行校验。Integration
集成方式
After authoring CLAUDE.md:
- User-level: Symlink to or place directly
~/.claude/CLAUDE.md - Project-level: Commit to in repository root
.claude/CLAUDE.md - Validation: Start a new Claude Code session and observe if instructions are followed
编写完CLAUDE.md后:
- 用户级别: 软链接到或直接放置在该路径
~/.claude/CLAUDE.md - 项目级别: 提交到仓库根目录的
.claude/CLAUDE.md - 验证: 开启新的Claude Code会话,观察指令是否被遵循