欢迎使用 Claude Code!
文档索引
可在此获取完整文档索引:https://code.claude.com/docs/llms.txt
在进一步浏览前,可使用该文件发现所有可用页面。
这份快速开始指南会让你在几分钟内开始使用 AI 驱动的编程辅助。完成后,你将了解如何使用 Claude Code 处理常见开发任务。
请确保你具备:
- 已打开的终端或命令提示符
- 一个可供操作的代码项目
- Claude 订阅(Pro、Max、Team 或 Enterprise)、Claude Console 账户,或通过受支持云提供商获得访问权限
如果你从未使用过终端,可以先阅读 terminal guide。
本指南主要介绍终端 CLI。Claude Code 同时也支持 Web、桌面应用、VS Code、JetBrains IDEs、Slack 以及 CI/CD 中的 GitHub Actions 和 GitLab。可在所有界面说明中查看完整列表。
第 1 步:安装 Claude Code
Section titled “第 1 步:安装 Claude Code”可使用以下任一方式安装 Claude Code:
macOS、Linux、WSL:
curl -fsSL https://claude.ai/install.sh | bashWindows PowerShell:
irm https://claude.ai/install.ps1 | iexWindows CMD:
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。当提示符显示 PS C:\ 时,你在 PowerShell 中;如果显示 C:\ 且前面没有 PS,则表示你在 CMD 中。
在原生 Windows 上,推荐安装 Git for Windows,这样 Claude Code 可以使用 Bash 工具。如果未安装 Git for Windows,Claude Code 会改用 PowerShell 作为 shell 工具。WSL 环境不需要 Git for Windows。
原生安装会在后台自动更新,以便你始终保持在最新版本。
brew install --cask claude-codeHomebrew 提供两个 cask。claude-code 跟踪稳定发布通道,通常会比最新版本滞后一周左右,并会跳过存在重大回归的问题版本。claude-code@latest 跟踪最新通道,会在版本发布后立即收到更新。
Homebrew 安装不会自动更新。请根据你安装的 cask 运行 brew upgrade claude-code 或 brew upgrade claude-code@latest,以获得最新功能和安全修复。
winget install Anthropic.ClaudeCodeWinGet 安装不会自动更新。请定期运行 winget upgrade Anthropic.ClaudeCode,以获得最新功能和安全修复。
你也可以在 Debian、Fedora、RHEL 和 Alpine 上使用 apt、dnf 或 apk 安装。
第 2 步:登录你的账户
Section titled “第 2 步:登录你的账户”Claude Code 需要账户才能使用。当你使用 claude 命令启动交互式会话时,需要先登录:
claude# 首次使用时会提示你登录
/login# 按提示使用你的账户登录你可以使用以下任一种账户类型登录:
- Claude Pro、Max、Team 或 Enterprise(推荐)
- Claude Console(使用预付费额度的 API 访问)。首次登录时,Console 中会自动创建一个
Claude Code工作区,用于统一成本跟踪。 - Amazon Bedrock、Google Vertex AI 或 Microsoft Foundry(企业云提供商)
登录完成后,你的凭据会保存在本机,之后无需重复登录。如需稍后切换账户,可使用 /login 命令。
第 3 步:启动你的第一次会话
Section titled “第 3 步:启动你的第一次会话”在任意项目目录中打开终端并启动 Claude Code:
cd /path/to/your/projectclaude你将看到 Claude Code 的欢迎界面,其中包含会话信息、最近的对话和最新更新。输入 /help 查看可用命令,或输入 /resume 继续之前的会话。
在完成第 2 步登录后,你的凭据会保存在系统中。更多说明见 Credential Management。
第 4 步:提出你的第一个问题
Section titled “第 4 步:提出你的第一个问题”先从理解你的代码库开始。可以尝试以下命令之一:
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 会在需要时读取你的项目文件。你不需要手动补充上下文。
第 5 步:做出你的第一次代码修改
Section titled “第 5 步:做出你的第一次代码修改”现在让 Claude Code 真正开始编码。试一个简单任务:
add a hello world function to the main fileClaude Code 会:
- 找到合适的文件
- 展示建议的修改
- 请求你的批准
- 完成编辑
Claude Code 在修改文件前总会请求权限。你可以逐项批准更改,也可以为当前会话启用 “Accept all” 模式。
第 6 步:在 Claude Code 中使用 Git
Section titled “第 6 步:在 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/quickstartshow me the last 5 commitshelp me resolve merge conflicts第 7 步:修复 Bug 或添加功能
Section titled “第 7 步:修复 Bug 或添加功能”Claude 很擅长调试和功能实现。
用自然语言描述你的需求:
add input validation to the user registration form或者修复现有问题:
there's a bug where users can submit empty forms - fix itClaude Code 会:
- 定位相关代码
- 理解上下文
- 实现解决方案
- 在可用时运行测试
第 8 步:试试其他常见工作流
Section titled “第 8 步:试试其他常见工作流”你可以通过多种方式与 Claude 协作:
refactor the authentication module to use async/await instead of callbackswrite unit tests for the calculator functionsupdate the README with installation instructionsreview my changes and suggest improvements像与一位有帮助的同事交流那样和 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 reference。
给初学者的专业建议
Section titled “给初学者的专业建议”更多内容请参阅 best practices 和 common workflows。
- 明确表达你的请求
- 使用分步骤指令
- 先让 Claude 探索
- 用快捷方式节省时间
接下来做什么?
Section titled “接下来做什么?”现在你已经掌握了基础,可以继续探索更高级的功能:
- How Claude Code works:理解代理循环、内置工具以及 Claude Code 如何与你的项目交互
- Best practices:通过更有效的提示方式和项目设置获得更好的结果
- Common workflows:常见任务的分步指南
- Extend Claude Code:使用
CLAUDE.md、skills、hooks、MCP 等进行自定义
- 在 Claude Code 中:输入
/help,或直接问 “how do I…” - 文档:你现在就在文档中,可以继续浏览其他指南
- 社区:加入他们的 Discord 获取技巧和支持