Claude Code 101 系列字幕笔记(英中对照)
来源:Anthropic 官方 YouTube 播放列表 Claude Code 101(共 9 集,其中第 1 集 "What is Claude Code?" 因版权被下架,未收录)。 每节按顺序给出:英文摘要一段,中文摘要一段,交替排列。技术术语与专有名词保留英文。
来源:Anthropic 官方 YouTube 播放列表 Claude Code 101(共 9 集,其中第 1 集 “What is Claude Code?” 因版权被下架,未收录)。 每节按顺序给出:英文摘要一段,中文摘要一段,交替排列。技术术语与专有名词保留英文。
1. Installing Claude Code(安装)
Claude Code can be installed in a terminal, on the web, or inside your IDE. On macOS, Linux, or WSL, the recommended way is a single curl command; Homebrew (brew install) is an alternative, though the brew package lacks auto-update. On Windows, you can install via PowerShell or winget (same auto-update caveat). On first launch inside a project directory you complete a short setup: choose a theme, sign in with a Pro/Max or Enterprise account, or provide an API key. Whatever directory you run Claude Code in, it gains access to that directory and everything under it. In VS Code, open the Extensions panel, search for “Claude Code,” install the extension published by Anthropic (look for the blue checkmark), and restart the editor if prompted. Open the Command Palette with Ctrl/Cmd+Shift+P, run “Claude Code,” and open a new tab; you can also click the Claude logo when a file is open. JetBrains IDEs have a Claude Code plugin from the JetBrains Marketplace; after installing and restarting, a Claude icon opens a pane with the same terminal experience. On Claude Desktop, install Claude Desktop, sign in, and toggle the “Claude Code” option; it behaves like the desktop app but lets you work in a specific folder. On the web, go to claude.ai/code; it works like the desktop version but is restricted to repositories hosted on the web. For always having the latest features, the terminal is the best choice — new features ship there first.
Claude Code 可以在终端、网页或 IDE 中安装使用。在 macOS、Linux 或 WSL 上,推荐使用单条 curl 命令一键安装;Homebrew(brew install)也是可选方案,但该方式安装的版本不具备自动更新功能。在 Windows 上,可通过 PowerShell 命令或 winget 安装(同样存在自动更新方面的限制)。首次在项目目录中启动时,你需要完成简短配置:选择主题、使用 Pro/Max 或 Enterprise 账号登录,或提供 API key。无论你在哪个目录中运行 Claude Code,它都能访问该目录及其下的全部内容。在 VS Code 中,打开扩展面板搜索 “Claude Code”,安装由 Anthropic 发布的扩展(认准蓝色对勾徽标),如有提示则重启编辑器。随后可通过 Ctrl/Cmd+Shift+P 打开命令面板,运行 “Claude Code” 并新建标签页;当文件打开时也可以点击 Claude 徽标。JetBrains IDE 可从 JetBrains Marketplace 安装 Claude Code 插件,安装并重启后,Claude 图标会打开一个窗格,提供与终端一致的体验。在 Claude Desktop 中,安装并登录后,可打开 “Claude Code” 开关;其外观与桌面应用类似,但支持在指定文件夹内工作。网页端可访问 claude.ai/code,功能与桌面版接近,但只能操作托管在网页端的仓库。若想第一时间用上新功能,终端是最佳选择——新特性最先在终端发布。
2. How Claude Code Works(工作原理)
Claude Code differs from ordinary chat applications, and it is best explained through the agentic loop. You enter a prompt, and Claude Code gathers the context required to fulfill it by interacting with the model. The model returns either text or a tool call that Claude Code can execute — for example, editing a file or running a command. Claude Code then takes that action and verifies the results, determining whether they achieve what your prompt set out to do. If the goal is met, Claude finishes and waits for the next prompt. If not, it loops again — re-running the cycle until the results satisfy the original request.
Claude Code 与普通的聊天应用不同,用”智能体循环”(agentic loop)这个概念能最好地解释其运作方式。你输入一条 prompt 后,Claude Code 会通过与模型交互来收集完成该 prompt 所需的上下文。模型返回的是文本或工具调用(tool call),而 Claude Code 可以实际执行这些工具调用——例如编辑文件或运行命令。随后 Claude Code 执行该操作并验证结果,判断其是否达成了 prompt 最初设定的目标。如果目标已达成,Claude 便结束本轮工作并等待下一条 prompt;如果未达成,它会回到循环中继续迭代,反复运行这一过程,直到结果满足原始请求为止。
3. Your First Claude Code Prompt(你的第一个 prompt)
You can talk to Claude Code like you would to any AI assistant, but a few settings protect you and make work easier. With Shift+Tab you cycle between modes: in auto-accept mode, Claude automatically approves file edits but still asks before running commands. There is no right or wrong choice — pick what feels best. Plan mode uses your prompt with tools to analyze your code and research your proposed changes; it asks clarifying questions, then returns a detailed plan it can execute. Plan mode is great for complex changes or safe reviews. In the demo, a mode-toggle feature is requested (“dark mode across the app, a toggle in the header, good contrast colors based on the existing light theme”); after entering plan mode twice with Shift, Claude plans, and the reviewer approves. The takeaway: be as explicit as possible. You can stay in the loop at every step, or use plan mode to let Claude dig into the details of what you want before executing.
你可以像使用任何 AI 助手一样与 Claude Code 对话,但有几项设置既能保护你,也让工作更轻松。按 Shift+Tab 可在两种模式间切换:在自动接受模式(auto-accept mode)下,Claude 会自动批准文件编辑,但执行命令前仍会征询你的同意。这两种模式没有对错之分,选择你觉得最顺手的方式即可。Plan 模式会利用工具分析你的代码,针对你提议的改动做研究,并提出澄清问题,最后返回一份它可执行的详细计划。Plan 模式非常适合复杂的改动或安全的代码审查。在演示中,用户请求实现一个”全应用暗色模式:在 header 添加切换开关,并基于现有浅色主题找到合适的对比色”的功能;连续按两次 Shift 进入 Plan 模式后,Claude 完成规划并由审查者批准执行。核心建议是:prompt 写得越明确越好。你可以每一步都保持参与,也可以借助 Plan 模式让 Claude 在执行前深入理解你的需求细节。
4. The CLAUDE.md File(CLAUDE.md 文件)
The CLAUDE.md file is one of the most useful parts of Claude Code: it gives Claude Code persistent memory about your project. Without it, every session starts from scratch — Claude must rediscover your codebase, understand which dependencies are needed, and which features are already implemented, making assumptions along the way. CLAUDE.md sits at the root of your project and is read automatically every time you start a session; its contents are appended to your prompt, like an onboarding script for your codebase. The /init command asks Claude to generate one based on your existing code. A sample file might state: “Next.js 15 app using the App Router, Tailwind, and Drizzle ORM; use two-space indentation, named exports; all API routes go under app/api; prefer server actions over API routes.” With such guidance, Claude can style a React component correctly and do its job right out of the gate. There is a hierarchy of memory files: the project-level CLAUDE.md in the root, and a user-level CLAUDE.md in your config folder that applies across all your projects (put personal preferences here, like how you write comments). If you keep correcting Claude (e.g., “always use server actions instead of API routes”), ask it to save that to the file so it remembers on future sessions. You can also reference docs with the @ symbol followed by a file path. The recommendation: start a project without a CLAUDE.md and observe where you keep correcting Claude — those corrections are what should go into the file.
CLAUDE.md 文件是 Claude Code 最有用的部分之一:它为 Claude Code 提供关于项目的持久记忆。如果没有它,每次会话都从零开始——Claude 必须重新探索你的代码库、弄清楚需要哪些依赖、哪些功能已实现,并在过程中不断做出假设。CLAUDE.md 位于项目根目录,每次启动会话时都会被自动读取,其内容会追加到你的 prompt 中,相当于一份代码库的”入职脚本”。使用 /init 命令可以让 Claude 基于现有代码自动生成一份。一个示例文件可能这样写:“基于 Next.js 15 的应用,使用 App Router、Tailwind 和 Drizzle ORM;使用两个空格缩进、命名导出;所有 API 路由放在 app/api 下;优先使用 server actions 而非 API routes。“有了这样的指引,Claude 就能正确地给 React 组件设置样式,一上来就能高效工作。记忆文件存在层级:项目级 CLAUDE.md 位于根目录;用户级 CLAUDE.md 位于你的配置文件夹中,跨所有项目生效(把个人偏好放这里,比如注释的写法)。如果反复纠正 Claude(例如”始终使用 server actions 而非 API routes”),可以请它把规则存进文件,这样下次会话它就会记住。还可以用 @ 符号加文件路径来引用项目中的文档。建议的做法是:先不带 CLAUDE.md 开始项目,观察你反复纠正 Claude 的地方——这些纠正正是应该写进文件的内容。
5. Explore → Plan → Code → Commit Workflow(工作流)
If you take one thing away from Claude Code, let it be this workflow: Explore, Plan, Code, Commit. Most people jump straight to pasting into Claude to write code, which means more course-correcting later. The fastest way to handle exploration is plan mode: it cannot edit files, only reads to gather research. Enter it by hitting Shift+Tab until you see plan mode under the text input. For example: “We need to add WebP conversion to our upload pipeline. Figure out where in the pipeline it should happen, what new dependencies we need, and how to approach it.” Claude reads relevant files, does web searches, and returns an actionable plan. Review it and add or remove items; this is the best moment to course-correct, before any code is written. You can also explore outside plan mode by simply asking Claude to explore your codebase. Once the plan looks good, you can approve it, and Claude toggles the checklist items. You decide whether Claude auto-accepts file edits or asks every time. Claude troubleshoots your codebase on its own, but sometimes you must correct it — and after plan mode, you still have the record of how it reached its results to guide its next decision. For Claude to be confident, it must be clear on what “correct” means — make this explicit in your prompts. Tools that help Claude verify will remove back-and-forth: for web UIs, use the Claude and Chrome integration so it can open a tab and test the UI before finishing; include a test suite Claude can validate against (it can even write tests). Make tests a source of truth to avoid false positives. If Claude keeps hitting the same issues, ask it to save the solution to its CLAUDE.md. Once you’re happy with the results, push your code — a tip: run a subagent code reviewer over your code first, then have Claude generate a commit in your style. Exploration gathers the context Claude needs; Plan creates a course of action; Code handles the back-and-forth of implementation; Commit lets you review and push so you can start the next feature.
如果只记住 Claude Code 的要点,那一定是这个工作流:Explore(探索)→ Plan(计划)→ Code(编码)→ Commit(提交)。大多数人是直接把任务粘贴给 Claude 让它写代码,这往往意味着之后要花更多时间纠正方向。探索阶段最快的方式是使用 Plan 模式:它不能编辑文件,只读取代码以收集研究信息。在文本输入框下按 Shift+Tab 直到切换到 Plan 模式即可进入。例如:“我们需要在上传 pipeline 中加入 WebP 转换。确定应该在 pipeline 的哪个环节做、需要哪些新依赖,以及如何实施。“Claude 会阅读相关文件、进行网页搜索,然后返回一份可执行的计划。仔细审查它,必要时增删条目;这是在写任何代码之前纠正方向的最佳时机。你也可以不进入 Plan 模式,直接让 Claude 探索代码库。计划满意后即可批准,Claude 会逐项勾选清单。你可以决定让 Claude 自动接受文件编辑,还是每次都征求同意。Claude 会尽力自行排查代码库,但有时你需要纠正它——而使用 Plan 模式的额外好处是,我们保留了它得出结果的推理记录,可用于指导下一步决策。为了让 Claude 有信心,它必须清楚”正确”的标准是什么——请在 prompt 中明确写出。能帮助 Claude 验证的工具会省去大量往返:构建 Web UI 时,使用 Claude 与 Chrome 的集成,让它在完成前打开标签页实测界面;在项目中加入测试套件供 Claude 持续验证(它甚至能为你编写测试),并让测试成为你和团队的”事实来源”,避免误报。如果发现 Claude 反复踩到同一类问题,可以请它把解决方案保存到 CLAUDE.md。当结果令你满意后,就可以提交代码了——一个小技巧:先用一个 subagent 代码审查器检查代码,再让 Claude 以你的风格生成 commit。探索阶段收集 Claude 所需的上下文,计划阶段制定行动方案,编码阶段处理实现的往返迭代,提交阶段完成审查与推送,以便开启下一个功能。
6. Context Management(上下文管理)
Context is Claude’s working memory — every file it reads, every command it runs, every message you send takes up space in the context window. Think of the context window as a fixed amount of space Claude can hold in memory. When you enter a prompt, Claude reads a file, runs a tool call, and gets a result back; all of this is added to the window. Because space is limited, optimizing it becomes crucial. When you approach the limit, the window is automatically compacted: Claude summarizes the important parts, removes unnecessary tool results, and frees up space — though this can lose conversation details. You can run compaction manually with /compact, which summarizes everything up to that point while keeping a memory of what you worked on. To start completely fresh with no memory, use /clear. To inspect the state of your context, run /context: you get a big-picture view of how large your context is, which entries take up the most space, and a graphic showing it all. Rule of thumb: when you’re mid-feature and approaching the window limit but need to continue, compact — keeping context relevant is important for continuity. When you’ve finished a plan and want to start a new feature, clear — you don’t want previous conversation biasing anything new. For things you want Claude to remember across other projects, put them in the CLAUDE.md file so it doesn’t rediscover everything from scratch. The irony of writing a prompt is that being vague takes up more context in the long run: when you’re ambiguous, Claude is forced to look around your codebase more and reason on its own, which consumes more window space than being explicit in a sentence or two. Subagents (sub-agents) load all of their context separately, which keeps the main conversation lean.
上下文是 Claude 的工作记忆——它读取的每个文件、运行的每条命令、你发送的每条消息,都会占用上下文窗口(context window)中的空间。可以把上下文窗口想象成 Claude 能在记忆中保留的固定容量。当你输入一条 prompt 时,Claude 会读取文件、运行工具调用并得到返回结果,这一切都会被加入窗口。由于空间有限,尽可能优化上下文就显得极为重要。当接近上限时,窗口会自动压缩(compaction):Claude 会总结重要信息、移除不必要的工具结果,从而释放大量空间——但请注意,这可能会丢失对话中的细节。你也可以用 /compact 命令手动压缩,它会把到目前为止的所有内容做一次总结,既腾出上下文,又保留此前工作内容的记忆。如果想彻底从零开始、不保留任何记忆,可以运行 /clear。要检查上下文状态,运行 /context 命令:这里能看到上下文整体大小的概览、哪些条目占用最多空间,以及一张直观的统计图。经验法则:当你在某个功能进行中、接近窗口上限但仍需继续时,使用 compact——保持上下文相关性对连续性很重要。当你完成一个计划、准备开始新功能时,使用 clear——你不希望之前的对话为新内容引入偏见。而那些希望 Claude 跨项目长期记住的东西,请放进 CLAUDE.md 文件,这样它就不必每次重新发现。写 prompt 有个反直觉之处:写得含糊在长期来看反而更占上下文。因为当你不明确时,Claude 被迫更多地在代码库中四处搜索、独自推理,这比用一两句话讲清楚要消耗更多的窗口空间。Subagent(子智能体)会各自独立加载自己的上下文,从而使主对话保持精简。
7. MCP in Claude Code(MCP 集成)
The Model Context Protocol (MCP) is an open standard that lets Claude Code connect to external tools and data sources. When you ask a question, Claude understands when it should invoke those tools to better answer your query. This is one of the most important things when working with Claude Code, because much of your context lives elsewhere — in databases, productivity apps, or public repositories. Understanding tools is key when talking about AI: tools give agents like Claude Code the ability to perform actions to better complete their tasks, which is different from other AI where you just get an output back. For example, if your team uses Linear as project management software, you can add an MCP server to bring in the context of your specific issues. For up-to-date documentation of a dependency you’re working with, the Context7 server provides it to Claude Code. There are hundreds of connectors at claude.com/connectors. You can add MCP servers with the /mcp command. There are two main types: HTTP servers for remote services (hosted by the service provider, reached over the network) and local servers for processes that run on your machine. Inside a Claude Code session, /mcp shows which servers are connected, their status, and lets you disable servers you don’t want. MCP servers can be scoped three ways: local (only available in the current project, for you), user (available across all your projects), and project scope using a .mcp.json that you check into version control, so anyone working on the code gets the exact same servers. One caveat: every MCP server adds its tool definitions to your context window even when unused, so many configured servers eat into your available context — use /mcp to disable anything you’re not actively using. If a tool has a CLI equivalent (like gh for GitHub or the AWS CLI), the CLI is often more context-efficient because it doesn’t add persistent tool definitions.
Model Context Protocol(MCP)是一个开放标准,允许 Claude Code 连接外部工具与数据源。当你提问时,Claude 会判断何时应当调用这些工具来更好地回答你的问题。这是使用 Claude Code 时最重要的事项之一,因为你的大量上下文其实存在于别处——数据库、效率应用或公共仓库中。谈论 AI 时理解”工具”是关键:工具赋予 Claude Code 这类智能体执行操作的能力,以更好地完成任务;这不同于其他直接返回输出的 AI。例如,如果你的团队使用 Linear 作为项目管理软件,可以添加一个 MCP server,把具体 issue 的上下文引入进来。想要某个依赖的最新文档时,Context7 server 就能把它提供给 Claude Code。claude.com/connectors 上有数百种现成连接器。你可以用 /mcp 命令添加 MCP server。MCP server 主要有两类:HTTP server 用于远程服务(由服务提供商托管、通过网络访问),本地 server 用于运行在你机器上的进程。在 Claude Code 会话中,/mcp 可以查看已连接的 server、它们的状态,并能禁用心想不再使用的 server。MCP server 有三种作用域:local(仅当前项目、仅对你有用)、user(跨你所有项目生效),以及 project 作用域——使用提交进版本控制的 .mcp.json 文件,这样任何参与该代码库的人都会获得完全相同的 server。需要注意:即使未使用,每个 MCP server 也会把工具定义加入你的上下文窗口,因此配置过多的 server 会蚕食可用的上下文——请用 /mcp 禁用当前不活跃使用的部分。如果某个工具有对应的 CLI 版本(如 GitHub 的 gh 或 AWS CLI),CLI 通常更省上下文,因为它不会添加常驻的工具定义。
8. Hooks(钩子)
Hooks let you run commands at different points in Claude Code’s lifecycle. The key difference from everything else covered is that hooks are deterministic — they always run. You can tell Claude in your CLAUDE.md to run Prettier after every file edit, and most of the time it will, but sometimes not perfectly; a hook makes it happen every single time with no exceptions. Use cases include auto-formatting after file edits, logging all commands for compliance, blocking dangerous operations like touching production files, and sending notifications when Claude finishes a task. Hooks are configured in your config file: pick an event, optionally set a matcher for which tool it applies to, and provide a command to run. PromptSubmit runs when you submit a prompt before Claude processes it. PreToolUse runs before a tool executes; PostToolUse runs after a tool completes. Notification runs when Claude sends a notification, and Stop runs when Claude stops responding. PostToolUse is the most common hook — e.g., formatting after edits: set a PostToolUse hook with a matcher of edit or multi-edit; whenever Claude modifies a file, the command checks the file and runs the appropriate formatter — Prettier for TypeScript, gofmt for Go, Ruff for Python, whatever your project uses. PreToolUse hooks can block tool calls before they execute: your hook receives tool name and input as JSON on stdin; if it exits with code 2, the action is blocked and the stderr message is fed to Claude as feedback so Claude knows why it was blocked and can adjust. Exit code 0 means proceed; exit code 2 means block — this is how you enforce hard rules. Examples: block edits to a production config, block bash commands containing rm -rf, block commits to main. You configure hooks at project level and can check them into your repo, so your whole team gets the same hooks. Use the CLAUDE_PROJECT_DIR environment variable in your commands to reference files stored in your project so they work regardless of Claude’s current working directory. Hooks give you deterministic control over Claude Code’s behavior: use PostToolUse for auto-formatting and logging, use PreToolUse to block operations. Configure them in .claude/hooks or in settings.json — and check them into your repo.
Hook(钩子)允许你在 Claude Code 生命周期的不同节点运行命令。与之前讲到的所有内容相比,关键区别在于 hook 是确定性的——它们必定会执行。你可以在 CLAUDE.md 中告诉 Claude 每次文件编辑后运行 Prettier,大多数时候它会照做,但偶尔不够完美;而 hook 能让它每次、毫无例外地发生。常见用例包括:文件编辑后自动格式化、为合规要求记录所有命令、阻止诸如修改生产环境文件之类的危险操作,以及在 Claude 完成任务时发送通知。Hook 在你的配置文件中配置:选择一个事件(event),可选地设置针对某个工具的匹配器(matcher),再提供要运行的命令。PromptSubmit 在你提交 prompt、Claude 处理之前运行。PreToolUse 在工具执行前运行;PostToolUse 在工具完成后运行。Notification 在 Claude 发送通知时运行,Stop 在 Claude 停止响应时运行。PostToolUse 是最常用的 hook——例如编辑后格式化:设置一个 matcher 为 edit 或 multi-edit 的 PostToolUse hook;每当 Claude 修改文件时,该命令都会检查文件并运行合适的格式化器——TypeScript 用 Prettier,Go 用 gofmt,Python 用 Ruff,按项目所需配置。PreToolUse hook 可以在工具执行前拦截:你的 hook 会通过 stdin 以 JSON 形式收到工具名称与输入;如果它以退出码 2 结束,该操作会被阻止,stderr 中的消息会作为反馈传给 Claude,让 Claude 明白被阻止的原因并做出调整。退出码 0 表示继续,退出码 2 表示阻止——这就是强制执行硬性规则的方式。示例:阻止对生产配置文件的修改、阻止包含 rm -rf 的 bash 命令、阻止向 main 分支提交。你可以在项目级别配置 hook 并提交进仓库,这样整个团队都能获得相同的 hook。在命令中使用 CLAUDE_PROJECT_DIR 环境变量来引用项目内存储的文件,这样无论 Claude 当前的工作目录是什么,命令都能正常工作。Hook 让你对 Claude Code 的行为拥有确定性的控制:PostToolUse 用于自动格式化与日志记录,PreToolUse 用于阻止危险操作。在 .claude/hooks 或 settings.json 中配置它们——并记得提交进仓库。
附录:系列索引
| # | 视频 | 说明 |
|---|---|---|
| 1 | What is Claude Code? | 因版权下架,字幕未收录 |
| 2 | Installing Claude Code | 安装(终端 / IDE / 网页 / Desktop) |
| 3 | How Claude Code Works | Agentic loop 工作原理 |
| 4 | Your First Claude Code Prompt | 模式切换与 Plan 模式 |
| 5 | The CLAUDE.md File | 项目持久记忆 |
| 6 | Explore → Plan → Code → Commit | 核心工作流 |
| 7 | Context Management | 上下文窗口与压缩/清理 |
| 8 | MCP in Claude Code | MCP 集成与作用域 |
| 9 | Hooks in Claude Code | 生命周期钩子与强制规则 |