All guides
Claude Code

快速入门

Checked 09/14/2026View original

AI translation, not an official translation. Refer to the original for technical details.

On this page

文档索引

获取完整文档索引,请访问:https://code.claude.com/docs/llms.txt 在进一步探索之前,使用此文件发现所有可用页面。

快速入门

欢迎使用 Claude Code!

本快速入门指南将帮助您在几分钟内开始使用 AI 驱动的编程辅助工具。完成后,您将了解如何使用 Claude Code 完成常见的开发任务。

开始之前

请确保您已具备:

第一步:安装 Claude Code

要安装 Claude Code,请使用以下方法之一:

```bash theme={null}
curl -fsSL https://claude.ai/install.sh | bash
```

**Windows PowerShell:**

```powershell theme={null}
irm https://claude.ai/install.ps1 | iex
```

**Windows CMD:**

```batch theme={null}
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
```

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.

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.

[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.

<Info>
  Native installations automatically update in the background to keep you on the latest version.
</Info>
Homebrew offers two casks. `claude-code` tracks the stable release channel, which is typically about a week behind and skips releases with major regressions. `claude-code@latest` tracks the latest channel and receives new versions as soon as they ship.

<Info>
  Homebrew installations do not auto-update. Run `brew upgrade claude-code` or `brew upgrade claude-code@latest`, depending on which cask you installed, to get the latest features and security fixes.
</Info>
<Info>
  WinGet installations do not auto-update. Run `winget upgrade Anthropic.ClaudeCode` periodically to get the latest features and security fixes.
</Info>

您也可以在 Debian、Fedora、RHEL 和 Alpine 上使用 apt、dnf 或 apk 进行安装。

要确认安装是否成功,请运行:

claude --version

该命令会打印版本号,后跟 (Claude Code)

第二步:登录您的账户

使用 Claude Code 需要一个账户。使用 claude 命令启动交互式会话,首次使用时系统会提示您登录:

claude

对于 Claude 订阅或 Console 账户,请按照提示在浏览器中完成身份验证。如果您已设置 ANTHROPIC_API_KEY 环境变量,Claude Code 将跳过登录提示,转而要求您批准密钥。如需稍后切换账户或重新进行身份验证,请在运行中的会话内输入 /login

/login

您可以使用以下任一账户类型登录:

登录后,您的凭据将被保存,无需再次登录。了解更多信息,请参阅凭据管理

第三步:开始您的第一个会话

在任意项目目录中打开终端并启动 Claude Code:

cd /path/to/your/project
claude

/path/to/your/project 替换为您要使用的项目路径。

您将看到 Claude Code 的提示符,其上方显示版本号、当前模型和工作目录。输入 /help 查看可用命令,或输入 /resume 继续上次的对话。

第四步:提出您的第一个问题

让我们从了解您的代码库开始。尝试以下命令之一:

what does this project do?

Claude 将分析您的文件并提供摘要。您也可以提出更具体的问题:

what technologies does this project use?
where is the main entry point?
explain the folder structure

您还可以询问 Claude 关于其自身功能的问题:

what can Claude Code do?
how do I create custom skills in Claude Code?
can Claude Code work with Docker?

第五步:进行您的第一次代码更改

现在让我们让 Claude Code 实际编写代码。尝试一个简单的任务:

add a hello world function to the main file

Claude Code 会找到合适的文件并向您展示更改内容。如果它在进行更改前询问您,请选择以批准。

自动模式是 Pro、Max 和 Team 计划交互式终端会话的内置起始权限模式:分类器会代替您审查操作,Claude 可以在不询问您的情况下编辑大多数文件并运行大多数命令。在其他计划中,手动模式是内置的起始权限模式。关于安装或升级后启动的第一个会话,请参阅安装或升级后的首次会话

第六步:在 Claude Code 中使用 Git

Claude Code 让 Git 操作变得像对话一样自然:

what files have I changed?
commit my changes with a descriptive message

您也可以提示执行更复杂的 Git 操作:

create a new branch called feature/quickstart
show me the last 5 commits
help me resolve merge conflicts

第七步:修复 Bug 或添加功能

Claude 擅长调试和功能实现。

用自然语言描述您的需求:

add input validation to the user registration form

或修复现有问题:

there's a bug where users can submit empty forms - fix it

Claude Code 将会:

  • 定位相关代码
  • 理解上下文
  • 实现解决方案
  • 如有可用测试则运行测试

第八步:尝试其他常见工作流程

与 Claude 协作的方式有很多种:

重构代码

refactor the authentication module to use async/await instead of callbacks

编写测试

write unit tests for the calculator functions

更新文档

update the README with installation instructions

代码审查

review my changes and suggest improvements

常用命令

以下是日常使用中最重要的命令。Shell 命令在您的终端中运行,用于启动或恢复 Claude Code。会话命令在 Claude Code 启动后于其内部运行。

Shell 命令

命令功能示例
claude启动交互模式claude
claude "task"以初始提示词启动交互模式claude "fix the build error"
claude -p "query"执行单次查询后退出claude -p "explain this function"
claude -c在当前目录中继续最近的对话claude -c
claude -r恢复之前的对话claude -r

会话命令

命令功能示例
/clear清除对话历史/clear
/help显示可用命令/help
/exit 或连按两次 Ctrl+D退出 Claude Code/exit

请参阅 CLI 参考 获取完整的 shell 命令列表,以及 命令参考 获取完整的会话命令列表。

初学者专业技巧

更多内容请参阅 最佳实践常见工作流

Try: "fix the login bug where users see a blank screen after entering wrong credentials"
```text wrap theme={null}
1. create a new database table for user profiles
2. create an API endpoint to get and update user profiles
3. build a webpage that allows users to see and edit their information
```
```text wrap theme={null}
analyze the database schema
```

```text wrap theme={null}
build a dashboard showing products that are most frequently returned by our UK customers
```

下一步是什么?

在您学习了基础知识之后,探索更多高级功能:

获取帮助

  • 在 Claude Code 中:输入 /help 或询问"如何..."
  • 文档:您已经在这里了!浏览其他指南
  • 社区:加入我们的 Discord 获取技巧和支持