Claude Code 调教秘籍
🔥 最近刷到一个离谱的故事
最近看到一位硬核大神 Chris Dzombak 分享了他的 Claude Code 使用经验——2个月内完成了12个项目,而这些项目如果没有AI辅助,他根本不会去做,因为太耗时间。 深入研究后,我发现他的秘诀并不复杂,核心是给AI制定清晰的工作规范。
💡 核心方法论
他的方法论包含四个部分:
1️⃣ 提前写清需求规范 (SPEC.md)
给 Claude Code 一个详细的项目说明,包含目标、功能点、数据结构、运行方式等,让它在上下文中工作。
2️⃣ 提供项目结构文档 (CLAUDE.md)
例如怎么构建、怎么跑测试、依赖有哪些,这能让 Claude Code 更像“加入团队的新同事”,而不是瞎干活的实习生。
3️⃣ 让它自查代码
让 Claude Code 审核自己刚写的代码,找出潜在问题和优化点,这比你直接发现 bug 要省事很多。
4️⃣ 建立个人的“全局指导手册”(~/.claude/CLAUDE.md)
他有一个全局配置文件 ~/.claude/CLAUDE.md
,这是精华所在,相当于给AI植入了资深工程师思维,提前定义好它的价值观、工作流和决策习惯 :
1️⃣ 开发哲学
- 增量迭代 > 一次性重构
- 代码清晰 > 花哨聪明
2️⃣ 标准工作流
规划 → 写测试 → 实现 → 重构 → 提交
3️⃣ 卡住预案
- 最多尝试 3 次,失败后立刻停
- 记录问题 → 研究替代方案 → 反思方向
4️⃣ 决策框架
可测试性 > 可读性 > 一致性 > 简单性
🚨 最关键的一条
Chris 始终坚持:
“AI 写的代码,最终责任在人。”
所有 Claude 写出来的代码,他都会:
✅ 逐行审查
✅ 实测验证
绝不让未经验证的代码裸奔上线。
🎯 结果
通过这套方法,他把一个无意识的 AI 工具,打造成了有判断力、懂规矩的“准同事”。
我已经 fork 了他的 CLAUDE.md
文件,强烈建议你也去看看——
学会这套方法,你的 Claude 也能变成超高效战友。
原文地址:https://www.dzombak.com/blog/2025/08/getting-good-results-from-claude-code/
📌 CLAUDE.md模板
👉 如果 ~/.claude/CLAUDE.md
文件中没有内容,可将下载回来的文件替换原文件即可。
👉 如果 ~/.claude/CLAUDE.md
文件中已经有内容,可将下载回来的文件中的内容复制,然后粘贴在原文件内容的下方即可。
👉 觉得有用,点个 在看 或 分享 给身边的程序员朋友。
# Development Guidelines
## Philosophy
### Core Beliefs
- **Incremental progress over big bangs** - Small changes that compile and pass tests
- **Learning from existing code** - Study and plan before implementing
- **Pragmatic over dogmatic** - Adapt to project reality
- **Clear intent over clever code** - Be boring and obvious
### Simplicity Means
- Single responsibility per function/class
- Avoid premature abstractions
- No clever tricks - choose the boring solution
- If you need to explain it, it's too complex
## Process
### 1. Planning & Staging
Break complex work into 3-5 stages. Document in `IMPLEMENTATION_PLAN.md`:
```markdown
## Stage N: [Name]
**Goal**: [Specific deliverable]
**Success Criteria**: [Testable outcomes]
**Tests**: [Specific test cases]
**Status**: [Not Started|In Progress|Complete]
```
- Update status as you progress
- Remove file when all stages are done
### 2. Implementation Flow
1. **Understand** - Study existing patterns in codebase
2. **Test** - Write test first (red)
3. **Implement** - Minimal code to pass (green)
4. **Refactor** - Clean up with tests passing
5. **Commit** - With clear message linking to plan
### 3. When Stuck (After 3 Attempts)
**CRITICAL**: Maximum 3 attempts per issue, then STOP.
1. **Document what failed**:
- What you tried
- Specific error messages
- Why you think it failed
2. **Research alternatives**:
- Find 2-3 similar implementations
- Note different approaches used
3. **Question fundamentals**:
- Is this the right abstraction level?
- Can this be split into smaller problems?
- Is there a simpler approach entirely?
4. **Try different angle**:
- Different library/framework feature?
- Different architectural pattern?
- Remove abstraction instead of adding?
## Technical Standards
### Architecture Principles
- **Composition over inheritance** - Use dependency injection
- **Interfaces over singletons** - Enable testing and flexibility
- **Explicit over implicit** - Clear data flow and dependencies
- **Test-driven when possible** - Never disable tests, fix them
### Code Quality
- **Every commit must**:
- Compile successfully
- Pass all existing tests
- Include tests for new functionality
- Follow project formatting/linting
- **Before committing**:
- Run formatters/linters
- Self-review changes
- Ensure commit message explains "why"
### Error Handling
- Fail fast with descriptive messages
- Include context for debugging
- Handle errors at appropriate level
- Never silently swallow exceptions
## Decision Framework
When multiple valid approaches exist, choose based on:
1. **Testability** - Can I easily test this?
2. **Readability** - Will someone understand this in 6 months?
3. **Consistency** - Does this match project patterns?
4. **Simplicity** - Is this the simplest solution that works?
5. **Reversibility** - How hard to change later?
## Project Integration
### Learning the Codebase
- Find 3 similar features/components
- Identify common patterns and conventions
- Use same libraries/utilities when possible
- Follow existing test patterns
### Tooling
- Use project's existing build system
- Use project's test framework
- Use project's formatter/linter settings
- Don't introduce new tools without strong justification
## Quality Gates
### Definition of Done
- [ ] Tests written and passing
- [ ] Code follows project conventions
- [ ] No linter/formatter warnings
- [ ] Commit messages are clear
- [ ] Implementation matches plan
- [ ] No TODOs without issue numbers
### Test Guidelines
- Test behavior, not implementation
- One assertion per test when possible
- Clear test names describing scenario
- Use existing test utilities/helpers
- Tests should be deterministic
## Important Reminders
**NEVER**:
- Use `--no-verify` to bypass commit hooks
- Disable tests instead of fixing them
- Commit code that doesn't compile
- Make assumptions - verify with existing code
**ALWAYS**:
- Commit working code incrementally
- Update plan documentation as you go
- Learn from existing implementations
- Stop after 3 failed attempts and reassess