二士共用一AI之器。一者三十秒得可用之码,一者得破烂不堪,费时一辰方补之。
其异非在器,而在令也。
何以多数AI所生之码皆不善?
AI 编码之器,实为模式匹配之器,其涵容之广,无与伦比。授之明则,则能妙续;授之歧义,则妄生臆断——此臆断多谬误。
常见之失:
- 辞涉空泛:"于吾之应用,增认证之能"——AI 不识汝之架构,不知汝之数据库之式,亦不晓汝之惯例
- 过巨:"为吾筑一SaaS仪表盘" — 人工智能自创架构,非所求,吾费时一晌解之
- 无上下文:"解此bug"而无周遭代码 — 人工智能臆测系统
- 求决于人工智能:以人工智能定产品或架构之择,而非行吾既定之策
其修非异之智器也,乃异之书辞之法也。
框架:境遇→约束→使命
凡有效之编程提示,皆有三部分:
[CONTEXT] Given this [file/system/function],
[CONSTRAINT] following these [conventions/rules],
[TASK] do [specific, scoped thing].
恶提示:
增删钮
善启:
"在"
src/components/ProjectCard.tsx,增一删除之钮,以召之。deleteProject服务器之动作自src/actions/projects.ts点击时,以现有方式显示确认对话框。AlertDialog自shadcn/ui。既删,乃呼revalidatePath('/dashboard')循既有之错谬处理之式:捕其错谬,示以 Toast,勿抛掷。
同请。次者费时四十秒以成文。其出为成品,非仅初稿,需时一辰以洁之。
编码之六式
一、施为之式
为增新制。此最习见,亦易谬误。
范式:
Add [feature] to [file/component].
It should [behavior description].
Use [specific library/pattern] — not [what to avoid].
Follow the existing pattern in [example file or function].
The return/export should look like: [description].
示例:
Add pagination to `getUserProjects` in `src/lib/queries.ts`.
It should accept `{ page: number, limit: number }` and return
`{ data, total, hasMore }`.
Use Drizzle's `.offset()` and `.limit()` — not cursor-based pagination.
Follow the same select pattern as `getUserById`: select specific
columns, never `select *`.
Type the return with a `PaginatedResult<T>` generic.
2. 错误提示
为调试之用。谬误在于未提供足够之背景,以示预期行为与实际行为之差异。
模板:
[function/component] in [file] is broken.
Expected: [what should happen]
Actual: [what is happening]
Error: [exact error message if any]
Relevant context: [the failing code + what it calls]
示例:
The `createProject` Server Action in `src/actions/projects.ts`
returns { error: "Unauthorized" } even when the user is logged in.
Expected: creates the project and returns { data: project }.
Actual: always hits the requireAuth() error branch.
Error: no error message, just the unauthorized return.
requireAuth() is in `src/lib/auth.ts` — pasting it below.
The user is definitely authenticated (visible in Clerk dashboard).
三、重铸提示
以善旧码而不破之。其要者:明示不可易者.
范本:
Refactor [function/file] to [improvement goal].
Keep: [API, behavior, types that must stay identical]
Change: [what should change]
Don't: [specific things to avoid]
例:
Refactor `UserTable.tsx` to extract the row actions into a
separate `UserTableActions` component.
Keep: the exact same props API on UserTable, same visual output,
same TypeScript types.
Change: move the action buttons and their handlers to
`UserTableActions.tsx`.
Don't: change how the parent passes data, don't add new dependencies.
四、试作之题旨
以生试作。须明言所依之庠序,所覆之域,所拟之象.
范本:
Write [unit/integration] tests for [function/component] in [file].
Testing library: [Vitest/Playwright/etc.]
Cover: [list of specific scenarios]
Mock: [external dependencies to mock and why]
Don't test: [implementation details to avoid]
例证:
Write Vitest unit tests for the `createProject` Server Action
in `src/actions/projects.ts`.
Cover:
- success case (user authorized, valid input)
- validation failure (name exceeds 50 chars)
- unauthorized user (requireAuth throws)
- database error (insert fails)
Mock: `src/lib/db.ts` (mock insert to return a fake project),
`src/lib/auth.ts` (mock requireAuth).
Don't test the actual database or actual auth — only the action's logic.
5. 解释提示
为解不识之码。谬者:求泛解也.
非:
"解此码"
善:
"解此Drizzle查询所为。其详:
.$onConflictDoUpdate何为,及其故何在"target: [users.clerkId]乎?试以一言总括其于数据库之效。"
所问精,所答亦精。'解此码'之问,得滔滔之文,尽述已知之事。"
6. 迁移与升级之提示
为更新代码至新API版本。"
模板:
Migrate [file] from [old API] to [new API].
Breaking changes to handle: [list specific breaking changes]
Don't change: [function signatures your app uses]
Reference: [paste the relevant migration docs]
例:
Migrate `src/lib/auth.ts` from Clerk v4 to Clerk v5.
Breaking changes: `auth()` is now async, `clerkMiddleware` replaces
`withClerkMiddleware`, user object shape changed.
Don't change the signatures my app uses: requireAuth() and getAuthUser().
Here are the relevant Clerk v5 migration notes:
[paste the breaking changes section from the docs]
语境为乘数
输出之质,首重语境。AI之器,唯用所授耳.
所当恒备者
- 确指文件之径
- 特指函数或组件之名——非全文件
- 既存之例,所循之式
- 所用之库名,勿臆其栈
- 所谓“竟”者何(返回之型,目见之效,行止之状)
所当屏弃者
- 全篇之码(“此乃吾之全案”)
- 无关之牍(“此乃
/lib中所有”) - 跨越诸系统之要求
至要之境,乃足使意旨无歧也
诀(克劳德码)以克劳德码,毋须将码植于提示。但引文件径——"于
src/actions/projects.ts"已足,克劳德码自能识之。留植码于特欲彰之片段耳
CLAUDE.md:永续之境,自在无拘
为文之佳,弊在屡复其常:每言“以 cuid2 为标识,用 Server Actions 而非 API routes,返 { data } 或 { error }……”
Claude 之码,一撰于根之 CLAUDE.md 文:
# CLAUDE.md
## Stack
- Next.js 15 App Router, TypeScript strict mode
- Drizzle ORM + Neon (PostgreSQL)
- Clerk auth, Zod validation, shadcn/ui
- Biome for linting and formatting
## Conventions
- cuid2 for all IDs, never auto-increment integers
- Soft-delete users (deletedAt), never hard delete
- Server Actions for mutations, not API routes
- Import env from `@/lib/env`, never `process.env` directly
- `requireAuth()` at the top of every protected action
- Return `{ data }` or `{ error: string }`, never throw from actions
- Error messages lowercase, no periods
## File structure
- Server Actions: `src/actions/[feature].ts`
- DB queries: `src/lib/queries.ts`
- Shared types: `src/types/[domain].ts`
启程之际,Claude Code读此,自当依此规,于每问皆施之。毋须复言“用cuid2”,自当为之.
分解之务:真为高士之技
别离硕果之徒与困顿之辈者,唯此一技:析务至当其宜.
勿:
"为我构建用户认证系统,含注册、登录、社交认证、Google OAuth、密码重置、邮箱验证、会话管理及账户设置页面。"
需做:
- "于Next.js 15 App Router中配置Clerk" → 已完成
- "于
requireAuth()中创建src/lib/auth.ts助手" → 已完成 - "于
/dashboard中添加Clerk中间件以保护路由" → 已完成 - "于
(dashboard)/settings/page.tsx设账户设置之页" → 既成
每步皆三十秒之提示,其果可验。合之与巨请无异——然无虚妄之架构,且汝悉知每句.
其律:若提示令人力尽其详需逾五分钟,则分为二提示。
汝当勿问人工智能者何事
架构之决断:
"当用微服务抑或单体架构耶?"
人工智能将依泛常之模则,予汝似是而非之答。彼不知尔辈之众寡,不知尔辈之流讯,不知尔辈之基业。先自决之,而后询人工智能以行尔之决。
商贾之理:
"用户中止其订阅时,当如何?"
此乃产品之决断,关乎利弊。汝自定之,而后施行之.
安全审计:
"此代码安乎?"
AI可应汝之请而撰安代码,然不能自发性察尽既有代码之瑕疵。当用专器以行审计。
凡不读者:
若欲抄AI之文而不读,止之。汝所运之码,非所解也。其坏也——必坏——汝将不知所求。
前后之例,真如所睹
功能之施
前(三十秒可书,四十五分钟可正):
"于项目列增索"
既(九十秒以成文,一用即效):
"于
src/app/(dashboard)/projects/page.tsx增索,当以URL索引之参(?q=),使索状恒存于新启。滤getUserProjects之果,其name含询(不辨大小),用迟索之输入——以useDebounce自src/hooks/useDebounce.ts迟三百毫秒。勿增新之倚。"
修 bug
旧状:
"吾之表单不提交"
新状:
"于
CreateProjectForm中,src/components/CreateProjectForm.tsx不唤 Server Action。React Hook Form 之handleSubmit已接,然 Action (createProject所来)未应。"src/actions/projects.ts之火不燃——于行动之巅以 console.log 确认。无浏览器之误。二文件并贴于下。"
重构
前:
"清理此文件"
后:
"此
src/lib/db.ts文件有三内联辅助函数 (withRetry,paginate,softDelete者,今已用於六處以上。其自src/lib/db-helpers.ts中提取之,並更新所有引用。勿改其函數之簽名或行為,唯改其位耳。"
元技能
欲善於提問,其法在於察知不佳之結果,而問其故.
- 輸出過於模糊 → 君之任務未足明確
- 人工智能创构之务甚巨,遂析之
- 人工智能用格失宜,境缺,增相关之文
- 人工智能定器物之策,尔求策而非行
- 码文不合尔之栈,尔之约未备
CLAUDE.md
每恶之出,皆示于题之反。宜正题,非独正其出。
得AI之助者,非择异级异模也。乃多费六十秒,以撰更善之问。此乃全胜之机,且日积月累,益彰其效。
详尽指南,附CLAUDE.md模板及Claude Code流程:
https://stacknotice.com/blog/ai-coding-prompts-senior-2026












