17* [将研究委派给 subagents](#delegate-research-to-subagents),以保持主上下文清洁17* [将研究委派给 subagents](#delegate-research-to-subagents),以保持主上下文清洁
18* [将 Claude 管道输入脚本](#pipe-claude-into-scripts),用于 CI 和批处理18* [将 Claude 管道输入脚本](#pipe-claude-into-scripts),用于 CI 和批处理
19 19
20<h2 id="prompt-recipes">20## 提示工作流程
21 提示工作流程
22</h2>
23 21
24这些是日常任务的提示模式,如探索陌生代码、调试、重构、编写测试和创建 PR。每个都可以在任何 Claude Code 界面中工作;根据您的项目调整措辞。22这些是日常任务的提示模式,如探索陌生代码、调试、重构、编写测试和创建 PR。每个都可以在任何 Claude Code 界面中工作;根据您的项目调整措辞。
25 23
26<h3 id="understand-new-codebases">24### 理解新的代码库
27 理解新的代码库
28</h3>
29 25
30有关在 monorepo 或大型代码库中配置 Claude Code 的信息,请参阅 [Monorepos 和大型存储库](/docs/zh-CN/large-codebases)。26有关在 monorepo 或大型代码库中配置 Claude Code 的信息,请参阅 [Monorepos 和大型存储库](/docs/zh-CN/large-codebases)。
31 27
32<h4 id="get-a-quick-codebase-overview">28#### 快速获取代码库概览
33 快速获取代码库概览
34</h4>
35 29
36假设您刚加入一个新项目,需要快速了解其结构。30假设您刚加入一个新项目,需要快速了解其结构。
37 31
38<Steps>32**1. 导航到项目根目录**
39 <Step title="导航到项目根目录">33
40 ```bash theme={null}34```bash theme={null}
41 cd /path/to/project 35cd /path/to/project
42 ```36```
43 37
44 将 `/path/to/project` 替换为您项目的路径。38将 `/path/to/project` 替换为您项目的路径。
45 </Step>39
46 40**2. 启动 Claude Code**
47 <Step title="启动 Claude Code">41
48 ```bash theme={null}42```bash theme={null}
49 claude 43claude
50 ```44```
51 </Step>45
52 46**3. 请求高级概览**
53 <Step title="请求高级概览">47
54 ```text wrap theme={null}48```text wrap theme={null}
55 give me an overview of this codebase49give me an overview of this codebase
56 ```50```
57 </Step>51
58 52**4. 深入了解特定组件**
59 <Step title="深入了解特定组件">53
60 ```text wrap theme={null}54```text wrap theme={null}
61 explain the main architecture patterns used here55explain the main architecture patterns used here
62 ```56```
63 57
64 ```text wrap theme={null}58```text wrap theme={null}
65 what are the key data models?59what are the key data models?
66 ```60```
67 61
68 ```text wrap theme={null}62```text wrap theme={null}
69 how is authentication handled?63how is authentication handled?
70 ```64```
71 </Step>65
72</Steps>66> [!TIP]
73 67>
74<Tip>68> 提示:
75 提示:69>
76 70> * 从广泛的问题开始,然后缩小到特定领域
77 * 从广泛的问题开始,然后缩小到特定领域71> * 询问项目中使用的编码约定和模式
78 * 询问项目中使用的编码约定和模式72> * 请求项目特定术语的词汇表
79 * 请求项目特定术语的词汇表73
80</Tip>74#### 查找相关代码
81
82<h4 id="find-relevant-code">
83 查找相关代码
84</h4>
85 75
86假设您需要定位与特定功能相关的代码。76假设您需要定位与特定功能相关的代码。
87 77
88<Steps>78**1. 要求 Claude 查找相关文件**
89 <Step title="要求 Claude 查找相关文件">79
90 ```text wrap theme={null}80```text wrap theme={null}
91 find the files that handle user authentication81find the files that handle user authentication
92 ```82```
93 </Step>83
94 84**2. 获取有关组件如何交互的上下文**
95 <Step title="获取有关组件如何交互的上下文">85
96 ```text wrap theme={null}86```text wrap theme={null}
97 how do these authentication files work together?87how do these authentication files work together?
98 ```88```
99 </Step>89
100 90**3. 理解执行流程**
101 <Step title="理解执行流程">91
102 ```text wrap theme={null}92```text wrap theme={null}
103 trace the login process from front-end to database93trace the login process from front-end to database
104 ```94```
105 </Step>95
106</Steps>96> [!TIP]
107 97>
108<Tip>98> 提示:
109 提示:99>
110 100> * 明确说明您要查找的内容
111 * 明确说明您要查找的内容101> * 使用项目中的领域语言
112 * 使用项目中的领域语言102> * 为您的语言安装 [code intelligence plugin](/docs/zh-CN/plugins/code-intelligence),以便 Claude 能够精确地进行"转到定义"和"查找引用"导航
113 * 为您的语言安装 [code intelligence plugin](/docs/zh-CN/plugins/code-intelligence),以便 Claude 能够精确地进行"转到定义"和"查找引用"导航
114</Tip>
115 103
116***104***
117 105
118<h3 id="fix-bugs-efficiently">106### 高效修复错误
119 高效修复错误
120</h3>
121 107
122假设您遇到了错误消息,需要找到并修复其来源。108假设您遇到了错误消息,需要找到并修复其来源。
123 109
124<Steps>110**1. 与 Claude 分享错误**
125 <Step title="与 Claude 分享错误">111
126 ```text wrap theme={null}112```text wrap theme={null}
127 I'm seeing an error when I run npm test113I'm seeing an error when I run npm test
128 ```114```
129 </Step>115
130 116**2. 请求修复建议**
131 <Step title="请求修复建议">117
132 ```text wrap theme={null}118```text wrap theme={null}
133 suggest a few ways to fix the @ts-ignore in user.ts119suggest a few ways to fix the @ts-ignore in user.ts
134 ```120```
135 </Step>121
136 122**3. 应用修复**
137 <Step title="应用修复">123
138 ```text wrap theme={null}124```text wrap theme={null}
139 update user.ts to add the null check you suggested125update user.ts to add the null check you suggested
140 ```126```
141 </Step>127
142</Steps>128> [!TIP]
143 129>
144<Tip>130> 提示:
145 提示:131>
146 132> * 告诉 Claude 重现问题的命令并获取堆栈跟踪
147 * 告诉 Claude 重现问题的命令并获取堆栈跟踪133> * 提及重现错误的任何步骤
148 * 提及重现错误的任何步骤134> * 让 Claude 知道错误是间歇性的还是持续的
149 * 让 Claude 知道错误是间歇性的还是持续的
150</Tip>
151 135
152***136***
153 137
154<h3 id="refactor-code">138### 重构代码
155 重构代码
156</h3>
157 139
158假设您需要更新旧代码以使用现代模式和实践。140假设您需要更新旧代码以使用现代模式和实践。
159 141
160有关将整个代码库迁移到新语言的信息,请参阅博客上的 [Anthropic 如何使用 Claude Code 运行大规模代码迁移](https://claude.com/blog/ai-code-migration)。142有关将整个代码库迁移到新语言的信息,请参阅博客上的 [Anthropic 如何使用 Claude Code 运行大规模代码迁移](https://claude.com/blog/ai-code-migration)。
161 143
162<Steps>144**1. 识别用于重构的遗留代码**
163 <Step title="识别用于重构的遗留代码">145
164 ```text wrap theme={null}146```text wrap theme={null}
165 find deprecated API usage in our codebase147find deprecated API usage in our codebase
166 ```148```
167 </Step>149
168 150**2. 获取重构建议**
169 <Step title="获取重构建议">151
170 ```text wrap theme={null}152```text wrap theme={null}
171 suggest how to refactor utils.js to use modern JavaScript features153suggest how to refactor utils.js to use modern JavaScript features
172 ```154```
173 </Step>155
174 156**3. 安全地应用更改**
175 <Step title="安全地应用更改">157
176 ```text wrap theme={null}158```text wrap theme={null}
177 refactor utils.js to use ES2024 features while maintaining the same behavior159refactor utils.js to use ES2024 features while maintaining the same behavior
178 ```160```
179 </Step>161
180 162**4. 验证重构**
181 <Step title="验证重构">163
182 ```text wrap theme={null}164```text wrap theme={null}
183 run tests for the refactored code165run tests for the refactored code
184 ```166```
185 </Step>167
186</Steps>168> [!TIP]
187 169>
188<Tip>170> 提示:
189 提示:171>
190 172> * 要求 Claude 解释现代方法的优势
191 * 要求 Claude 解释现代方法的优势173> * 在需要时请求更改保持向后兼容性
192 * 在需要时请求更改保持向后兼容性174> * 以小的、可测试的增量进行重构
193 * 以小的、可测试的增量进行重构
194</Tip>
195 175
196***176***
197 177
198<h3 id="work-with-tests">178### 使用测试
199 使用测试
200</h3>
201 179
202假设您需要为未覆盖的代码添加测试。180假设您需要为未覆盖的代码添加测试。
203 181
204<Steps>182**1. 识别未测试的代码**
205 <Step title="识别未测试的代码">183
206 ```text wrap theme={null}184```text wrap theme={null}
207 find functions in NotificationsService.swift that are not covered by tests185find functions in NotificationsService.swift that are not covered by tests
208 ```186```
209 </Step>187
210 188**2. 生成测试脚手架**
211 <Step title="生成测试脚手架">189
212 ```text wrap theme={null}190```text wrap theme={null}
213 add tests for the notification service191add tests for the notification service
214 ```192```
215 </Step>193
216 194**3. 添加有意义的测试用例**
217 <Step title="添加有意义的测试用例">195
218 ```text wrap theme={null}196```text wrap theme={null}
219 add test cases for edge conditions in the notification service197add test cases for edge conditions in the notification service
220 ```198```
221 </Step>199
222 200**4. 运行并验证测试**
223 <Step title="运行并验证测试">201
224 ```text wrap theme={null}202```text wrap theme={null}
225 run the new tests and fix any failures203run the new tests and fix any failures
226 ```204```
227 </Step>
228</Steps>
229 205
230Claude 可以生成遵循您项目现有模式和约定的测试。请求测试时,请明确说明您想验证的行为。Claude 检查您现有的测试文件以匹配已在使用的样式、框架和断言模式。206Claude 可以生成遵循您项目现有模式和约定的测试。请求测试时,请明确说明您想验证的行为。Claude 检查您现有的测试文件以匹配已在使用的样式、框架和断言模式。
231 207
233 209
234***210***
235 211
236<h3 id="create-pull-requests">212### 创建拉取请求
237 创建拉取请求
238</h3>
239 213
240您可以通过直接要求 Claude 创建拉取请求("create a pr for my changes"),或逐步指导 Claude:214您可以通过直接要求 Claude 创建拉取请求("create a pr for my changes"),或逐步指导 Claude:
241 215
242<Steps>216**1. 总结您的更改**
243 <Step title="总结您的更改">217
244 ```text wrap theme={null}218```text wrap theme={null}
245 summarize the changes I've made to the authentication module219summarize the changes I've made to the authentication module
246 ```220```
247 </Step>221
248 222**2. 生成拉取请求**
249 <Step title="生成拉取请求">223
250 ```text wrap theme={null}224```text wrap theme={null}
251 create a pr225create a pr
252 ```226```
253 </Step>227
254 228**3. 审查和细化**
255 <Step title="审查和细化">229
256 ```text wrap theme={null}230```text wrap theme={null}
257 enhance the PR description with more context about the security improvements231enhance the PR description with more context about the security improvements
258 ```232```
259 </Step>
260</Steps>
261 233
262要稍后找到会话,请运行 `claude --from-pr 1234`,将 1234 替换为您自己的 PR 编号,这会打开会话选择器,筛选链接到该 PR 的会话,或将 PR URL 粘贴到 [`/resume` 选择器](/docs/zh-CN/sessions#use-the-session-picker) 搜索中。当 Claude 使用 `gh pr create` 或 `glab mr create` 创建拉取请求时,Claude Code 会将会话链接到 PR,以及当 Claude [处理现有 PR](/docs/zh-CN/agent-view#pull-request-status) 时。234要稍后找到会话,请运行 `claude --from-pr 1234`,将 1234 替换为您自己的 PR 编号,这会打开会话选择器,筛选链接到该 PR 的会话,或将 PR URL 粘贴到 [`/resume` 选择器](/docs/zh-CN/sessions#use-the-session-picker) 搜索中。当 Claude 使用 `gh pr create` 或 `glab mr create` 创建拉取请求时,Claude Code 会将会话链接到 PR,以及当 Claude [处理现有 PR](/docs/zh-CN/agent-view#pull-request-status) 时。
263 235
264<Tip>236> [!TIP]
265 在提交前审查 Claude 生成的 PR,并要求 Claude 突出显示潜在的风险或注意事项。237>
266</Tip>238> 在提交前审查 Claude 生成的 PR,并要求 Claude 突出显示潜在的风险或注意事项。
267 239
268<h3 id="handle-documentation">240### 处理文档
269 处理文档
270</h3>
271 241
272假设您需要为代码添加或更新文档。242假设您需要为代码添加或更新文档。
273 243
274<Steps>244**1. 识别未记录的代码**
275 <Step title="识别未记录的代码">245
276 ```text wrap theme={null}246```text wrap theme={null}
277 find functions without proper JSDoc comments in the auth module247find functions without proper JSDoc comments in the auth module
278 ```248```
279 </Step>249
280 250**2. 生成文档**
281 <Step title="生成文档">251
282 ```text wrap theme={null}252```text wrap theme={null}
283 add JSDoc comments to the undocumented functions in auth.js253add JSDoc comments to the undocumented functions in auth.js
284 ```254```
285 </Step>255
286 256**3. 审查和增强**
287 <Step title="审查和增强">257
288 ```text wrap theme={null}258```text wrap theme={null}
289 improve the generated documentation with more context and examples259improve the generated documentation with more context and examples
290 ```260```
291 </Step>261
292 262**4. 验证文档**
293 <Step title="验证文档">263
294 ```text wrap theme={null}264```text wrap theme={null}
295 check if the documentation follows our project standards265check if the documentation follows our project standards
296 ```266```
297 </Step>267
298</Steps>268> [!TIP]
299 269>
300<Tip>270> 提示:
301 提示:271>
302 272> * 指定您想要的文档样式(JSDoc、docstrings 等)
303 * 指定您想要的文档样式(JSDoc、docstrings 等)273> * 请求文档中的示例
304 * 请求文档中的示例274> * 请求公共 API、接口和复杂逻辑的文档
305 * 请求公共 API、接口和复杂逻辑的文档
306</Tip>
307 275
308***276***
309 277
310<h3 id="work-in-notes-and-non-code-folders">278### 在笔记和非代码文件夹中工作
311 在笔记和非代码文件夹中工作
312</h3>
313 279
314Claude Code 可以在任何目录中工作。在笔记库、文档文件夹或任何 markdown 文件集合中运行它,以搜索、编辑和重新组织内容,就像处理代码一样。280Claude Code 可以在任何目录中工作。在笔记库、文档文件夹或任何 markdown 文件集合中运行它,以搜索、编辑和重新组织内容,就像处理代码一样。
315 281
317 283
318***284***
319 285
320<h3 id="work-with-images">286### 使用图像
321 使用图像
322</h3>
323 287
324假设您需要在代码库中使用图像,并希望 Claude 帮助分析图像内容。288假设您需要在代码库中使用图像,并希望 Claude 帮助分析图像内容。
325 289
326<Steps>290**1. 将图像添加到对话中**
327 <Step title="将图像添加到对话中">291
328 您可以使用以下任何方法:292您可以使用以下任何方法:
329 293
330 1. 将图像拖放到 Claude Code 窗口中2941. 将图像拖放到 Claude Code 窗口中
331 2. 复制图像并使用 `Ctrl+V` 将其粘贴到 CLI 中,或在 [Windows 和 WSL 上使用 `Alt+V`](/docs/zh-CN/interactive-mode#general-controls)2952. 复制图像并使用 `Ctrl+V` 将其粘贴到 CLI 中,或在 [Windows 和 WSL 上使用 `Alt+V`](/docs/zh-CN/interactive-mode#general-controls)
332 3. 向 Claude 提供图像路径,例如"Analyze this image: /path/to/your/image.png"2963. 向 Claude 提供图像路径,例如"Analyze this image: /path/to/your/image.png"
333 </Step>297
334 298**2. 要求 Claude 分析图像**
335 <Step title="要求 Claude 分析图像">299
336 ```text wrap theme={null}300```text wrap theme={null}
337 What does this image show?301What does this image show?
338 ```302```
339 303
340 ```text wrap theme={null}304```text wrap theme={null}
341 Describe the UI elements in this screenshot305Describe the UI elements in this screenshot
342 ```306```
343 307
344 ```text wrap theme={null}308```text wrap theme={null}
345 Are there any problematic elements in this diagram?309Are there any problematic elements in this diagram?
346 ```310```
347 </Step>311
348 312**3. 使用图像获取上下文**
349 <Step title="使用图像获取上下文">313
350 ```text wrap theme={null}314```text wrap theme={null}
351 Here's a screenshot of the error. What's causing it?315Here's a screenshot of the error. What's causing it?
352 ```316```
353 317
354 ```text wrap theme={null}318```text wrap theme={null}
355 This is our current database schema. How should we modify it for the new feature?319This is our current database schema. How should we modify it for the new feature?
356 ```320```
357 </Step>321
358 322**4. 从视觉内容获取代码建议**
359 <Step title="从视觉内容获取代码建议">323
360 ```text wrap theme={null}324```text wrap theme={null}
361 Generate CSS to match this design mockup325Generate CSS to match this design mockup
362 ```326```
363 327
364 ```text wrap theme={null}328```text wrap theme={null}
365 What HTML structure would recreate this component?329What HTML structure would recreate this component?
366 ```330```
367 </Step>331
368</Steps>332> [!TIP]
369 333>
370<Tip>334> 提示:
371 提示:335>
372 336> * 当文本描述不清楚或繁琐时使用图像
373 * 当文本描述不清楚或繁琐时使用图像337> * 包含错误、UI 设计或图表的屏幕截图以获得更好的上下文
374 * 包含错误、UI 设计或图表的屏幕截图以获得更好的上下文338> * 您可以在对话中使用多个图像
375 * 您可以在对话中使用多个图像339> * 图像分析适用于图表、屏幕截图、模型等
376 * 图像分析适用于图表、屏幕截图、模型等340> * 当 Claude 引用图像时(例如,`[Image #1]`),`Cmd+Click`(Mac)或 `Ctrl+Click`(Windows/Linux)链接以在默认查看器中打开图像
377 * 当 Claude 引用图像时(例如,`[Image #1]`),`Cmd+Click`(Mac)或 `Ctrl+Click`(Windows/Linux)链接以在默认查看器中打开图像
378</Tip>
379 341
380***342***
381 343
382<h3 id="reference-files-and-directories">344### 引用文件和目录
383 引用文件和目录
384</h3>
385 345
386使用 @ 快速包含文件或目录,无需等待 Claude 读取它们。346使用 @ 快速包含文件或目录,无需等待 Claude 读取它们。
387 347
388<Steps>348**1. 引用单个文件**
389 <Step title="引用单个文件">
390 ```text wrap theme={null}
391 Explain the logic in @src/utils/auth.js
392 ```
393 349
394 当文件符合 [Read 工具](/docs/zh-CN/tools-reference#read-tool-behavior)的 token 限制(默认为 25,000 个 token)时,这会将文件内容包含在对话中。大于 256KB 的文本文件不会被包含。350```text wrap theme={null}
395 </Step>351Explain the logic in @src/utils/auth.js
352```
353
354当文件符合 [Read 工具](/docs/zh-CN/tools-reference#read-tool-behavior)的 token 限制(默认为 25,000 个 token)时,这会将文件内容包含在对话中。大于 256KB 的文本文件不会被包含。
396 355
397 <Step title="引用目录">356**2. 引用目录**
398 ```text wrap theme={null}357
399 What's the structure of @src/components?358```text wrap theme={null}
400 ```359What's the structure of @src/components?
401 </Step>360```
402 361
403 <Step title="引用 MCP 资源">362**3. 引用 MCP 资源**
404 ```text wrap theme={null}
405 Show me the data from @github:repos/owner/repo/issues
406 ```
407 363
408 这使用 @server:resource 格式从连接的 MCP 服务器获取数据。有关详细信息,请参阅 [MCP 资源](/docs/zh-CN/mcp#use-mcp-resources)。364```text wrap theme={null}
409 </Step>365Show me the data from @github:repos/owner/repo/issues
410</Steps>366```
411 367
412<Tip>368这使用 @server:resource 格式从连接的 MCP 服务器获取数据。有关详细信息,请参阅 [MCP 资源](/docs/zh-CN/mcp#use-mcp-resources)。
413 提示:
414 369
415 * 文件路径可以是相对的或绝对的370> [!TIP]
416 * 键入 `@` 打开路径建议菜单,然后按 Enter 或 Tab 接受突出显示的路径,再按 Enter 发送消息371>
417 * @ 文件引用在文件的目录和父目录中添加 `CLAUDE.md` 到上下文372> 提示:
418 * 目录引用显示文件列表,而不是内容373>
419 * 您可以在单个消息中引用多个文件(例如,"@file1.js and @file2.js")374> * 文件路径可以是相对的或绝对的
420</Tip>375> * 键入 `@` 打开路径建议菜单,然后按 Enter 或 Tab 接受突出显示的路径,再按 Enter 发送消息
376> * @ 文件引用在文件的目录和父目录中添加 `CLAUDE.md` 到上下文
377> * 目录引用显示文件列表,而不是内容
378> * 您可以在单个消息中引用多个文件(例如,"@file1.js and @file2.js")
421 379
422若要阻止 `@` 引用在消息中包含文件内容和目录列表,请在 shell 或用户设置中设置 [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](/docs/zh-CN/env-vars#variables)。随后 Claude 会收到您引用的路径,并附带一条说明,提示它使用其文件工具读取这些路径。该变量需要 Claude Code v2.1.299 或更高版本,并且 Claude Code 会在项目设置和本地设置中忽略它。380若要阻止 `@` 引用在消息中包含文件内容和目录列表,请在 shell 或用户设置中设置 [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](/docs/zh-CN/env-vars#variables)。随后 Claude 会收到您引用的路径,并附带一条说明,提示它使用其文件工具读取这些路径。该变量需要 Claude Code v2.1.299 或更高版本,并且 Claude Code 会在项目设置和本地设置中忽略它。
423 381
424***382***
425 383
426<h3 id="run-claude-on-a-schedule">384### 按计划运行 Claude
427 按计划运行 Claude
428</h3>
429 385
430假设您想让 Claude 自动定期处理任务,如每天早上审查开放的 PR、每周审计依赖项或在夜间检查 CI 失败。386假设您想让 Claude 自动定期处理任务,如每天早上审查开放的 PR、每周审计依赖项或在夜间检查 CI 失败。
431 387
433 389
434| 选项 | 运行位置 | 最适合 |390| 选项 | 运行位置 | 最适合 |
435| :- | :- | :- |391| :- | :- | :- |
436| [Routines](/docs/zh-CN/routines) | 云端,默认由 Anthropic 管理 | 即使您的计算机关闭也应该运行的任务。也可以在 API 调用或 GitHub 事件上触发,除了计划。在 [claude.ai/code/routines](https://claude.ai/code/routines) 配置。 |392| [云端定时任务](/docs/zh-CN/routines) | 云端,默认由 Anthropic 管理 | 即使您的计算机关闭也应该运行的任务。也可以在 API 调用或 GitHub 事件上触发,除了计划。在 [claude.ai/code/routines](https://claude.ai/code/routines) 配置。 |
437| [桌面计划任务](/docs/zh-CN/desktop-scheduled-tasks) | 您的机器,通过桌面应用 | 需要直接访问本地文件、工具或未提交更改的任务。 |393| [桌面计划任务](/docs/zh-CN/desktop-scheduled-tasks) | 您的机器,通过桌面应用 | 需要直接访问本地文件、工具或未提交更改的任务。 |
438| [GitHub Actions](/docs/zh-CN/github-actions) | 您的 CI 管道 | 与存储库事件(如打开的 PR)相关的任务,或应该与工作流配置一起存在的 cron 计划。 |394| [GitHub Actions](/docs/zh-CN/github-actions) | 您的 CI 管道 | 与存储库事件(如打开的 PR)相关的任务,或应该与工作流配置一起存在的 cron 计划。 |
439| [`/loop`](/docs/zh-CN/scheduled-tasks) | 当前 CLI 会话 | 会话打开时的快速轮询。`--resume` 和 `--continue` 恢复未过期的固定间隔循环。 |395| [`/loop`](/docs/zh-CN/scheduled-tasks) | 当前 CLI 会话 | 会话打开时的快速轮询。`--resume` 和 `--continue` 恢复未过期的固定间隔循环。 |
440 396
441<Tip>397> [!TIP]
442 为计划任务编写提示时,明确说明成功是什么样的以及如何处理结果。任务自主运行,所以它不能提出澄清问题。例如:"审查标记为 `needs-review` 的开放 PR,对任何问题留下内联评论,并在 `#eng-reviews` Slack 频道中发布摘要。"398>
443</Tip>399> 为计划任务编写提示时,明确说明成功是什么样的以及如何处理结果。任务自主运行,所以它不能提出澄清问题。例如:"审查标记为 `needs-review` 的开放 PR,对任何问题留下内联评论,并在 `#eng-reviews` Slack 频道中发布摘要。"
444 400
445***401***
446 402
447<h3 id="ask-claude-about-its-capabilities">403### 询问 Claude 关于其功能
448 询问 Claude 关于其功能
449</h3>
450 404
451Claude 可以回答关于其自身功能和限制的问题。它会在最新的 Claude Code 文档中查找答案,因此答案不局限于您正在运行的版本。405Claude 可以回答关于其自身功能和限制的问题。它会在最新的 Claude Code 文档中查找答案,因此答案不局限于您正在运行的版本。
452 406
453<h4 id="example-questions">407#### 示例问题
454 示例问题
455</h4>
456 408
457```text wrap theme={null}409```text wrap theme={null}
458can Claude Code create pull requests?410can Claude Code create pull requests?
478what are the limitations of Claude Code?430what are the limitations of Claude Code?
479```431```
480 432
481<Note>433> [!NOTE]
482 Claude 基于文档提供对这些问题的答案。有关可执行示例和实际演示,请运行 `/powerup` 以获得带有动画演示的交互式课程,或参考上面的特定工作流程部分。434>
483</Note>435> Claude 基于文档提供对这些问题的答案。有关可执行示例和实际演示,请运行 `/powerup` 以获得带有动画演示的交互式课程,或参考上面的特定工作流程部分。
484
485<Tip>
486 提示:
487 436
488 * 提出具体问题以获得详细答案437> [!TIP]
489 * Claude 可以解释复杂的功能,如 MCP 集成、企业配置和高级工作流程438>
490</Tip>439> 提示:
440>
441> * 提出具体问题以获得详细答案
442> * Claude 可以解释复杂的功能,如 MCP 集成、企业配置和高级工作流程
491 443
492***444***
493 445
494<h2 id="resume-previous-conversations">446## 恢复以前的对话
495 恢复以前的对话
496</h2>
497 447
498当任务跨越多个会话时,从您离开的地方继续,而不是重新解释上下文。Claude Code 在本地保存每个对话。448当任务跨越多个会话时,从您离开的地方继续,而不是重新解释上下文。Claude Code 在本地保存每个对话。
499 449
503 453
504这会恢复当前目录中最近的会话;如果还没有,它会打印 `No conversation found to continue` 并退出。使用 `claude --resume` 从列表中选择,或从运行中的会话内使用 `/resume`。有关命名、分支和完整选择器参考,请参阅[管理会话](/docs/zh-CN/sessions)。454这会恢复当前目录中最近的会话;如果还没有,它会打印 `No conversation found to continue` 并退出。使用 `claude --resume` 从列表中选择,或从运行中的会话内使用 `/resume`。有关命名、分支和完整选择器参考,请参阅[管理会话](/docs/zh-CN/sessions)。
505 455
506<h2 id="run-parallel-sessions-with-worktrees">456## 使用 worktrees 运行并行会话
507 使用 worktrees 运行并行会话
508</h2>
509 457
510在一个终端中处理功能,同时 Claude 在另一个终端中修复错误,而不会编辑冲突。每个 [git worktree](https://git-scm.com/docs/git-worktree) 是其自己分支上的单独检出,从现有提交创建,因此存储库首先需要至少一个提交。458在一个终端中处理功能,同时 Claude 在另一个终端中修复错误,而不会编辑冲突。每个 [git worktree](https://git-scm.com/docs/git-worktree) 是其自己分支上的单独检出,从现有提交创建,因此存储库首先需要至少一个提交。
511 459
515 463
516在第二个终端中使用不同的名称运行相同的命令以启动隔离的并行会话。在没有提交的存储库中,该命令失败并显示 `Failed to resolve base branch "HEAD": git rev-parse failed`。有关清理、`.worktreeinclude` 和非 git VCS 支持,请参阅 [Worktrees](/docs/zh-CN/worktrees)。要从一个屏幕而不是单独的终端监视并行会话,请参阅[后台代理](/docs/zh-CN/agent-view)。464在第二个终端中使用不同的名称运行相同的命令以启动隔离的并行会话。在没有提交的存储库中,该命令失败并显示 `Failed to resolve base branch "HEAD": git rev-parse failed`。有关清理、`.worktreeinclude` 和非 git VCS 支持,请参阅 [Worktrees](/docs/zh-CN/worktrees)。要从一个屏幕而不是单独的终端监视并行会话,请参阅[后台代理](/docs/zh-CN/agent-view)。
517 465
518<h2 id="plan-before-editing">466## 编辑前规划
519 编辑前规划
520</h2>
521 467
522对于您想在接触磁盘前审查的更改,切换到 plan mode。Claude 读取文件并提出计划,但在您批准前不进行任何编辑。状态栏在 plan mode 激活时显示 `⏸ plan mode on`。468对于您想在接触磁盘前审查的更改,切换到 plan mode。Claude 读取文件并提出计划,但在您批准前不进行任何编辑。状态栏在 plan mode 激活时显示 `⏸ plan mode on`。
523 469
527 473
528您也可以在会话中按 `Shift+Tab` 直到状态栏显示 `⏸ plan mode on` 来切换到 plan mode。有关批准流程和在文本编辑器中编辑计划,请参阅 [Plan mode](/docs/zh-CN/permission-modes#analyze-before-you-edit-with-plan-mode)。474您也可以在会话中按 `Shift+Tab` 直到状态栏显示 `⏸ plan mode on` 来切换到 plan mode。有关批准流程和在文本编辑器中编辑计划,请参阅 [Plan mode](/docs/zh-CN/permission-modes#analyze-before-you-edit-with-plan-mode)。
529 475
530<h2 id="delegate-research-to-subagents">476## 将研究委派给 subagents
531 将研究委派给 subagents
532</h2>
533 477
534探索大型代码库会用文件读取填充您的上下文。委派探索,以便只有发现结果返回。478探索大型代码库会用文件读取填充您的上下文。委派探索,以便只有发现结果返回。
535 479
539 483
540subagent 在其自己的上下文窗口中读取文件并报告摘要。有关定义具有自己工具和提示的自定义代理,请参阅 [Subagents](/docs/zh-CN/sub-agents)。484subagent 在其自己的上下文窗口中读取文件并报告摘要。有关定义具有自己工具和提示的自定义代理,请参阅 [Subagents](/docs/zh-CN/sub-agents)。
541 485
542<h2 id="pipe-claude-into-scripts">486## 将 Claude 管道输入脚本
543 将 Claude 管道输入脚本
544</h2>
545 487
546以非交互方式运行 Claude 用于 CI、预提交钩子或批处理。stdin 和 stdout 像任何 Unix 工具一样工作。488以非交互方式运行 Claude 用于 CI、预提交钩子或批处理。stdin 和 stdout 像任何 Unix 工具一样工作。
547 489
551 493
552有关输出格式、权限标志和扇出模式,请参阅[非交互模式](/docs/zh-CN/headless)。494有关输出格式、权限标志和扇出模式,请参阅[非交互模式](/docs/zh-CN/headless)。
553 495
554<h2 id="next-steps">496## 后续步骤
555 后续步骤
556</h2>
557 497
558<CardGroup cols={2}>498> **[最佳实践](/docs/zh-CN/best-practices)**
559 <Card title="最佳实践" icon="lightbulb" href="/docs/zh-CN/best-practices">499>
560 充分利用 Claude Code 的模式500> 充分利用 Claude Code 的模式
561 </Card>
562 501
563 <Card title="管理会话" icon="rotate-left" href="/docs/zh-CN/sessions">502> **[管理会话](/docs/zh-CN/sessions)**
564 恢复、命名和分支对话503>
565 </Card>504> 恢复、命名和分支对话
566 505
567 <Card title="Worktrees" icon="code-branch" href="/docs/zh-CN/worktrees">506> **[Worktrees](/docs/zh-CN/worktrees)**
568 运行隔离的并行会话507>
569 </Card>508> 运行隔离的并行会话
570 509
571 <Card title="扩展 Claude Code" icon="puzzle-piece" href="/docs/zh-CN/features-overview">510> **[扩展 Claude Code](/docs/zh-CN/features-overview)**
572 添加 skills、hooks、MCP、subagents 和插件511>
573 </Card>512> 添加 skills、hooks、MCP、subagents 和插件
574</CardGroup>