快速开始
欢迎使用 Claude Code!
本快速开始指南将在几分钟内让您使用 AI 驱动的编码辅助。完成本指南后,您将了解如何使用 Claude Code 完成常见的开发任务。
开始前
确保您拥有:
- 打开的终端或命令提示符
- 如果您之前从未使用过终端,请查看终端指南
- 一个可以使用的代码项目
- 一个 Claude 订阅(Pro、Max、Team 或 Enterprise)、Claude Console 账户,或通过支持的云提供商的访问权限
本指南涵盖终端 CLI。Claude Code 也可在网页、桌面应用、VS Code 和 JetBrains IDE、Slack 中使用,以及通过 GitHub Actions 和 GitLab 进行 CI/CD。查看所有界面。
步骤 1:安装 Claude Code
To install Claude Code, use one of the following methods:
macOS, Linux, WSL:
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell:
irm https://claude.ai/install.ps1 | iex
Windows CMD:
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 to match the error to a fix and for alternative install methods.
Git for Windows 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.
Native installations automatically update in the background to keep you on the latest version.
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.
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.
winget install Anthropic.ClaudeCode
WinGet installations do not auto-update. Run winget upgrade Anthropic.ClaudeCode periodically to get the latest features and security fixes.
You can also install with apt, dnf, or apk on Debian, Fedora, RHEL, and Alpine.
步骤 2:登录您的账户
Claude Code 需要账户才能使用。使用 claude 命令启动交互式会话,首次使用时系统会提示您登录:
claude
对于 Claude 订阅或 Console 账户,请按照提示在浏览器中完成身份验证。要稍后切换账户或重新身份验证,请在运行的会话中输入 /login:
/login
您可以使用以下任何账户类型登录:
- Claude Pro、Max、Team 或 Enterprise(推荐)
- Claude Console(具有预付费额度的 API 访问)。首次登录时,Console 中会自动为集中成本跟踪创建一个"Claude Code"工作区。
- Amazon Bedrock、Google Vertex AI 或 Microsoft Foundry(企业云提供商)
- 自托管的 Claude apps gateway(如果您的组织运行一个):您的管理员会预先配置网关 URL,
/login会直接在 Cloud gateway 屏幕上打开,供您使用企业 SSO 登录
登录后,您的凭证将被存储,您无需再次登录。
步骤 3:启动您的第一个会话
在任何项目目录中打开您的终端并启动 Claude Code:
cd /path/to/your/project
claude
您将看到 Claude Code 提示符,其中显示版本、当前模型和上方显示的工作目录。输入 /help 查看可用命令,或输入 /resume 继续之前的对话。
登录后(步骤 2),您的凭证将存储在您的系统上。在凭证管理中了解更多信息。
步骤 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:进行您的第一次代码更改
现在让我们让 Claude Code 进行一些实际的编码。尝试一个简单的任务:
在主文件中添加一个 hello world 函数
Claude Code 将:
- 找到适当的文件
- 向您显示建议的更改
- 请求您的批准
- 进行编辑
Claude Code 在修改文件前始终请求许可。您可以批准单个更改或为会话启用"全部接受"模式。
步骤 6:在 Claude Code 中使用 Git
Claude Code 使 Git 操作变得对话式:
我更改了哪些文件?
用描述性消息提交我的更改
您也可以提示更复杂的 Git 操作:
创建一个名为 feature/quickstart 的新分支
显示我最后的 5 次提交
帮我解决合并冲突
步骤 7:修复错误或添加功能
Claude 擅长调试和功能实现。
用自然语言描述您想要的内容:
向用户注册表单添加输入验证
或修复现有问题:
有一个错误,用户可以提交空表单 - 修复它
Claude Code 将:
- 定位相关代码
- 理解上下文
- 实现解决方案
- 如果可用,运行测试
步骤 8:尝试其他常见工作流
有多种方式可以与 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
像与有帮助的同事交谈一样与 Claude 交谈。描述您想要实现的目标,它将帮助您实现。
基本命令
以下是日常使用中最重要的命令。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 |
有关完整的 shell 命令列表,请参阅 CLI 参考,有关完整的会话命令列表,请参阅 命令参考。
初学者专业提示
尝试:"修复登录错误,用户输入错误凭证后看到空白屏幕"
使用分步说明
将复杂任务分解为步骤:
1. 为用户配置文件创建新的数据库表
2. 创建 API 端点以获取和更新用户配置文件
3. 构建允许用户查看和编辑其信息的网页
让 Claude 先探索
在进行更改之前,让 Claude 理解您的代码:
分析数据库架构
构建一个仪表板,显示英国客户最常退货的产品
使用快捷方式节省时间
- 输入
/查看所有命令和 skills - 使用 Tab 进行命令补全
- 按 ↑ 查看命令历史
- 按
Shift+Tab循环切换权限模式
接下来呢?
现在您已经学习了基础知识,探索更多高级功能:
了解代理循环、内置工具以及 Claude Code 如何与您的项目交互
通过有效的提示和项目设置获得更好的结果
常见任务的分步指南
使用 CLAUDE.md、skills、hooks、MCP 等进行自定义
获取帮助
- 在 Claude Code 中:输入
/help或询问"我如何..." - 文档:您在这里!浏览其他指南
- 社区:加入我们的 Discord 获取提示和支持