Skip to content

快速开始

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

开始前

确保您有:

  • Node.js 18+ 或使用原生安装
  • 一个 Claude.ai 或 Claude Console 账户

步骤 1:安装 Claude Code

bash
# macOS/Linux
curl -fsSL https://claude.ai/install.sh | bash

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

# NPM
npm install -g @anthropic-ai/claude-code

步骤 2:登录您的账户

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

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

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

bash
cd your-project
claude

您将看到 Claude Code 欢迎屏幕。输入 /help 查看可用命令,或输入 /resume 继续之前的对话。

步骤 4:提出您的第一个问题

让我们从了解您的代码库开始:

> give me an overview of this codebase
> explain the main architecture patterns used here

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

让 Claude Code 进行一些实际的编码:

> add input validation to the user registration function

Claude Code 将:

  1. 找到适当的文件
  2. 向您显示建议的更改
  3. 请求您的批准
  4. 进行编辑

步骤 6:在 Claude Code 中使用 Git

Claude Code 使 Git 操作变得对话式:

> commit these changes with a descriptive message
> create a new branch for this feature

步骤 7:修复错误或添加功能

Claude 擅长调试和功能实现:

> fix the authentication bug in the login flow
> add a dark mode toggle to the settings page

基本命令

命令功能示例
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+C退出 Claude Code> exit

初学者的专业提示

  • 从广泛的问题开始,然后缩小到特定领域
  • 使用 @filename 引用特定文件
  • 使用 /compact 定期压缩对话以减少上下文大小
  • 在批准前审查建议的更改

接下来是什么?

aicodex 文档网站