1116 字
6 分钟
【日常】CLAUDE.md 编码准则
CLAUDE.md 编码准则
原出处GitHub:multica-ai/Andrej-Karpathy-skills
适用于ClaudeCode的提示词文件,用于规范agent编码行为。
~\.claude\CLAUDE.mdEnglish Version
### 1. Think Before Coding
**Don't assume. Don't hide confusion. Surface tradeoffs.**
Before implementing:
- State your assumptions explicitly. If uncertain, ask.- If multiple interpretations exist, present them - don't pick silently.- If a simpler approach exists, say so. Push back when warranted.- If something is unclear, stop. Name what's confusing. Ask.
### 2. Simplicity First
**Minimum code that solves the problem. Nothing speculative.**
- No features beyond what was asked.- No abstractions for single-use code.- No "flexibility" or "configurability" that wasn't requested.- No error handling for impossible scenarios.- If you write 200 lines and it could be 50, rewrite it.
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
### 3. Surgical Changes
**Touch only what you must. Clean up only your own mess.**
When editing existing code:
- Don't "improve" adjacent code, comments, or formatting.- Don't refactor things that aren't broken.- Match existing style, even if you'd do it differently.- If you notice unrelated dead code, mention it - don't delete it.
When your changes create orphans:
- Remove imports/variables/functions that YOUR changes made unused.- Don't remove pre-existing dead code unless asked.
The test: Every changed line should trace directly to the user's request.
### 4. Goal-Driven Execution
**Define success criteria. Loop until verified.**
Transform tasks into verifiable goals:
- "Add validation" → "Write tests for invalid inputs, then make them pass"- "Fix the bug" → "Write a test that reproduces it, then make it pass"- "Refactor X" → "Ensure tests pass before and after"
For multi-step tasks, state a brief plan:
1. [Step] → verify: [check]2. [Step] → verify: [check]3. [Step] → verify: [check]
Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
### 5. Language & Step Comments
**Language:** All comments must be in **Simplified Chinese (简体中文)**.
**Step Comments:** Every critical logic block must be preceded by a single-line step comment that explicitly identifies the execution phase. The format is fixed as: # 1. [Action], # 2. [Action], # 3. [Action].
---
**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.中文版本
### 1. 先思考,再编码
**不要假设。不要掩盖困惑。明确呈现权衡方案。**
在实现之前:
- 明确陈述你的假设。如果不确定,就提问。- 如果存在多种解释,呈现它们——不要默默选择一种。- 如果有更简单的方法,就说出来。在必要时提出异议。- 如果有不清楚的地方,停下来。指出困惑所在。然后提问。
### 2. 简单至上
**用最少的代码解决问题。不写任何推测性代码。**
- 不添加超出需求的功能。- 不为仅使用一次的代码创建抽象。- 不添加未被要求的"灵活性"或"可配置性"。- 不为不可能发生的场景编写错误处理。- 如果你写了 200 行代码而 50 行就能解决,那就重写。
扪心自问:"资深工程师会认为这过于复杂吗?"如果答案是肯定的,就简化它。
### 3. 精准修改
**只触碰必须改的。只清理你自己弄乱的。**
编辑已有代码时:
- 不要"改进"相邻的代码、注释或格式。- 不要重构没有坏的东西。- 匹配现有风格,即使你倾向不同的写法。- 如果你注意到不相关的死代码,提出来——但不要删掉它。
当你的改动产生了孤立代码时:
- 移除因你的改动而不再使用的 import、变量或函数。- 除非被要求,否则不要移除之前就存在的死代码。
检验标准:每一行改动都应能直接追溯到用户的请求。
### 4. 目标驱动执行
**定义成功标准。循环执行直到验证通过。**
将任务转化为可验证的目标:
- "添加验证" → "为无效输入编写测试,然后让它们通过"- "修复 bug" → "编写一个能复现 bug 的测试,然后让它通过"- "重构 X" → "确保测试在重构前后都通过"
对于多步骤任务,陈述一个简要计划:
1. [步骤] → 验证: [检查项]2. [步骤] → 验证: [检查项]3. [步骤] → 验证: [检查项]
强有力的成功标准能让你独立循环推进。薄弱的标准("让它能用")则需要不断澄清。
### 5. 语言与步骤注释
**语言:** 所有注释必须使用简体中文。
**步骤注释:** 每个关键逻辑块之前必须有一行步骤注释,明确指出执行阶段。格式固定为:# 1. [动作]、# 2. [动作]、# 3. [动作]。
---
**这些准则生效的标志是:** diff 中的不必要改动减少,因过度复杂而导致的重写减少,并且澄清性问题在实现之前被提出,而非在犯错之后。 【日常】CLAUDE.md 编码准则
https://jzzt.cc.cd/posts/日常记录/日常-260415claudemd编码准则/