跳转至主要内容
本快速入门指南将让您在几分钟内掌握 AI 驱动的编码辅助功能。读完后,您将了解如何使用 Claude Code 完成常见的开发任务。

开始之前

请确保您具备以下条件
本指南涵盖终端 CLI。Claude Code 也可通过网页桌面应用VS CodeJetBrains IDEsSlack,以及通过 GitHub ActionsGitLab 用于 CI/CD 中。请查看所有可用界面

第一步:安装 Claude Code

要安装 Claude Code,请使用以下方法之一

第二步:登录您的账户

使用 Claude Code 需要账户。当您使用 claude 命令启动交互式会话时,您需要进行登录
claude
# You'll be prompted to log in on first use
/login
# Follow the prompts to log in with your account
您可以使用以下任何一种账户类型进行登录 登录后,您的凭据会被存储,无需再次登录。若要稍后切换账户,请使用 /login 命令。

第三步:开始您的第一个会话

在任何项目目录中打开您的终端并启动 Claude Code
cd /path/to/your/project
claude
您将看到 Claude Code 的欢迎界面,其中包含您的会话信息、最近的对话和最新更新。输入 /help 查看可用命令,或输入 /resume 继续之前的对话。
登录后(第二步),您的凭据会存储在您的系统上。在凭据管理中了解更多信息。

第四步:提出您的第一个问题

让我们从了解您的代码库开始。尝试使用以下命令之一
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 会根据需要读取您的项目文件。您无需手动添加上下文。

第五步:进行第一次代码修改

现在让我们让 Claude Code 进行实际的编码工作。尝试一个简单的任务
add a hello world function to the main file
Claude Code 将会
  1. 找到合适的文件
  2. 向您展示建议的更改
  3. 请求您的批准
  4. 进行编辑
Claude Code 在修改文件前总是会请求许可。您可以批准单个更改,或者为会话启用“全部接受 (Accept all)”模式。

第六步:在 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

第七步:修复错误或添加功能

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 "任务"运行一次性任务claude "修复构建错误"
claude -p "查询"运行一次性查询,然后退出claude -p "解释此函数"
claude -c继续当前目录下的最近一次对话claude -c
claude -r恢复之前的对话claude -r
claude commit创建 Git 提交claude commit
/clear清除对话历史/clear
/help显示可用命令/help
exit 或 Ctrl+C退出 Claude Codeexit
请查看CLI 参考手册获取完整命令列表。

新手专业提示

欲了解更多信息,请参阅最佳实践常见工作流程
与其说:“修复错误”不如说:“修复登录错误,即用户在输入错误凭据后看到空白屏幕的问题”
将复杂的任务拆解为步骤
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 理解您的代码
analyze the database schema
build a dashboard showing products that are most frequently returned by our UK customers
  • ? 查看所有可用的键盘快捷键
  • 使用 Tab 键补全命令
  • 按 ↑ 键查看命令历史
  • 输入 / 查看所有命令和技能

接下来做什么?

现在您已经掌握了基础知识,可以探索更高级的功能了

Claude Code 的工作原理

了解代理循环、内置工具以及 Claude Code 如何与您的项目交互

最佳实践

通过有效的提示词工程和项目设置获得更好的结果

常见工作流

常见任务的分步指南

扩展 Claude Code

使用 CLAUDE.md、技能、钩子、MCP 等进行自定义

获取帮助

  • 在 Claude Code 中:输入 /help 或提问“如何...”
  • 文档:您就在这里!浏览其他指南
  • 社区:加入我们的 Discord 获取提示和支持
© . This site is unofficial and not affiliated with Anthropic.