如果你完全不碰代码,这章可以跳过 —— 单拎出来就是为了让你跳得干净。碰的话:这一章你写一份真的 CLAUDE.md,然后用「先写验收标准、再让它实现、最后自己读 diff」跑通一次完整循环。If you never touch code, skip this chapter — it's separate precisely so you can. If you do: here you write a real CLAUDE.md, then close one full loop with acceptance criteria first, implementation second, and your own reading of the diff last.
如果你完全不碰代码,这一章可以跳过 —— 把它单独拎出来,就是为了让你能干净地跳过,不必为一项用不上的能力分心。跳之前扫一眼第四节:那里有三件不写码的人也用得上的事。If you never touch code, skip this chapter — it's a separate one precisely so you can skip it cleanly, without being distracted by a capability you won't use. Before you skip, glance at section four: it holds three things that are useful even if you never write code.
— I
碰代码的活,分四个地方放Code Work Splits Across Four Places.
你要做的What you're doing
去哪做Where
为什么Why
问清一个概念、推敲一段思路Clarify a concept, think through an approach
网页 chatWeb chat
一问一答,不碰文件Turn-by-turn, touches no files
要一个能跑、能改的小东西A small runnable, editable thing
Artifact(第 7 章)Artifact (Ch. 7)
现做现改,不进仓库Made and revised live, never enters the repo
在真实仓库里跨文件改、要跑测试Cross-file changes in a real repo, with tests
Claude Code
读仓库、改文件、跑命令、提 commitReads the repo, edits files, runs commands, commits
把 Claude 接进你自己的程序Wire Claude into your own program
API(另一条账,第 11 章)API (a separate bill, Ch. 11)
程序化调用,按 token 计费Programmatic calls, billed by token
Claude Code 不是编辑器里的自动补全,是一个会读你整个仓库、自己跑命令的 agent:读代码库、改文件、跑命令,再看结果、自己调整,直到把一件事做完。1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。截至 2026-08。Claude Code Docs · Overview — Claude Code is an agentic coding tool: it reads the codebase, edits files, runs commands, then evaluates and adjusts; it runs in the terminal, IDE, desktop, and browser on one shared engine and CLAUDE.md. As of 2026-08.它跑在终端、IDE、桌面与浏览器里,共用同一套引擎与同一份 CLAUDE.md。1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。截至 2026-08。Claude Code Docs · Overview — Claude Code is an agentic coding tool: it reads the codebase, edits files, runs commands, then evaluates and adjusts; it runs in the terminal, IDE, desktop, and browser on one shared engine and CLAUDE.md. As of 2026-08.你的工作从「逐行写」变成「定义任务、审查结果」。Claude Code isn't editor autocomplete — it's an agent that reads your whole repo and runs commands itself: reading the codebase, editing files, running commands, then checking results and adjusting until the task is done.1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。截至 2026-08。Claude Code Docs · Overview — Claude Code is an agentic coding tool: it reads the codebase, edits files, runs commands, then evaluates and adjusts; it runs in the terminal, IDE, desktop, and browser on one shared engine and CLAUDE.md. As of 2026-08. It runs in the terminal, IDE, desktop, and browser on one shared engine and one shared CLAUDE.md.1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。截至 2026-08。Claude Code Docs · Overview — Claude Code is an agentic coding tool: it reads the codebase, edits files, runs commands, then evaluates and adjusts; it runs in the terminal, IDE, desktop, and browser on one shared engine and CLAUDE.md. As of 2026-08. Your work shifts from writing line by line to defining tasks and reviewing results.一件很多人不知道的事:Pro 就包含 Claude Code,用的是订阅额度,不需要另开 API 账户。2注 2Note 2Anthropic · Claude 套餐与价格 —— Claude Code 列在 Pro 及以上各档的功能内(Free 不含),用的是订阅额度,不需要另开 API 账户。截至 2026-08。Anthropic · Claude Plans & Pricing — Claude Code is listed under Pro and above (not on Free), drawing on subscription usage rather than requiring a separate API account. As of 2026-08.它常被当成开发者专属的付费工具,其实你那份 $20 的 Pro 就能跑。代价是它吃额度 —— 重活比闲聊更快撞到限额,这一项会在第 11 章那本账里冒尖。Something many people don't know: Pro already includes Claude Code, drawing on subscription usage rather than a separate API account.2注 2Note 2Anthropic · Claude 套餐与价格 —— Claude Code 列在 Pro 及以上各档的功能内(Free 不含),用的是订阅额度,不需要另开 API 账户。截至 2026-08。Anthropic · Claude Plans & Pricing — Claude Code is listed under Pro and above (not on Free), drawing on subscription usage rather than requiring a separate API account. As of 2026-08. It's taken for a developer-only paid tool when your $20 Pro already runs it. The cost is quota — heavy work hits the limit sooner than chitchat, and it's a line that spikes in Chapter 11's ledger.
— II
动手:写一份真的 CLAUDE.mdDo It: Write a Real CLAUDE.md.
CLAUDE.md 是放在项目根目录的一份 markdown,它每开一个新会话都先读。它替你回答那些你本来每次都要重新交代的问题。CLAUDE.md is a markdown file in the project root that it reads at the start of every session. It answers, once, the questions you would otherwise re-explain every time.下面这份可以直接抄,把尖括号里的换成你项目的。它刻意短 —— 第一版写长了没人维护,而过期的 CLAUDE.md 比没有更糟。Copy the file below and replace what's in angle brackets with your project's reality. It's deliberately short — a long first version never gets maintained, and a stale CLAUDE.md is worse than none.
CLAUDE.md
# <项目名><一句话:这个项目是什么,给谁用。>## Running it- Install: `<npm ci>`- Dev server: `<npm run dev>` (port `<3000>`)- Env vars live in `.env.local`; see `.env.example`. Never read or write real secrets — ask me and I'll set them.## Verifying a change (run these before saying you're done)- Tests: `<npm test>`- Lint: `<npm run lint>`- Types: `<npx tsc --noEmit>`- Build: `<npm run build>`If any of these fail, fix the cause — do not skip the check and do notuse flags that bypass it.## Off-limits- `<src/generated/>` is generated; edit the generator, not the output.- `<migrations/>` — never edit an existing migration; add a new one.- Never force-push, never `git commit --no-verify`, never delete a file I didn't ask you to delete.## Conventions- <TypeScript strict; no new dependencies unless I approve them.>- <Match the surrounding file's style rather than the project average.>- Commit messages: `<type>(<scope>): <subject>`.## How I want you to work- Read the relevant files before changing them. Don't conclude about code you haven't opened.- Make only the change I asked for. No drive-by refactors.- When you're done, show evidence: the command you ran and its output. Not "it works".
五段:这是什么、怎么跑、怎么验、别碰哪儿、我的偏好。第三段最重要 —— 没有那几条命令,它只能靠猜,也没法交证据。Five parts: what this is, how to run it, how to verify it, what not to touch, and my preferences. The third matters most — without those commands it can only guess, and it has no way to show evidence.
01
先填「怎么验」那一段,别的都可以后补Fill in the 'how to verify' block first; everything else can wait
测试、lint、typecheck、构建四条命令写进去。这四行是全文的重心 —— 它们把「它说做完了」变成「它能证明做完了」,而这正是整章的验收标准。Put the four commands in: tests, lint, typecheck, build. Those four lines carry the file — they turn 'it says it's done' into 'it can prove it's done,' which is this chapter's entire bar.
02
写清禁区,用具体路径Name the off-limits, with concrete paths
「小心点」没用,「migrations/ 里的现有文件一个都别改,要改加新的」有用。禁区那段是唯一一段值得你反复更新的 —— 每次它动错一个地方,就往这段加一行。'Be careful' does nothing; 'never edit an existing file under migrations/ — add a new one' does. The off-limits block is the one section worth updating repeatedly: every time it touches the wrong thing, add a line.
03
放进项目根目录,开一个新会话验一次Drop it in the project root and verify with a fresh session
开一个新会话,只问一句「这个项目怎么跑起来、怎么验证一个改动」。它答不上来,就是这份文件没写清 —— 这一问比读十遍自己写的文档管用。Start a fresh session and ask only 'how do I run this project, and how do I verify a change?' If it can't answer, the file isn't clear enough — that one question beats re-reading your own doc ten times.
— III
动手:跑通一次循环Do It: Close One Loop.
顺序是先写验收标准、再让它实现、最后自己读 diff。这三步的顺序比每一步本身更重要。The order is: acceptance criteria first, implementation second, your own reading of the diff last. The order matters more than any single step.
01
挑一个跨 3 个以上文件的小改动Pick a small change spanning 3+ files
太小的(改个文案)显不出差别,太大的(重构整个模块)第一次容易失控。跨三个文件、有明确对错的那种最合适 —— 比如修一个你已经知道复现步骤的 bug。Too small (a copy tweak) shows nothing; too large (refactor a whole module) is easy to lose control of on the first try. Three files with a clear right answer is the sweet spot — a bug whose repro steps you already know, for instance.
02
先让它写一个会失败的测试Have it write a failing test first
这是整章最值钱的一步。先有一个能复现问题、现在会红的测试,验收标准就从「你觉得对不对」变成「这条测试红转绿了没有」。官方把「给它一个能自己跑的检查」称作最高杠杆,就是这个意思。This is the most valuable step in the chapter. With a test that reproduces the problem and is currently red, the bar stops being 'does this look right to you' and becomes 'did that test go from red to green.' This is what Anthropic means by calling 'give it a check it can run itself' the highest-leverage practice.
03
贴护栏,让它去改Paste the guardrails and let it work
用下面那段护栏开场。然后别盯着它一行行看 —— 你要审的是结果,不是过程;盯着看只会让你忍不住替它写。Open with the guardrail block below. Then don't watch it line by line — what you're reviewing is the result, not the process; watching just makes you write it yourself.
04
要证据,然后自己读 diffDemand evidence, then read the diff yourself
它说做完了,你要的是那条命令的输出。看完输出再读 diff —— 记下哪一步它明显比你快、哪一步你还是得自己改。这条分工就是你之后该不该开终端的依据。When it says it's done, what you want is the output of that command. Read the output, then read the diff — noting which step it was clearly faster at and which you still had to fix yourself. That division is your basis for when to open the terminal at all.
动手前先读相关文件,没读过的代码不要下结论。
只做我要求的改动,别顺手重构、别加没要的抽象。
不可逆的动作(删文件 / force-push / 对外发消息)先问我;别用 --no-verify 这类绕过检查的捷径。
做完给我证据:跑了哪些命令、输出是什么,而不是一句「我搞定了」。
任务:<把任务贴这里>。验收标准:<哪条测试要从红变绿 / 什么行为要变>。Read the relevant files before acting; don't conclude about code you haven't opened.
Make only the change I asked for: no drive-by refactors, no abstractions I didn't request.
For irreversible actions (deleting files / force-push / posting externally), ask me first; and don't take shortcuts like --no-verify that bypass checks.
When done, show evidence: which commands you ran and their output, not just 'it works.'
Task: <paste the task>. Acceptance: <which test must go from red to green / what behavior must change>.
动手前先读 src/auth/session.ts 和它的测试,没读过的代码不要下结论。
只把这个登录超时的 bug 修掉,别顺手把整个 session 模块重构、别加没要的缓存层。
不可逆的动作(删 migration 文件 / force-push 到 main / 给 Slack 发上线通知)先问我;别用 --no-verify 这类绕过检查的捷径。
做完给我证据:跑了 npm test 之后的输出贴上来,而不是一句「我搞定了」。
任务:修复并发登录时 session 提前过期的问题。验收标准:tests/auth/session.concurrent.test.ts 从红变绿,其余测试不许变红。Before acting, read src/auth/session.ts and its tests; don't conclude about code you haven't opened.
Fix only this login-timeout bug: don't refactor the whole session module, don't add a caching layer I didn't request.
For irreversible actions (deleting a migration file / force-pushing to main / posting a deploy notice to Slack), ask me first; and don't take shortcuts like --no-verify that bypass checks.
When done, show evidence: paste the output after running npm test, not just 'it works.'
Task: fix sessions expiring early under concurrent logins. Acceptance: tests/auth/session.concurrent.test.ts goes from red to green, and no other test turns red.
越是放手让它自己跑,越要先给护栏。4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-08。Claude API Docs · Prompting best practices — give it guardrails: confirm before irreversible actions, no destructive shortcuts like --no-verify; in code review tell it to report everything and not filter; read files first to avoid hallucination, do only what's asked to avoid over-engineering. As of 2026-08.上面那段里最容易被删掉、也最不该删的是最后一句 —— 「给我证据,不是断言」。官方把「给它一个能自己跑的检查」称作最高杠杆:能自己验的活,你才敢真走开;验不了的,diff 还得你一行行看。5注 5Note 5Claude Code Docs · Best practices —— 最高杠杆是「给它一个能自己跑的检查」,让它交证据(测试输出 / 命令 / 截图)而不是交断言。截至 2026-08。Claude Code Docs · Best practices — the highest-leverage practice is to give it a check it can run itself, and have it show evidence (test output / the command / a screenshot) rather than assert success. As of 2026-08.The more you let it run on its own, the more it needs guardrails first.4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-08。Claude API Docs · Prompting best practices — give it guardrails: confirm before irreversible actions, no destructive shortcuts like --no-verify; in code review tell it to report everything and not filter; read files first to avoid hallucination, do only what's asked to avoid over-engineering. As of 2026-08. The line most often deleted from that block, and the one that should never go, is the last — evidence, not assertions. Anthropic calls 'give it a check it can run itself' the highest-leverage practice: work it can verify itself is work you can walk away from; work it can't, the diff is still yours to read line by line.5注 5Note 5Claude Code Docs · Best practices —— 最高杠杆是「给它一个能自己跑的检查」,让它交证据(测试输出 / 命令 / 截图)而不是交断言。截至 2026-08。Claude Code Docs · Best practices — the highest-leverage practice is to give it a check it can run itself, and have it show evidence (test output / the command / a screenshot) rather than assert success. As of 2026-08.让它做代码评审时,要反过来说一句:When you have it review code, say the opposite of what feels natural:
评审这个 <diff / PR / 这几个文件>,别改代码,只给意见。
先读相关文件和它依赖的地方,没读过的别评。
全列出来、别替我过滤:按「会出错 / 安全 / 可简化」分类,每条标 文件:行 + 一句为什么。
能复现的问题给复现步骤;拿不准的也写上,标「拿不准」。
最后一句:这个改动能不能合,还缺什么。Review this <diff / PR / these files>; don't change the code, just give opinions.
Read the relevant files and what they depend on first; don't review code you haven't opened.
List everything, don't filter for me: sort into 'will break / security / can simplify,' each with file:line + a one-line why.
For reproducible issues give repro steps; write down the uncertain ones too, marked 'unsure.'
Last line: can this merge, and what's still missing.
评审这个 PR(登录超时的修复),别改代码,只给意见。
先读 src/auth/session.ts 和调用它的地方,没读过的别评。
全列出来、别替我过滤:按「会出错 / 安全 / 可简化」分类,每条标 文件:行 + 一句为什么。
能复现的问题给复现步骤;拿不准的也写上,标「拿不准」。
最后一句:这个改动能不能合,还缺什么(比如缺一个并发场景的测试)。Review this PR (the login-timeout fix); don't change the code, just give opinions.
Read src/auth/session.ts and its callers first; don't review code you haven't opened.
List everything, don't filter for me: sort into 'will break / security / can simplify,' each with file:line + a one-line why.
For reproducible issues give repro steps; write down the uncertain ones too, marked 'unsure.'
Last line: can this merge, and what's still missing (e.g. a test for the concurrent case).
那句「全报、别替我过滤」是刻意的。你随口说一句「保守点、只报严重的」,它真会把查到的小 bug 咽回去不报 —— 宁可多报几条你再筛,也别让它默默吞掉一个真 bug。4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-08。Claude API Docs · Prompting best practices — give it guardrails: confirm before irreversible actions, no destructive shortcuts like --no-verify; in code review tell it to report everything and not filter; read files first to avoid hallucination, do only what's asked to avoid over-engineering. As of 2026-08.The 'report everything, don't filter for me' line is deliberate. An offhand 'be conservative, only flag severe ones' makes it swallow the small bugs it found — better a few extra to triage than one real bug silently dropped.4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-08。Claude API Docs · Prompting best practices — give it guardrails: confirm before irreversible actions, no destructive shortcuts like --no-verify; in code review tell it to report everything and not filter; read files first to avoid hallucination, do only what's asked to avoid over-engineering. As of 2026-08.
— IV
不写码,也用得上的三件事Three Things Even Non-Coders Can Use.
一个装了三百张扫描件、命名乱七八糟的文件夹,按「年份-供应商-金额」重命名并分文件夹。给它护栏那句「不可逆动作先问我」,并且先让它把改名计划打印出来给你看,确认无误再执行。这件事 Cowork 也能做(第 8 章),区别是终端里你能先看到完整的计划。A folder of three hundred scans with chaotic names, renamed to 'year-vendor-amount' and sorted into subfolders. Give it the 'ask before irreversible actions' guardrail, and have it print the rename plan for you to read before executing. Cowork can do this too (Chapter 8); the difference is that in the terminal you see the full plan first.
改一个你不太懂的配置文件(nginx、CI 的 yaml、某个工具的 toml),让它先解释每一行现在在做什么、再改。这一栏的价值不在改,在那句「先解释」—— 你会发现自己维护了两年的配置里,有三行谁也不知道是干嘛的。Editing a config file you don't fully understand (nginx, a CI yaml, some tool's toml): have it explain what each line currently does before changing anything. The value here isn't the edit — it's the 'explain first,' which reliably reveals that three lines in a config you've maintained for two years do something nobody remembers.
「把这个 CSV 按某列拆成十二个文件」这种活,让它写一个一次性脚本跑掉,比在 Excel 里点二十分钟快。关键在于要它把脚本留下来 —— 下次同样的活,你只要改一个参数。这就是把一次性劳动变成一件资产。'Split this CSV by one column into twelve files' — have it write a throwaway script and run it, faster than twenty minutes of clicking in Excel. The key is to make it keep the script: next time the same job needs one parameter changed. That's how one-off labor becomes an asset.
都不需要你会编程,只需要你会用终端敲一条命令 —— 或者干脆让它替你敲。共同点:都是「一堆文件上的重复操作」。None of these require programming — only that you can type one command in a terminal, or hand that off too. What they share: each is a repetitive operation across a pile of files.
— V
边界:什么时候别开终端Boundaries: When Not to Open the Terminal.
没有验收标准的活Work with no acceptance criteria
「让这段代码更好一点」在终端里最容易变成一场漫无目的的长会话。它最强的是「有明确验收标准」的活 —— 定不出标准,先回网页 chat 把标准想清楚。'Make this code a bit better' is how an aimless long session starts. It's strongest on work with clear acceptance criteria — if you can't define one, go back to web chat and work out the criteria first.
你读不懂的 diffA diff you can't read
它把瓶颈从打字挪到了读 diff。你审 diff 的速度就是你的速度 —— 如果那段代码你根本读不懂,交给它做只是把风险往后推了一步。It moves the bottleneck from typing to reading the diff. Your diff-reading speed is your speed — and if you can't read that code at all, delegating just defers the risk by one step.
先别急着上自动化Don't rush the automation
再往上它能更自动:hooks 在它动作前后跑命令、subagents 并行做一件大任务的不同部分、background agents 让你一屏盯几个会话。3注 3Note 3Anthropic · Enabling Claude Code to work more autonomously —— 后台 agent、子 agent 与 hooks,让一次会话并行推进多件事。Anthropic · Enabling Claude Code to work more autonomously — background agents, subagents, and hooks let one session push several things in parallel.但对个人用户,先把单会话用顺就够 —— 这些值不值得碰,看你的活是不是真能拆开并行。It can go further: hooks run commands before or after its actions, subagents split one big task, background agents let you watch several sessions at once.3注 3Note 3Anthropic · Enabling Claude Code to work more autonomously —— 后台 agent、子 agent 与 hooks,让一次会话并行推进多件事。Anthropic · Enabling Claude Code to work more autonomously — background agents, subagents, and hooks let one session push several things in parallel. But for an individual, getting one session smooth is enough first — whether these are worth it depends on whether your work genuinely splits into parallel parts.
Agent SDK 是另一回事The Agent SDK is a different thing
再往外的 Agent SDK 是给你自己搭定制 agent 的,那是开发者地界,这本书不展开。Further out, the Agent SDK is for building your own custom agents — developer land, beyond this book.
— VI
收束 · 本章验收Sign-off.
项目根目录有一份 CLAUDE.md,含「怎么跑 / 怎么验 / 禁区」三段。The project root holds a CLAUDE.md with 'how to run / how to verify / off-limits.'
新开会话问「这个项目怎么跑、怎么验一个改动」,它答得上来。A fresh session can answer 'how do I run this and how do I verify a change.'
跑了一次完整循环:先有一个会失败的测试,再让它实现。Closed one full loop: a failing test first, implementation second.
它交回来的是命令输出,不是一句「我搞定了」。What it handed back was command output, not 'it works.'
你自己读完了 diff,并记下了哪一步它快、哪一步你还得自己来。You read the diff yourself and noted which step it was faster at and which you still had to do.
至少往 CLAUDE.md 的禁区那段加了一行 —— 来自这次真的踩到的地方。Added at least one line to the off-limits block — from something that actually went wrong this time.
终端里它做得快,
但 diff 还得你看.
It's fast in the terminal,
but the diff is still yours to read.
Aklman Library
— 讨论Discussion
讨论Discussion.
评论区初始化中…Initializing comments…
01 / 01
没有匹配结果No matches.
换个关键词,或按 Esc 回到页面Try another keyword, or press Esc to return