{/* TRANSLATED — 已翻译为中文 */}

> ## 文档索引
> 在此获取完整文档索引：https://code.claude.com/docs/llms.txt
> 使用此文件发现所有可用页面，然后再进一步探索。

# 快速入门

> 欢迎使用 Claude Code！

本快速入门指南将在几分钟内让你开始使用 AI 驱动的编码辅助。完成后，你将了解如何使用 Claude Code 处理常见的开发任务。

## 开始之前

请确保你拥有：

* 已打开终端或命令提示符
  * 如果你从未使用过终端，请查看[终端指南](/en/terminal-guide)
* 一个代码项目可供使用
* [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/) 账户，或通过[支持的云提供商](/en/third-party-integrations)访问

<Note>
  本指南涵盖终端 CLI。Claude Code 还可在 [Web](https://claude.ai/code)、[桌面应用](/en/desktop)、[VS Code](/en/vs-code) 和 [JetBrains IDE](/en/jetbrains)、[Slack](/en/slack) 中使用，以及通过 [GitHub Actions](/en/github-actions) 和 [GitLab](/en/gitlab-ci-cd) 在 CI/CD 中使用。查看[所有接口](/en/overview#use-claude-code-everywhere)。
</Note>

## 步骤 1：安装 Claude Code

要安装 Claude Code，请使用以下方法之一：

<Tabs>
  <Tab title="原生安装（推荐）">
    **macOS、Linux、WSL：**

    ```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
    ```

    如果你看到 `The token '&&' is not a valid statement separator`，说明你在 PowerShell 中而不是 CMD。如果你看到 `'irm' is not recognized as an internal or external command`，说明你在 CMD 中而不是 PowerShell。在 PowerShell 中你的提示符显示 `PS C:\`，在 CMD 中显示 `C:\`（没有 `PS`）。

    建议在原生 Windows 上安装 [Git for Windows](https://git-scm.com/downloads/win)，以便 Claude Code 可以使用 Bash 工具。如果未安装 Git for Windows，Claude Code 将改用 PowerShell 作为 shell 工具。WSL 环境不需要 Git for Windows。

    <Info>
      原生安装会自动在后台更新，确保你始终使用最新版本。
    </Info>
  </Tab>

  <Tab title="Homebrew">
    ```bash theme={null}
    brew install --cask claude-code
    ```

    Homebrew 提供两个 cask。`claude-code` 跟踪稳定发布通道，通常落后约一周，并跳过存在重大回归的版本。`claude-code@latest` 跟踪最新通道，新版本发布后立即接收。

    <Info>
      Homebrew 安装不会自动更新。根据你安装的 cask，运行 `brew upgrade claude-code` 或 `brew upgrade claude-code@latest` 以获取最新功能和安全修复。
    </Info>
  </Tab>

  <Tab title="WinGet">
    ```powershell theme={null}
    winget install Anthropic.ClaudeCode
    ```

    <Info>
      WinGet 安装不会自动更新。定期运行 `winget upgrade Anthropic.ClaudeCode` 以获取最新功能和安全修复。
    </Info>
  </Tab>
</Tabs>

你也可以在 Debian、Fedora、RHEL 和 Alpine 上使用 [apt、dnf 或 apk](/en/setup#install-with-linux-package-managers) 进行安装。

## 步骤 2：登录账户

Claude Code 需要账户才能使用。使用 `claude` 命令启动交互式会话，首次使用时系统会提示你登录：

```bash theme={null}
claude
```

对于 Claude 订阅或 Console 账户，请按照提示在浏览器中完成认证。要稍后切换账户或重新认证，请在运行中的会话内输入 `/login`：

```text theme={null}
/login
```

你可以使用以下任何账户类型登录：

* [Claude Pro、Max、Team 或 Enterprise](https://claude.com/pricing?utm_source=claude_code\&utm_medium=docs\&utm_content=quickstart_login)（推荐）
* [Claude Console](https://console.anthropic.com/)（使用预付费额度的 API 访问）。首次登录时，Console 中会自动创建一个 "Claude Code" 工作区用于集中成本跟踪。
* [Amazon Bedrock、Google Vertex AI 或 Microsoft Foundry](/en/third-party-integrations)（企业云提供商）

登录后，你的凭据将被存储，无需再次登录。

## 步骤 3：启动你的第一个会话

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

```bash theme={null}
cd /path/to/your/project
claude
```

你将看到 Claude Code 欢迎界面，其中包含你的会话信息、最近对话和最新更新。输入 `/help` 查看可用命令，或输入 `/resume` 继续之前的对话。

<Tip>
  登录后（步骤 2），你的凭据将存储在系统上。了解更多请参阅[凭据管理](/en/authentication#credential-management)。
</Tip>

## 步骤 4：提出你的第一个问题

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

```text theme={null}
what does this project do?
```

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

```text theme={null}
what technologies does this project use?
```

```text theme={null}
where is the main entry point?
```

```text theme={null}
explain the folder structure
```

你也可以询问 Claude 关于其自身能力的问题：

```text theme={null}
what can Claude Code do?
```

```text theme={null}
how do I create custom skills in Claude Code?
```

```text theme={null}
can Claude Code work with Docker?
```

<Note>
  Claude Code 会根据需要读取你的项目文件。你无需手动添加上下文。
</Note>

## 步骤 5：进行你的第一次代码更改

现在让我们让 Claude Code 做一些实际的编码工作。尝试一个简单任务：

```text theme={null}
add a hello world function to the main file
```

Claude Code 将：

1. 找到合适的文件
2. 向你展示拟议的更改
3. 请求你的批准
4. 进行编辑

<Note>
  Claude Code 在修改文件前始终会请求权限。你可以批准单个更改，或为会话启用"全部接受"模式。
</Note>

## 步骤 6：在 Claude Code 中使用 Git

Claude Code 让 Git 操作变得对话式：

```text theme={null}
what files have I changed?
```

```text theme={null}
commit my changes with a descriptive message
```

你也可以提示更复杂的 Git 操作：

```text theme={null}
create a new branch called feature/quickstart
```

```text theme={null}
show me the last 5 commits
```

```text theme={null}
help me resolve merge conflicts
```

## 步骤 7：修复错误或添加功能

Claude 擅长调试和功能实现。

用自然语言描述你想要的内容：

```text theme={null}
add input validation to the user registration form
```

或修复现有问题：

```text theme={null}
there's a bug where users can submit empty forms - fix it
```

Claude Code 将：

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

## 步骤 8：试用其他常见工作流

有多种与 Claude 协作的方式：

**重构代码**

```text theme={null}
refactor the authentication module to use async/await instead of callbacks
```

**编写测试**

```text theme={null}
write unit tests for the calculator functions
```

**更新文档**

```text theme={null}
update the README with installation instructions
```

**代码审查**

```text theme={null}
review my changes and suggest improvements
```

<Tip>
  像与乐于助人的同事交谈一样与 Claude 对话。描述你想要实现的目标，它会帮助你达成。
</Tip>

## 常用命令

以下是日常使用中最重要的命令：

| 命令                | 功能                                             | 示例                                |
| ------------------- | ------------------------------------------------ | ----------------------------------- |
| `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 参考](/en/cli-reference)。

## 新手技巧

更多信息请参阅[最佳实践](/en/best-practices)和[常见工作流](/en/common-workflows)。

<AccordionGroup>
  <Accordion title="明确你的请求">
    不要这样："fix the bug"

    试试这样："fix the login bug where users see a blank screen after entering wrong credentials"
  </Accordion>

  <Accordion title="使用分步说明">
    将复杂任务分解为步骤：

    ```text 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
    ```
  </Accordion>

  <Accordion title="让 Claude 先探索">
    在进行更改之前，让 Claude 理解你的代码：

    ```text theme={null}
    analyze the database schema
    ```

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

  <Accordion title="使用快捷方式节省时间">
    * 输入 `/` 查看所有命令和技能
    * 使用 Tab 进行命令补全
    * 按 ↑ 查看命令历史
    * 按 `Shift+Tab` 循环切换权限模式
  </Accordion>
</AccordionGroup>

## 下一步

既然你已经学会了基础知识，来探索更多高级功能吧：

<CardGroup cols={2}>
  <Card title="Claude Code 工作原理" icon="microchip" href="/en/how-claude-code-works">
    了解智能体循环、内置工具以及 Claude Code 如何与你的项目交互
  </Card>

  <Card title="最佳实践" icon="star" href="/en/best-practices">
    通过有效的提示和项目设置获得更好的结果
  </Card>

  <Card title="常见工作流" icon="graduation-cap" href="/en/common-workflows">
    常见任务的分步指南
  </Card>

  <Card title="扩展 Claude Code" icon="puzzle-piece" href="/en/features-overview">
    使用 CLAUDE.md、技能、钩子、MCP 等进行自定义
  </Card>
</CardGroup>

## 获取帮助

* **在 Claude Code 中**：输入 `/help` 或询问"how do I..."
* **文档**：你就在这里！浏览其他指南
* **社区**：加入我们的 [Discord](https://www.anthropic.com/discord) 获取技巧和支持
