2026 年调查:66% 的开发者 遇到 AI 「差不多对,但就是不对」的问题;45% 说调试 AI 写的代码比自己写还慢。根源几乎都一样:提示词太模糊。
核心原则:越具体,AI 偏差越小
Claude Code 无法读心术。你脑子里的约束、背景、偏好——不写出来就猜。
4 个让提示词立刻变好的技巧
技巧 1:圈定范围
| 模糊写法 | 精准写法 |
|---|---|
"fix the login bug" | "login fails after session timeout. check src/auth/ token refresh. write a failing test then fix it" |
"add tests for foo.py" | "write a test for foo.py: edge case where user is logged out. avoid mocks" |
"make dashboard look better" | "[screenshot] implement this design. screenshot result, compare to original, fix differences" |
技巧 2:指向现有代码模式
text
# 差的
"add a calendar widget"
# 好的
"look at HotDogWidget.php to understand the pattern.
Follow same structure to implement a calendar widget.
No new libraries."技巧 3:给可验证的成功标准
text
# 函数验证
"write validateEmail function.
Test cases: user@example.com=true, invalid=false, user@.com=false.
Run tests after implementing."
# Bug 修复验证
"build fails with [paste error]. Fix root cause, verify build succeeds. Don't suppress the error."技巧 4:用 @ 直接引用文件
text
# 差的
"look at the auth service and..."
# 好的
"@src/auth/session.ts 的 refreshToken 函数有竞态条件,修复"
# 或精确到行号
"@src/auth.ts#45-80 这段逻辑是什么意思?"蝴蝶效应:模糊提示越改越乱
Claude 早期误解了一个前提,在此基础上构建整个功能,5 个 PR 之后才发现。
高危场景:「实现认证系统」「加个 dashboard」「修一下性能」
预防:任务越大,提示越要具体。大任务先用 Plan Mode 确认方向。
探索时可以模糊
text
"what would you improve in this file?"
"这个架构有什么潜在问题?"规则:探索用开放,执行用精确。
Claude 面试你(高级技巧)
text
I want to build [description]. Interview me using AskUserQuestion tool.
Ask about implementation, UX, edge cases, tradeoffs.
Don't ask obvious questions — dig into hard parts.
When done, write complete spec to SPEC.md.完成 SPEC.md 后,开新会话 执行——干净上下文专注实现。
提示词速查模板
text
# Bug 修复
[症状],发生在 [触发条件]。
检查 [文件/路径],特别是 [关键函数]。
写能复现 bug 的测试,然后修复。
# 新功能
参考 [现有文件] 的实现模式,
实现 [功能],要求 [约束]。不引入新库。
# Code Review
检查 @[文件] 是否有 [问题类型]。
列出具体问题行和修复建议。
# UI 改动
[粘贴截图] 实现这个设计。
截图对比原图,列差异,逐一修复。来源:Claude Code 官方 Best Practices | morphllm.com | 整理:ClaudeEagle