新手起步
从 “先解释” 和 “边界” 模式开始。它们最简单且效果最直接。
可记忆的命名模式,用于与 Claude Code 的高效交互。这些模式来源于社区最佳实践,帮助你更有效地沟通。
通过建立上下文和标准来设定质量期望。
模式: “Implement as if you were a [角色] at [高标准公司/场景]”
# 高质量代码Implement this authentication system as if you werea senior security engineer at a major bank.
# 生产就绪Review this code as if preparing for a SOC2 audit.
# 性能优先Optimize this function as if it will handle10,000 requests per second.通过添加明确限制来强制创造性解决方案。
模式: “Solve this [with constraint X] [without using Y]”
# 依赖约束Implement this feature without adding any new dependencies.
# 规模约束Solve this in under 50 lines of code.
# 时间约束(执行)This must complete in under 100ms.
# 简洁约束Use only standard library functions.强制在实现之前进行规划。
模式: “Before implementing, explain your approach in [N] sentences”
Before writing code, explain in 2-3 sentenceshow you'll approach this.Before implementing, outline:1. What components you'll modify2. What edge cases you've considered3. What could go wrongBefore choosing an approach, explain 2-3 alternativesand why you'd pick one.通过让 Claude 提问来协作调试。
模式: “I’m stuck on [X]. Ask me questions to help me figure it out.”
# 调试I'm stuck on why this test is failing.Ask me questions to help diagnose the issue.
# 设计I can't decide on the right architecture.Ask me questions about my requirements.
# 问题理解I don't fully understand what I need to build.Ask clarifying questions.通过验证逐步构建复杂功能。
模式: “Let’s build this incrementally. Start with [最小版本], then we’ll add [功能].”
Build the user registration incrementally:1. First: Basic form that saves to database2. Then: Email validation3. Then: Password strength requirements4. Finally: Email verification flow
Show me step 1 first.Refactor this incrementally.First extract the validation logic,run tests, then we'll continue.定义明确的范围,防止过度工程化。
模式: “Only modify [X]. Don’t touch [Y].”
# 文件范围Only modify auth.ts. Don't change any other files.
# 函数范围Fix just the calculateTotal function.Don't refactor surrounding code.
# 功能范围Add the logout button only.Don't add session management or remember-me features.不同场景适合不同的模式组合:
| 场景 | 模式组合 |
|---|---|
| 关键功能 | As If + 先解释 + 渐进式 |
| 快速修复 | 约束 + 边界 |
| 调试会话 | 橡皮鸭 + 渐进式 |
| 架构决策 | 先解释 + As If |
| 重构 | 边界 + 渐进式 + 约束 |
应避免的提示词反模式:
| 反模式 | 问题 | 更好的方式 |
|---|---|---|
| ”Make it perfect” | 标准未定义 | 使用 “As If” 模式指定具体上下文 |
| ”Fix everything” | 范围爆炸 | 使用 “边界” 模式 |
| ”Just do it” | 缺乏验证 | 使用 “先解释” 模式 |
| ”Make it fast” | 约束模糊 | 指定具体:“under 100ms” |
| 过度详细描述 | 上下文污染 | 仅聚焦相关约束 |
新手起步
从 “先解释” 和 “边界” 模式开始。它们最简单且效果最直接。
日常开发
渐进式 模式是日常功能开发的默认选择,配合 约束 模式保持简洁。
疑难调试
橡皮鸭 模式帮助你理清思路,让 Claude 引导你发现问题根源。
关键系统
对安全或性能关键的系统,组合使用 As If + 先解释 + 渐进式。