Skip to content

欢迎使用 Claude Code。本指南会帮助你在几分钟内开始使用 AI 编程辅助完成常见开发任务。

欢迎使用 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 CodeJetBrains IDEsSlack 以及 CI/CD 中的 GitHub ActionsGitLab。可在所有界面说明中查看完整列表。

可使用以下任一方式安装 Claude Code:

macOS、Linux、WSL:

Terminal window
curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

Terminal window
irm https://claude.ai/install.ps1 | iex

Windows CMD:

Terminal window
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。

原生安装会在后台自动更新,以便你始终保持在最新版本。

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

Claude Code 需要账户才能使用。当你使用 claude 命令启动交互式会话时,需要先登录:

Terminal window
claude
# 首次使用时会提示你登录
/login
# 按提示使用你的账户登录

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

登录完成后,你的凭据会保存在本机,之后无需重复登录。如需稍后切换账户,可使用 /login 命令。

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

Terminal window
cd /path/to/your/project
claude

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

在完成第 2 步登录后,你的凭据会保存在系统中。更多说明见 Credential Management

先从理解你的代码库开始。可以尝试以下命令之一:

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 file

Claude Code 会:

  • 找到合适的文件
  • 展示建议的修改
  • 请求你的批准
  • 完成编辑

Claude Code 在修改文件前总会请求权限。你可以逐项批准更改,也可以为当前会话启用 “Accept all” 模式。

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

Claude 很擅长调试和功能实现。

用自然语言描述你的需求:

add input validation to the user registration form

或者修复现有问题:

there's a bug where users can submit empty forms - fix it

Claude Code 会:

  • 定位相关代码
  • 理解上下文
  • 实现解决方案
  • 在可用时运行测试

你可以通过多种方式与 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
exitCtrl+D退出 Claude Codeexit

完整命令列表请参阅 CLI reference

更多内容请参阅 best practicescommon workflows

  • 明确表达你的请求
  • 使用分步骤指令
  • 先让 Claude 探索
  • 用快捷方式节省时间

现在你已经掌握了基础,可以继续探索更高级的功能:

  • 在 Claude Code 中:输入 /help,或直接问 “how do I…”
  • 文档:你现在就在文档中,可以继续浏览其他指南
  • 社区:加入他们的 Discord 获取技巧和支持
-
0:000:00