English ← MyDocs

文档索引

在此获取完整文档索引:https://code.claude.com/docs/llms.txt 使用此文件发现所有可用页面,然后再进一步探索。

快速入门

欢迎使用 Claude Code!

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

开始之前

请确保你拥有:

Note

本指南涵盖终端 CLI。Claude Code 还可在 Web桌面应用VS CodeJetBrains IDESlack 中使用,以及通过 GitHub ActionsGitLab 在 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。

Info

原生安装会自动在后台更新,确保你始终使用最新版本。

brew install --cask claude-code

Homebrew 提供两个 cask。claude-code 跟踪稳定发布通道,通常落后约一周,并跳过存在重大回归的版本。claude-code@latest 跟踪最新通道,新版本发布后立即接收。

Info

Homebrew 安装不会自动更新。根据你安装的 cask,运行 brew upgrade claude-codebrew upgrade claude-code@latest 以获取最新功能和安全修复。

winget install Anthropic.ClaudeCode
Info

WinGet 安装不会自动更新。定期运行 winget upgrade Anthropic.ClaudeCode 以获取最新功能和安全修复。

你也可以在 Debian、Fedora、RHEL 和 Alpine 上使用 apt、dnf 或 apk 进行安装。

步骤 2:登录账户

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

claude

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

/login

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

登录后,你的凭据将被存储,无需再次登录。

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

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

cd /path/to/your/project
claude

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

Tip

登录后(步骤 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?
Note

Claude Code 会根据需要读取你的项目文件。你无需手动添加上下文。

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

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

add a hello world function to the main file

Claude Code 将:

  1. 找到合适的文件
  2. 向你展示拟议的更改
  3. 请求你的批准
  4. 进行编辑
Note

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
Tip

像与乐于助人的同事交谈一样与 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 Codeexit

完整命令列表请参阅 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 中:输入 /help 或询问"how do I..."
  • 文档:你就在这里!浏览其他指南
  • 社区:加入我们的 Discord 获取技巧和支持