9本快速开始指南将在几分钟内让您使用 AI 驱动的编码辅助。完成本指南后,您将了解如何使用 Claude Code 完成常见的开发任务。9本快速开始指南将在几分钟内让您使用 AI 驱动的编码辅助。完成本指南后,您将了解如何使用 Claude Code 完成常见的开发任务。
10 10
11<Note>11<Note>
12 默认配置下,Claude Code 需要能够访问 claude.ai 和 Anthropic API 等端点才能完成安装、登录和正常使用。在中国大陆的网络环境中,这些端点可能无法直接访问。开始前,请先确认所在网络能够连通这些服务。企业代理配置以及 Amazon Bedrock 等第三方提供商的网络要求,请参阅[网络配置](/zh-CN/network-config#network-access-requirements)。12 默认配置下,Claude Code 需要能够访问 claude.ai 和 Anthropic API 等端点才能完成安装、登录和正常使用。在中国大陆的网络环境中,这些端点可能无法直接访问。开始前,请先确认所在网络能够连通这些服务。企业代理配置以及 Amazon Bedrock 等第三方提供商的网络要求,请参阅[网络配置](/docs/zh-CN/network-config#network-access-requirements)。
13</Note>13</Note>
14 14
15<h2 id="before-you-begin">15<h2 id="before-you-begin">
19确保您拥有:19确保您拥有:
20 20
21* 打开的终端或命令提示符21* 打开的终端或命令提示符
22 * 如果您之前从未使用过终端,请查看[终端指南](/zh-CN/terminal-guide)22 * 如果您之前从未使用过终端,请查看[终端指南](/docs/zh-CN/terminal-guide)
23* 一个可以使用的代码项目23* 一个可以使用的代码项目
24* 一个 [Claude 订阅](https://claude.com/pricing?utm_source=claude_code\&utm_medium=docs\&utm_content=quickstart_prereq)(Pro、Max、Team 或 Enterprise)、[Claude Console](https://console.anthropic.com/) 账户,或通过[支持的云提供商](/zh-CN/third-party-integrations)的访问权限24* 一个 [Claude 订阅](https://claude.com/pricing?utm_source=claude_code\&utm_medium=docs\&utm_content=quickstart_prereq)(Pro、Max、Team 或 Enterprise)、[Claude Console](https://platform.claude.com/) 账户,或通过[支持的云提供商](/docs/zh-CN/third-party-integrations)的访问权限
25 25
26<Note>26<Note>
27 本指南涵盖终端 CLI。Claude Code 也可在[网页](https://claude.ai/code)、[桌面应用](/zh-CN/desktop)、[VS Code](/zh-CN/vs-code) 和 [JetBrains IDE](/zh-CN/jetbrains)、[Slack](/zh-CN/slack) 中使用,以及通过 [GitHub Actions](/zh-CN/github-actions) 和 [GitLab](/zh-CN/gitlab-ci-cd) 进行 CI/CD。查看[所有界面](/zh-CN/overview#use-claude-code-everywhere)。27 本指南涵盖终端 CLI。Claude Code 也可在[网页](https://claude.ai/code)、[桌面应用](/docs/zh-CN/desktop)、[VS Code](/docs/zh-CN/vs-code) 和 [JetBrains IDE](/docs/zh-CN/jetbrains)、[Slack](/docs/zh-CN/slack) 中使用,以及通过 [GitHub Actions](/docs/zh-CN/github-actions) 和 [GitLab](/docs/zh-CN/gitlab-ci-cd) 进行 CI/CD。查看[所有界面](/docs/zh-CN/overview#use-claude-code-everywhere)。
28</Note>28</Note>
29 29
30<h2 id="step-1-install-claude-code">30<h2 id="step-1-install-claude-code">
55 55
56 If you see `The token '&&' is not a valid statement separator`, you're in PowerShell, not CMD. If you see `'irm' is not recognized as an internal or external command`, you're in CMD, not PowerShell. Your prompt shows `PS C:\` when you're in PowerShell and `C:\` without the `PS` when you're in CMD.56 If you see `The token '&&' is not a valid statement separator`, you're in PowerShell, not CMD. If you see `'irm' is not recognized as an internal or external command`, you're in CMD, not PowerShell. Your prompt shows `PS C:\` when you're in PowerShell and `C:\` without the `PS` when you're in CMD.
57 57
58 If the install command fails with `syntax error near unexpected token '<'`, a `403`, or another curl error, see [Troubleshoot installation](/en/troubleshoot-install#find-your-error) to match the error to a fix and for alternative install methods.58 If the install command fails with `syntax error near unexpected token '<'`, a `403`, or another curl error, see [Troubleshoot installation](/docs/en/troubleshoot-install#find-your-error) to match the error to a fix and for alternative install methods.
59 59
60 [Git for Windows](https://git-scm.com/downloads/win) is recommended on native Windows so Claude Code can use the Bash tool. If Git for Windows is not installed, Claude Code uses PowerShell as the shell tool instead. WSL setups do not need Git for Windows.60 [Git for Windows](https://git-scm.com/downloads/win) is recommended on native Windows so Claude Code can use the Bash tool. If Git for Windows is not installed, Claude Code uses PowerShell as the shell tool instead. WSL setups do not need Git for Windows.
61 61
87 </Tab>87 </Tab>
88</Tabs>88</Tabs>
89 89
90You can also install with [apt, dnf, or apk](/en/setup#install-with-linux-package-managers) on Debian, Fedora, RHEL, and Alpine.90You can also install with [apt, dnf, or apk](/docs/en/setup#install-with-linux-package-managers) on Debian, Fedora, RHEL, and Alpine.
91
92要确认安装成功,请运行:
93
94```bash theme={null}
95claude --version
96```
97
98该命令会打印一个版本号,后面跟着 `(Claude Code)`。
91 99
92<h2 id="step-2-log-in-to-your-account">100<h2 id="step-2-log-in-to-your-account">
93 步骤 2:登录您的账户101 步骤 2:登录您的账户
99claude107claude
100```108```
101 109
102对于 Claude 订阅或 Console 账户,请按照提示在浏览器中完成身份验证。要稍后切换账户或重新身份验证,请在运行的会话中输入 `/login`:110对于 Claude 订阅或 Console 账户,请按照提示在浏览器中完成身份验证。如果您已设置 `ANTHROPIC_API_KEY` 环境变量,Claude Code 会跳过登录提示,改为要求您批准该密钥。要稍后切换账户或重新身份验证,请在运行的会话中输入 `/login`:
103 111
104```text theme={null}112```text wrap theme={null}
105/login113/login
106```114```
107 115
108您可以使用以下任何账户类型登录:116您可以使用以下任何账户类型登录:
109 117
110* [Claude Pro、Max、Team 或 Enterprise](https://claude.com/pricing?utm_source=claude_code\&utm_medium=docs\&utm_content=quickstart_login)(推荐)118* [Claude Pro、Max、Team 或 Enterprise](https://claude.com/pricing?utm_source=claude_code\&utm_medium=docs\&utm_content=quickstart_login)(推荐)
111* [Claude Console](https://console.anthropic.com/)(具有预付费额度的 API 访问)。首次登录时,Console 中会自动为集中成本跟踪创建一个"Claude Code"工作区。119* [Claude Console](https://platform.claude.com/)(具有预付费额度的 API 访问)。首次登录时,Console 中会自动为集中成本跟踪创建一个"Claude Code"工作区。
112* [Amazon Bedrock、Google Cloud 的 Agent Platform 或 Microsoft Foundry](/zh-CN/third-party-integrations)(企业云提供商)120* [Amazon Bedrock、Google Cloud 的 Agent Platform 或 Microsoft Foundry](/docs/zh-CN/third-party-integrations)(企业云提供商)
113* 自托管的 [Claude apps gateway](/zh-CN/claude-apps-gateway)(如果您的组织运行一个):您的管理员会预先配置网关 URL,`/login` 会直接在 **Cloud gateway** 屏幕上打开,供您使用企业 SSO 登录121* 自托管的 [Claude apps gateway](/docs/zh-CN/claude-apps-gateway)(如果您的组织运行一个):您的管理员会预先配置网关 URL,`/login` 会直接在 **Cloud gateway** 屏幕上打开,供您使用企业 SSO 登录
114 122
115登录后,您的凭证将被存储,您无需再次登录。123登录后,您的凭证将被存储,您无需再次登录。详细了解 [凭证管理](/docs/zh-CN/authentication#credential-management)。
116 124
117<h2 id="step-3-start-your-first-session">125<h2 id="step-3-start-your-first-session">
118 步骤 3:启动您的第一个会话126 步骤 3:启动您的第一个会话
125claude133claude
126```134```
127 135
128您将看到 Claude Code 提示符,其中显示版本、当前模型和上方显示的工作目录。输入 `/help` 查看可用命令,或输入 `/resume` 继续之前的对话。136将 `/path/to/your/project` 替换为您要处理的项目的路径。
129 137
130<Tip>138您将看到 Claude Code 提示符,其中显示版本、当前模型和上方显示的工作目录。输入 `/help` 查看可用命令,或输入 `/resume` 继续之前的对话。
131 登录后(步骤 2),您的凭证将存储在您的系统上。在[凭证管理](/zh-CN/authentication#credential-management)中了解更多信息。
132</Tip>
133 139
134<h2 id="step-4-ask-your-first-question">140<h2 id="step-4-ask-your-first-question">
135 步骤 4:提出您的第一个问题141 步骤 4:提出您的第一个问题
137 143
138让我们从理解您的代码库开始。尝试以下命令之一:144让我们从理解您的代码库开始。尝试以下命令之一:
139 145
140```text theme={null}146```text wrap theme={null}
141what does this project do?147what does this project do?
142```148```
143 149
144Claude 将分析您的文件并提供摘要。您也可以提出更具体的问题:150Claude 将分析您的文件并提供摘要。您也可以提出更具体的问题:
145 151
146```text theme={null}152```text wrap theme={null}
147what technologies does this project use?153what technologies does this project use?
148```154```
149 155
150```text theme={null}156```text wrap theme={null}
151where is the main entry point?157where is the main entry point?
152```158```
153 159
154```text theme={null}160```text wrap theme={null}
155explain the folder structure161explain the folder structure
156```162```
157 163
158您也可以询问 Claude 关于其自身功能的问题:164您也可以询问 Claude 关于其自身功能的问题:
159 165
160```text theme={null}166```text wrap theme={null}
161what can Claude Code do?167what can Claude Code do?
162```168```
163 169
164```text theme={null}170```text wrap theme={null}
165how do I create custom skills in Claude Code?171how do I create custom skills in Claude Code?
166```172```
167 173
168```text theme={null}174```text wrap theme={null}
169can Claude Code work with Docker?175can Claude Code work with Docker?
170```176```
171 177
179 185
180现在让我们让 Claude Code 进行一些实际的编码。尝试一个简单的任务:186现在让我们让 Claude Code 进行一些实际的编码。尝试一个简单的任务:
181 187
182```text theme={null}188```text wrap theme={null}
183在主文件中添加一个 hello world 函数189在主文件中添加一个 hello world 函数
184```190```
185 191
186Claude Code 将:192Claude Code 找到适当的文件并向您显示更改。如果它在进行更改前询问,请选择**是**以批准。
187 193
1881. 找到适当的文件194Auto 模式是 Pro、Max 和 Team 计划上交互式终端会话的[内置起始权限模式](/docs/zh-CN/permission-modes#eliminate-prompts-with-auto-mode):分类器审查操作而不是您,Claude 在不询问的情况下编辑大多数文件并运行大多数命令。在其他计划上,Manual 模式是内置起始权限模式。对于安装后立即启动的会话,请参阅[安装或升级后的首个会话](/docs/zh-CN/env-vars#first-session-after-an-install-or-upgrade)。
1892. 向您显示建议的更改
1903. 请求您的批准
1914. 进行编辑
192 195
193<Note>196<Note>
194 Claude Code 在修改文件前始终请求许可。您可以批准单个更改或为会话启用"全部接受"模式。197 您的设置或您的组织可以设置不同的起始权限模式。[会话启动时的权限模式](/docs/zh-CN/permission-modes#which-mode-a-session-starts-in)列出了相关内容。随时按 `Shift+Tab` 切换您所在会话的权限模式。
195</Note>198</Note>
196 199
197<h2 id="step-6-use-git-with-claude-code">200<h2 id="step-6-use-git-with-claude-code">
200 203
201Claude Code 使 Git 操作变得对话式:204Claude Code 使 Git 操作变得对话式:
202 205
203```text theme={null}206```text wrap theme={null}
204我更改了哪些文件?207我更改了哪些文件?
205```208```
206 209
207```text theme={null}210```text wrap theme={null}
208用描述性消息提交我的更改211用描述性消息提交我的更改
209```212```
210 213
211您也可以提示更复杂的 Git 操作:214您也可以提示更复杂的 Git 操作:
212 215
213```text theme={null}216```text wrap theme={null}
214创建一个名为 feature/quickstart 的新分支217创建一个名为 feature/quickstart 的新分支
215```218```
216 219
217```text theme={null}220```text wrap theme={null}
218显示我最后的 5 次提交221显示我最后的 5 次提交
219```222```
220 223
221```text theme={null}224```text wrap theme={null}
222帮我解决合并冲突225帮我解决合并冲突
223```226```
224 227
230 233
231用自然语言描述您想要的内容:234用自然语言描述您想要的内容:
232 235
233```text theme={null}236```text wrap theme={null}
234向用户注册表单添加输入验证237向用户注册表单添加输入验证
235```238```
236 239
237或修复现有问题:240或修复现有问题:
238 241
239```text theme={null}242```text wrap theme={null}
240有一个错误,用户可以提交空表单 - 修复它243有一个错误,用户可以提交空表单 - 修复它
241```244```
242 245
255 258
256**重构代码**259**重构代码**
257 260
258```text theme={null}261```text wrap theme={null}
259refactor the authentication module to use async/await instead of callbacks262refactor the authentication module to use async/await instead of callbacks
260```263```
261 264
262**编写测试**265**编写测试**
263 266
264```text theme={null}267```text wrap theme={null}
265write unit tests for the calculator functions268write unit tests for the calculator functions
266```269```
267 270
268**更新文档**271**更新文档**
269 272
270```text theme={null}273```text wrap theme={null}
271update the README with installation instructions274update the README with installation instructions
272```275```
273 276
274**代码审查**277**代码审查**
275 278
276```text theme={null}279```text wrap theme={null}
277review my changes and suggest improvements280review my changes and suggest improvements
278```281```
279 282
292| 命令 | 功能 | 示例 |295| 命令 | 功能 | 示例 |
293| ------------------- | ------------- | ----------------------------------- |296| ------------------- | ------------- | ----------------------------------- |
294| `claude` | 启动交互模式 | `claude` |297| `claude` | 启动交互模式 | `claude` |
295| `claude "task"` | 运行一次性任务 | `claude "fix the build error"` |298| `claude "task"` | 使用初始提示启动交互模式 | `claude "fix the build error"` |
296| `claude -p "query"` | 运行一次性查询,然后退出 | `claude -p "explain this function"` |299| `claude -p "query"` | 运行一次性查询,然后退出 | `claude -p "explain this function"` |
297| `claude -c` | 在当前目录中继续最近的对话 | `claude -c` |300| `claude -c` | 在当前目录中继续最近的对话 | `claude -c` |
298| `claude -r` | 恢复之前的对话 | `claude -r` |301| `claude -r` | 恢复之前的对话 | `claude -r` |
300**会话命令**303**会话命令**
301 304
302| 命令 | 功能 | 示例 |305| 命令 | 功能 | 示例 |
303| ---------------- | -------------- | -------- |306| ------------------- | -------------- | -------- |
304| `/clear` | 清除对话历史 | `/clear` |307| `/clear` | 清除对话历史 | `/clear` |
305| `/help` | 显示可用命令 | `/help` |308| `/help` | 显示可用命令 | `/help` |
306| `/exit` 或 Ctrl+D | 退出 Claude Code | `/exit` |309| `/exit` 或 Ctrl+D 两次 | 退出 Claude Code | `/exit` |
307 310
308有关完整的 shell 命令列表,请参阅 [CLI 参考](/zh-CN/cli-reference),有关完整的会话命令列表,请参阅 [命令参考](/zh-CN/commands)。311有关完整的 shell 命令列表,请参阅 [CLI 参考](/docs/zh-CN/cli-reference),有关完整的会话命令列表,请参阅 [命令参考](/docs/zh-CN/commands)。
309 312
310<h2 id="pro-tips-for-beginners">313<h2 id="pro-tips-for-beginners">
311 初学者专业提示314 初学者专业提示
312</h2>315</h2>
313 316
314有关更多信息,请参阅[最佳实践](/zh-CN/best-practices)和[常见工作流](/zh-CN/common-workflows)。317有关更多信息,请参阅[最佳实践](/docs/zh-CN/best-practices)和[常见工作流](/docs/zh-CN/common-workflows)。
315 318
316<AccordionGroup>319<AccordionGroup>
317 <Accordion title="对您的请求要具体">320 <Accordion title="对您的请求要具体">
323 <Accordion title="使用分步说明">326 <Accordion title="使用分步说明">
324 将复杂任务分解为步骤:327 将复杂任务分解为步骤:
325 328
326 ```text theme={null}329 ```text wrap theme={null}
327 1. 为用户配置文件创建新的数据库表330 1. 为用户配置文件创建新的数据库表
328 2. 创建 API 端点以获取和更新用户配置文件331 2. 创建 API 端点以获取和更新用户配置文件
329 3. 构建允许用户查看和编辑其信息的网页332 3. 构建允许用户查看和编辑其信息的网页
333 <Accordion title="让 Claude 先探索">336 <Accordion title="让 Claude 先探索">
334 在进行更改之前,让 Claude 理解您的代码:337 在进行更改之前,让 Claude 理解您的代码:
335 338
336 ```text theme={null}339 ```text wrap theme={null}
337 分析数据库架构340 分析数据库架构
338 ```341 ```
339 342
340 ```text theme={null}343 ```text wrap theme={null}
341 构建一个仪表板,显示英国客户最常退货的产品344 构建一个仪表板,显示英国客户最常退货的产品
342 ```345 ```
343 </Accordion>346 </Accordion>
357现在您已经学习了基础知识,探索更多高级功能:360现在您已经学习了基础知识,探索更多高级功能:
358 361
359<CardGroup cols={2}>362<CardGroup cols={2}>
360 <Card title="Claude Code 如何工作" icon="microchip" href="/zh-CN/how-claude-code-works">363 <Card title="Claude Code 如何工作" icon="microchip" href="/docs/zh-CN/how-claude-code-works">
361 了解代理循环、内置工具以及 Claude Code 如何与您的项目交互364 了解代理循环、内置工具以及 Claude Code 如何与您的项目交互
362 </Card>365 </Card>
363 366
364 <Card title="最佳实践" icon="star" href="/zh-CN/best-practices">367 <Card title="最佳实践" icon="star" href="/docs/zh-CN/best-practices">
365 通过有效的提示和项目设置获得更好的结果368 通过有效的提示和项目设置获得更好的结果
366 </Card>369 </Card>
367 370
368 <Card title="常见工作流" icon="graduation-cap" href="/zh-CN/common-workflows">371 <Card title="常见工作流" icon="graduation-cap" href="/docs/zh-CN/common-workflows">
369 常见任务的分步指南372 常见任务的分步指南
370 </Card>373 </Card>
371 374
372 <Card title="扩展 Claude Code" icon="puzzle-piece" href="/zh-CN/features-overview">375 <Card title="扩展 Claude Code" icon="puzzle-piece" href="/docs/zh-CN/features-overview">
373 使用 CLAUDE.md、skills、hooks、MCP 等进行自定义376 使用 CLAUDE.md、skills、hooks、MCP 等进行自定义
374 </Card>377 </Card>
375</CardGroup>378</CardGroup>