Claude Code 是 Anthropic 推出的 AI 驱动编码助手,能够理解你的整个代码库,并跨多个文件和工具完成复杂的开发任务。本教程将带你从零开始,完成安装配置,并开始你的第一个 AI 辅助开发会话。
系统要求
开始之前,请确保你具备:
- 已打开的终端或命令提示符
- 一个代码项目
- Claude 订阅(Pro、Max、Teams 或 Enterprise)或 Anthropic Console 账户
Step 1:安装 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注意:Windows 用户需要先安装 Git for Windows。
使用 Homebrew(macOS)
brew install --cask claude-codeHomebrew 安装不会自动更新。运行
brew upgrade claude-code手动更新。
使用 WinGet(Windows)
winget install Anthropic.ClaudeCodeStep 2:登录账户
在任意项目目录启动 Claude Code:
claude
# 首次使用时会提示登录或者使用登录命令:
/login
# 按提示完成账户登录你可以使用以下账户类型登录:
- Claude Pro / Max / Teams / Enterprise(推荐)
- Claude Console(API 访问,按量计费)
- 第三方云提供商:Amazon Bedrock、Google Vertex AI、Microsoft Foundry
登录成功后,凭证会保存到本地,之后无需重复登录。
Step 3:开始你的第一个会话
在项目目录中启动 Claude Code:
cd /path/to/your/project
claude你会看到欢迎界面,显示会话信息、近期对话和最新更新。输入 /help 查看可用命令,或输入 /resume 继续上次的对话。
Step 4:探索代码库
开始了解你的项目,尝试这些命令:
what does this project do?Claude 会分析你的文件并提供项目概述。你还可以问更具体的问题:
what technologies does this project use?where is the main entry point?explain the folder structureClaude Code 会按需读取你的项目文件,无需手动添加上下文。
Step 5:进行第一次代码修改
尝试让 Claude Code 完成一个简单任务:
add a hello world function to the main fileClaude Code 会:
- 找到合适的文件
- 展示建议的修改内容
- 请求你的确认
- 执行修改
Claude Code 在修改文件前始终会请求权限确认。你可以逐个批准,或开启「全部接受」模式。
Step 6:与 Git 集成
Claude Code 让 Git 操作变得更自然:
what files have I changed?commit my changes with a descriptive messagecreate a new branch called feature/quickstartshow me the last 5 commitshelp me resolve merge conflictsStep 7:修复 Bug 或添加功能
用自然语言描述你的需求:
add input validation to the user registration form或者修复现有问题:
there is a bug where users can submit empty forms - fix itClaude Code 会定位相关代码、理解上下文、实现解决方案,并在有测试的情况下运行测试。
Step 8:更多常用工作流
重构代码
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 -p "prompt" | 非交互式单次执行 | claude -p "fix the bug in auth.ts" |
claude --help | 查看帮助信息 | claude --help |
其他使用界面
Claude Code 不仅支持终端,还可以通过以下方式使用:
- VS Code 扩展:内联差异、@-提及、方案审阅、对话历史
- JetBrains IDE 插件
- 桌面应用:独立运行,支持并排多会话
- 网页版:
claude.ai/code - Slack 集成
- GitHub Actions / GitLab CI/CD
小结
Claude Code 将 AI 编码助手直接带入你的开发工作流。通过自然语言与代码库交互,让重构、调试、测试编写等任务变得更加高效。掌握本教程后,你已具备开始日常开发使用的基础,进一步探索 MCP 集成、Hooks 自动化、Agent 团队等高级功能将进一步提升你的开发效率。
来源:Claude Code 官方文档 - Quickstart
原文作者:Anthropic Team