文档索引
在此获取完整文档索引:https://code.claude.com/docs/llms.txt 使用此文件发现所有可用页面,然后再进一步探索。
快速入门
欢迎使用 Claude Code!
本快速入门指南将在几分钟内让你开始使用 AI 驱动的编码辅助。完成后,你将了解如何使用 Claude Code 处理常见的开发任务。
开始之前
请确保你拥有:
- 已打开终端或命令提示符
- 如果你从未使用过终端,请查看终端指南
- 一个代码项目可供使用
- Claude 订阅(Pro、Max、Team 或 Enterprise)、Claude Console 账户,或通过支持的云提供商访问
本指南涵盖终端 CLI。Claude Code 还可在 Web、桌面应用、VS Code 和 JetBrains IDE、Slack 中使用,以及通过 GitHub Actions 和 GitLab 在 CI/CD 中使用。查看所有接口。
步骤 1:安装 Claude Code
要安装 Claude Code,请使用以下方法之一:
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
如果你看到 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,以便 Claude Code 可以使用 Bash 工具。如果未安装 Git for Windows,Claude Code 将改用 PowerShell 作为 shell 工具。WSL 环境不需要 Git for Windows。
原生安装会自动在后台更新,确保你始终使用最新版本。
brew install --cask claude-code
Homebrew 提供两个 cask。claude-code 跟踪稳定发布通道,通常落后约一周,并跳过存在重大回归的版本。claude-code@latest 跟踪最新通道,新版本发布后立即接收。
Homebrew 安装不会自动更新。根据你安装的 cask,运行 brew upgrade claude-code 或 brew upgrade claude-code@latest 以获取最新功能和安全修复。
winget install Anthropic.ClaudeCode
WinGet 安装不会自动更新。定期运行 winget upgrade Anthropic.ClaudeCode 以获取最新功能和安全修复。
你也可以在 Debian、Fedora、RHEL 和 Alpine 上使用 apt、dnf 或 apk 进行安装。
步骤 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(企业云提供商)
登录后,你的凭据将被存储,无需再次登录。
步骤 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 做一些实际的编码工作。尝试一个简单任务:
add a hello world function to the main file
Claude Code 将:
- 找到合适的文件
- 向你展示拟议的更改
- 请求你的批准
- 进行编辑
Claude Code 在修改文件前始终会请求权限。你可以批准单个更改,或为会话启用"全部接受"模式。
步骤 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/quickstart
show me the last 5 commits
help me resolve merge conflicts
步骤 7:修复错误或添加功能
Claude 擅长调试和功能实现。
用自然语言描述你想要的内容:
add input validation to the user registration form
或修复现有问题:
there's a bug where users can submit empty forms - fix it
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 对话。描述你想要实现的目标,它会帮助你达成。
常用命令
以下是日常使用中最重要的命令:
| 命令 | 功能 | 示例 |
|---|---|---|
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 参考。
新手技巧
明确你的请求
不要这样:"fix the bug"
试试这样:"fix the login bug where users see a blank screen after entering wrong credentials"
使用分步说明
将复杂任务分解为步骤:
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
让 Claude 先探索
在进行更改之前,让 Claude 理解你的代码:
analyze the database schema
build a dashboard showing products that are most frequently returned by our UK customers
使用快捷方式节省时间
- 输入
/查看所有命令和技能 - 使用 Tab 进行命令补全
- 按 ↑ 查看命令历史
- 按
Shift+Tab循环切换权限模式
下一步
既然你已经学会了基础知识,来探索更多高级功能吧:
了解智能体循环、内置工具以及 Claude Code 如何与你的项目交互
通过有效的提示和项目设置获得更好的结果
常见任务的分步指南
使用 CLAUDE.md、技能、钩子、MCP 等进行自定义
获取帮助
- 在 Claude Code 中:输入
/help或询问"how do I..." - 文档:你就在这里!浏览其他指南
- 社区:加入我们的 Discord 获取技巧和支持