快速开始

欢迎使用 Claude Code!

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

开始前

确保您拥有:

本指南涵盖终端 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)。

步骤 1:安装 Claude Code

To install Claude Code, use one of the following methods:

**macOS, Linux, WSL:**
theme
1
curl -fsSL https://claude.ai/install.sh | bash
**Windows PowerShell:**
theme
1
irm https://claude.ai/install.ps1 | iex
**Windows CMD:**
theme
1
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. [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>
theme
1
brew install --cask claude-code
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>
theme
1
winget install Anthropic.ClaudeCode
<Info>
  WinGet installations do not auto-update. Run `winget upgrade Anthropic.ClaudeCode` periodically to get the latest features and security fixes.
</Info>

You can also install with apt, dnf, or apk on Debian, Fedora, RHEL, and Alpine.

步骤 2:登录您的账户

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

theme
1
claude

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

theme
1
/login

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

登录后,您的凭证将被存储,您无需再次登录。

步骤 3:启动您的第一个会话

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

theme
1
2
cd /path/to/your/project
claude

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

登录后(步骤 2),您的凭证将存储在您的系统上。在[凭证管理](/zh-CN/authentication#credential-management)中了解更多信息。

步骤 4:提出您的第一个问题

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

theme
1
这个项目做什么?

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

theme
1
这个项目使用什么技术?
theme
1
主入口点在哪里?
theme
1
解释文件夹结构

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

theme
1
Claude Code 能做什么?
theme
1
我如何在 Claude Code 中创建自定义 skills?
theme
1
Claude Code 可以与 Docker 一起工作吗?
Claude Code 根据需要读取您的项目文件。您不必手动添加上下文。

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

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

theme
1
在主文件中添加一个 hello world 函数

Claude Code 将:

  1. 找到适当的文件
  2. 向您显示建议的更改
  3. 请求您的批准
  4. 进行编辑
Claude Code 在修改文件前始终请求许可。您可以批准单个更改或为会话启用"全部接受"模式。

步骤 6:在 Claude Code 中使用 Git

Claude Code 使 Git 操作变得对话式:

theme
1
我更改了哪些文件?
theme
1
用描述性消息提交我的更改

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

theme
1
创建一个名为 feature/quickstart 的新分支
theme
1
显示我最后的 5 次提交
theme
1
帮我解决合并冲突

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

Claude 擅长调试和功能实现。

用自然语言描述您想要的内容:

theme
1
向用户注册表单添加输入验证

或修复现有问题:

theme
1
有一个错误,用户可以提交空表单 - 修复它

Claude Code 将:

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

步骤 8:尝试其他常见工作流

有多种方式可以与 Claude 一起工作:

重构代码

theme
1
重构身份验证模块以使用 async/await 而不是回调

编写测试

theme
1
为计算器函数编写单元测试

更新文档

theme
1
使用安装说明更新 README

代码审查

theme
1
审查我的更改并建议改进
像与有帮助的同事交谈一样与 Claude 交谈。描述您想要实现的目标,它将帮助您实现。

基本命令

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

命令 功能 示例
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 参考

初学者专业提示

有关更多信息,请参阅最佳实践常见工作流

不要说:"修复错误"
尝试:"修复登录错误,用户输入错误凭证后看到空白屏幕"
将复杂任务分解为步骤:
theme
1
2
3
1. 为用户配置文件创建新的数据库表
2. 创建 API 端点以获取和更新用户配置文件
3. 构建允许用户查看和编辑其信息的网页
在进行更改之前,让 Claude 理解您的代码:
theme
1
分析数据库架构
theme
1
构建一个仪表板,显示英国客户最常退货的产品
* 输入 `/` 查看所有命令和 skills * 使用 Tab 进行命令补全 * 按 ↑ 查看命令历史 * 按 `Shift+Tab` 循环切换权限模式

接下来呢?

现在您已经学习了基础知识,探索更多高级功能:

了解代理循环、内置工具以及 Claude Code 如何与您的项目交互 通过有效的提示和项目设置获得更好的结果 常见任务的分步指南 使用 CLAUDE.md、skills、hooks、MCP 等进行自定义

获取帮助

  • 在 Claude Code 中:输入 /help 或询问”我如何…”
  • 文档:您在这里!浏览其他指南
  • 社区:加入我们的 Discord 获取提示和支持