返回资料库 Claude Code 专题

Claude Code 快速入门

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

来源:code.claude.com/docs/en/quickstart | 整理时间:2026-04-01


前置条件

  • 终端(命令行)基础
  • 一个代码项目
  • Claude 账号(Pro/Max/Teams/Enterprise 或 Console API 账号)

第一步:安装

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

⚠️ Windows 需要先安装 Git for Windows

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


第二步:登录

claude
# 首次使用会提示登录

支持的账号类型:

  • Claude Pro / Max / Teams / Enterprise(推荐)
  • Claude Console(API 密钥访问)
  • Amazon Bedrock / Google Vertex AI / Microsoft Foundry

登录后,凭证会保存在本地,后续无需重复登录。


第三步:启动第一个会话

cd /path/to/your/project
claude

进入后可以:

  • /help — 查看所有命令
  • /resume — 继续之前的对话

第四步:探索代码库

# 了解项目整体
what does this project do?

# 了解技术栈
what technologies does this project use?

# 了解目录结构
explain the folder structure

# 找入口文件
where is the main entry point?

💡 Claude Code 会自动读取相关文件,不需要手动指定


第五步:做第一次代码修改

add a hello world function to the main file

Claude Code 会:

  1. 找到合适的文件
  2. 展示拟修改内容
  3. 请求你的确认
  4. 执行修改

默认需要确认每次文件修改。可以开启"全部接受"模式跳过确认。


第六步:Git 操作

# 查看修改内容
what files have I changed?

# 提交(自动生成 commit 信息)
commit my changes with a descriptive message

# 创建分支
create a new branch called feature/my-feature

# 查看提交历史
show me the last 5 commits

第七步:修 Bug、加功能

# 加功能(自然语言描述)
add input validation to the user registration form

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

# Claude 会:
# 1. 找到相关代码
# 2. 理解上下文
# 3. 实现修改
# 4. 如果有测试,运行测试

常用命令速查

命令 功能
claude 启动交互模式
claude "任务" 执行一次性任务
claude -p "查询" 单次查询后退出
claude -c 继续上次对话
claude -r 从历史会话中选择继续
claude commit 创建 Git commit
/clear 清空对话历史
/help 显示帮助
exitCtrl+C 退出

新手技巧

1. 具体描述需求

# 不好:add tests
# 好:write a test for foo.py covering the edge case 
#      where user is logged out. avoid mocks.

2. 分步骤指令

# 1. 先探索
read /src/auth and understand how we handle sessions

# 2. 再规划
what files need to change to add Google OAuth?

# 3. 最后执行
implement the OAuth flow from your plan

3. 让 Claude 先探索

使用 Plan Mode 安全分析(不会修改文件):

claude --permission-mode plan

4. 利用快捷键

  • Esc — 停止当前操作
  • Esc + Esc — 撤回并恢复之前的代码状态
  • Ctrl+G — 在文本编辑器中打开计划
  • Ctrl+O — 切换详细输出模式
  • Shift+Tab — 切换权限模式

下一步

常见问题

Claude Code 快速入门 适合什么读者?

Claude Code 快速入门 适合希望系统掌握 Claude Code 专题 的读者,尤其是需要从概念快速过渡到实践的人。页面包含主题摘要、相关阅读和来源链接,便于形成可执行的学习路径。

阅读 Claude Code 快速入门 需要多久?

当前页面预估阅读时长约 4 分钟。建议先读正文结论,再根据“同专题延伸”继续阅读,通常 20 到 40 分钟可以建立完整主题框架。

如何把 Claude Code 快速入门 的内容用于实际项目?

先按正文中的关键概念完成最小可运行示例,再把示例嵌入你当前项目流程。你可以结合来源链接验证细节,并使用同专题文章补齐部署、协作和评估步骤。