写码 · 终端里的开发循环Write Code · The Development Loop in Your Terminal.
如果你完全不碰代码,这章可以跳过 —— 这正是把它单独拎出来的原因。Claude Code 是跑在终端、IDE、桌面里的 agent:读仓库、跑命令、改文件、提 commit。这章给那条线:什么时候终端里的循环胜过对话框,什么时候别用它。If you never touch code, skip this chapter — which is exactly why it's a separate one. Claude Code is an agent that runs in your terminal, IDE, and desktop: reading the repo, running commands, editing files, making commits. Here's the line — when the terminal loop beats the chat box, and when not to reach for it.
如果你完全不碰代码,这一章可以跳过 —— 把它单独拎出来,就是为了让你能干净地跳过,不必为一项用不上的能力分心。如果你偶尔写点脚本、改点配置,那它和你有关。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. If you occasionally write a script or tweak a config, it concerns you.碰代码的活,也分四个地方放 —— 别都丢进网页那个框:Code work splits across four places too — don't drop it all in the web box:
你要做的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
— I
它是 agent,不是补全It's an Agent, Not Autocomplete.
Claude Code 不是编辑器里的自动补全,是一个会读你整个仓库、自己跑命令的 agent。Claude Code isn't editor autocomplete — it's an agent that reads your whole repo and runs commands itself.它跑在终端、IDE、桌面与浏览器里,共用同一套引擎:读代码库、改文件、跑命令,再看结果、自己调整,直到把一件事做完。1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。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.你的工作从「逐行写」变成「定义任务、审查结果」。It runs in the terminal, IDE, desktop, and browser on one shared engine: reading the codebase, editing files, running commands, then checking results and adjusting until a task is done.1注 1Note 1Claude Code Docs · Overview —— Claude Code 是 agent 化编码工具:读代码库、改文件、跑命令,再评估并调整;在终端、IDE、桌面、浏览器里都能跑,共用同一套引擎与 CLAUDE.md。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. Your work shifts from 'writing line by line' to 'defining tasks and reviewing results.'它怎么记住你的项目:CLAUDE.md 是放在项目根目录的一份 markdown,它每开一个新会话都先读 —— 写你的代码规范、架构决定、常用库;它还会自己攒下构建命令、调试心得,跨会话保留。和网页 chat 写代码的本质区别就在这:一个能直接动你的文件并验证,一个只能给你一段、你再去粘。How it remembers your project: CLAUDE.md is a markdown file in the project root that it reads at the start of every session — your coding standards, architecture decisions, preferred libraries; it also accumulates build commands and debugging notes across sessions on its own. That's the real difference from writing code in web chat: one edits and verifies your files directly, the other hands you a snippet to paste.把仓库交给它之前,先确认这几样到位 —— 缺一样,它就得靠猜:Before handing it the repo, confirm these are in place — miss one and it has to guess:
README / CLAUDE.md 里写了:项目是什么、怎么跑起来。README / CLAUDE.md says what the project is and how to run it.
测试、lint、typecheck 各是哪条命令,写进 CLAUDE.md。The test, lint, and typecheck commands are each written into CLAUDE.md.
环境变量 / 密钥怎么配 —— 但别把真密钥贴给它。How env vars / secrets are configured — but don't paste real secrets to it.
哪些目录或文件是禁区,明确告诉它别碰。Which directories or files are off-limits, told to it explicitly.
有一条它能自己跑的检查(测试或构建),好让它交证据、不是交断言。There's a check it can run itself (tests or a build), so it shows evidence, not assertions.
— II
订阅就含,不另花 APIIncluded in the Plan, No API Bill.
Claude Code 已经在你的订阅里,不用你去开 API 账户。Claude Code is already in your subscription — no API account to open.Pro 和 Max 都直接包含 Claude Code,用的是订阅额度,不是单独计费的 API。2注 2Note 2Claude 帮助中心 · 用 Pro 或 Max 账号使用 Claude Code —— Claude Code 已包含在 Pro / Max 订阅里,用订阅额度,无需另购 API。Claude Help Center · Use Claude Code with your Pro or Max plan — Claude Code is included in the Pro / Max subscription, drawing on plan quota, no separate API needed.这点和很多人的预期相反 —— 它常被当成开发者专属的付费工具,其实你那份 $20 的 Pro 就能跑。代价是它吃额度:重活比闲聊更快撞到限额。Both Pro and Max include Claude Code directly, drawing on your subscription quota rather than a separately billed API.2注 2Note 2Claude 帮助中心 · 用 Pro 或 Max 账号使用 Claude Code —— Claude Code 已包含在 Pro / Max 订阅里,用订阅额度,无需另购 API。Claude Help Center · Use Claude Code with your Pro or Max plan — Claude Code is included in the Pro / Max subscription, drawing on plan quota, no separate API needed. This runs counter to many people's assumption — 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.再往上它能更自动:hooks 在它动作前后跑命令(改完自动格式化、提交前先 lint),subagents 派多个 agent 并行做一件大任务的不同部分,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.对个人用户,这些值不值得碰,看你的活是不是真能拆开并行 —— 多数人先把单会话用顺就够。再往外的 Agent SDK 是给你自己搭定制 agent 的,那是开发者地界,这本书不展开。It can go further: hooks run commands before or after its actions (auto-format after an edit, lint before a commit), subagents spawn several agents on different parts of one big task, and background agents let you watch several sessions run at once from one screen.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. For an individual, whether these are worth it depends on whether your work truly splits into parallel parts — most people are fine getting one session smooth first. Further out, the Agent SDK is for building your own custom agents — developer land, beyond this book.
— III
终端循环 vs 对话框The Terminal Loop vs the Chat Box.
改完代码它做得快,但 diff 还得你看。It's fast once the code's done, but the diff is still yours to read.给条线:当一件事要跨多个文件、要跑起来验证、要在你真实的仓库里改时,终端循环胜过对话框;当你只是想问清一个概念、推敲一段思路时,网页 chat 更顺。它最强的是「有明确验收标准」的活 —— 先写测试再让它实现。别在终端里跑漫无目的的长会话。The line: when a task spans many files, needs to run and be verified, and lives in your real repo, the terminal loop beats the chat box; when you just want to clarify a concept or think through an approach, web chat flows better. It's strongest on work with clear acceptance criteria — write the tests first, then have it implement. Don't run aimless long sessions in the terminal.有个 Opus 4.8 的脾气要顺着用:它更字面地执行你的指令。6注 6Note 6Claude API Docs · What's new in Claude Opus 4.8 —— Opus 4.8 更字面地执行指令、按任务难度自校准回答长度。截至 2026-07。Claude API Docs · What's new in Claude Opus 4.8 — Opus 4.8 follows instructions more literally and self-calibrates response length to task difficulty. As of 2026-07.好处是听话;坏处是你随口说一句「保守点、只报严重的」,它真会把查到的小 bug 咽回去不报。所以让它做代码评审,反过来明说「全报、别替我过滤」—— 宁可多报几条你再筛,也别让它默默吞掉一个真 bug。4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-07。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-07.One Opus 4.8 trait to work with: it follows instructions more literally.6注 6Note 6Claude API Docs · What's new in Claude Opus 4.8 —— Opus 4.8 更字面地执行指令、按任务难度自校准回答长度。截至 2026-07。Claude API Docs · What's new in Claude Opus 4.8 — Opus 4.8 follows instructions more literally and self-calibrates response length to task difficulty. As of 2026-07. The upside is obedience; the downside is that an offhand 'be conservative, only flag severe ones' makes it swallow the small bugs it found. So for code review, say the opposite outright — 'report everything, don't filter for me' — better a few extra to triage than one real bug silently dropped.4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-07。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-07.越是放手让它自己跑,越要先给护栏。4注 4Note 4Claude API Docs · Prompting best practices —— 给它护栏:不可逆动作先确认、别用 --no-verify 等破坏性捷径;代码评审要它「全报别过滤」;先读文件防幻觉、只做被要求的防过度工程。截至 2026-07。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-07.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-07。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-07.
放手快做Just go fast
随便改,怎么快怎么来。Change whatever, fastest path wins.
给它护栏Give it guardrails
不可逆的动作 —— 删文件、force-push、对外发消息 —— 先问我再做;别用 --no-verify 这类绕过检查的捷径。Irreversible actions — deleting files, force-push, posting to external services — ask me first; and don't take shortcuts like --no-verify that bypass checks.
动手前先读相关文件,没读过的代码不要下结论。
只做我要求的改动,别顺手重构、别加没要的抽象。
不可逆的动作(删文件 / force-push / 对外发消息)先问我。
做评审时把发现的问题全列出来,别按严重度替我过滤。
做完给我证据:跑了哪些测试、命令输出是什么,而不是一句「我搞定了」。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.
In a review, list every issue you find; don't filter by severity for me.
When done, show evidence: which tests you ran and their output, not just 'it works.'
动手修这个登录超时的 bug 前,先读 src/auth/session.ts 和它的测试,没读过的代码不要下结论。
只把这个超时 bug 修掉,别顺手把整个 session 模块重构、别加没要的缓存层。
不可逆的动作(删 migration 文件 / force-push 到 main / 给 Slack 发上线通知)先问我。
顺手做完代码评审时把发现的问题全列出来,别按严重度替我过滤。
做完给我证据:跑了 npm test 之后的输出贴上来,而不是一句「我搞定了」。Before fixing this login-timeout bug, read src/auth/session.ts and its tests; don't conclude about code you haven't opened.
Fix only this 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.
In the review you do alongside, list every issue you find; don't filter by severity for me.
When done, show evidence: paste the output after running npm test, not just 'it works.'
评审这个 <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).
官方把一条叫作最高杠杆:给它一个能自己跑的检查 —— 测试、构建、一张可对比的截图。5注 5Note 5Claude Code Docs · Best practices —— 最高杠杆是「给它一个能自己跑的检查」,让它交证据(测试输出 / 命令 / 截图)而不是交断言。截至 2026-07。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-07.能自己验的活,你才敢真走开;验不了的,diff 还得你一行行看。Anthropic calls one practice the highest-leverage: give it a check it can run on its own — tests, a build, a screenshot to compare.5注 5Note 5Claude Code Docs · Best practices —— 最高杠杆是「给它一个能自己跑的检查」,让它交证据(测试输出 / 命令 / 截图)而不是交断言。截至 2026-07。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-07. 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.和 Cowork 的分工:同一套引擎,Claude Code 是开发者在自己的代码里做,Cowork 是桌面端替所有人做完非代码的活。碰代码、要进仓库,开终端;不碰代码,回前面那几章。The division with Cowork: same engine — Claude Code is developers working in their own code, Cowork is the desktop finishing non-code work for everyone. Touching code, going into a repo, open the terminal; not touching code, go back to the earlier chapters.(只对碰代码的人)把这章用到一个你最近手动改过的小改动上:(For those who touch code) Apply this to a small change you recently made by hand:
01
挑一个跨 3 个以上文件的小改动Pick a small change spanning 3+ files
找一个你最近手动做过、改动横跨三个以上文件的小任务。Find a small task you recently did by hand whose change spanned three or more files.
02
在仓库里用 Claude Code 重做一遍Redo it with Claude Code in the repo
给它定义清楚任务和验收标准,让它去改,你只审。Define the task and acceptance criteria clearly, let it make the change, and only review.
03
自己审 diff,记下分工Read the diff, note the division
记下哪一步它明显比你快,哪一步你还是得自己来。这条分工就是你之后该不该开终端的依据。Note which step it was clearly faster at and which you still had to do yourself. That division is your basis for when to open the terminal at all.
终端里它做得快,
但 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