主题
快速开始
本快速开始指南将在几分钟内让您使用 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 functionClaude Code 将:
- 找到适当的文件
- 向您显示建议的更改
- 请求您的批准
- 进行编辑
步骤 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 |
exit 或 Ctrl+C | 退出 Claude Code | > exit |
初学者的专业提示
- 从广泛的问题开始,然后缩小到特定领域
- 使用
@filename引用特定文件 - 使用
/compact定期压缩对话以减少上下文大小 - 在批准前审查建议的更改