实战:路径与工作流

Claude Code 快速入门

更新 原创整合
标签
claude-codequickstarttutorial

Claude Code 是什么

Claude Code 是 Anthropic 的 AI 编程助手,在终端、IDE 和浏览器中运行。它和网页版 Claude 的核心区别:能直接读写你电脑上的文件、执行命令、管理 Git

维度 Claude Code 网页版 Claude / ChatGPT
访问文件 可以读写本地文件 只能上传单个文件
执行操作 可以运行命令、改代码 只能对话
项目理解 理解整个文件夹结构 一次只看一个文件
持续对话 在同一项目中保持上下文 有限

安装

macOS / Linux / WSL

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

Windows

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

# 或 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、Console API、Amazon Bedrock、Google Vertex AI、Microsoft Foundry。登录后凭证保存在本地,无需重复登录。


定价

套餐 适用 月费
Pro 短任务、小代码库 $20/月
Max 5x 大代码库日常使用 $100/月
Max 20x 高强度使用 $200/月
Team/Enterprise 团队协作 按需定价

第一次使用

进入项目目录,启动:

cd /path/to/your/project
claude

常用命令:

命令 功能
claude 启动交互模式
claude "任务" 执行一次性任务
claude -p "查询" 单次查询后退出
claude -c 继续上次对话
claude commit 创建 Git commit
/help 查看所有命令
/resume 继续之前的对话
exit 退出

探索代码库

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

它会:找到文件 → 展示拟修改内容 → 请求确认 → 执行修改。默认每次文件修改都需要确认,可以开启"全部接受"跳过。

Git 操作

commit my changes with a descriptive message
create a new branch called feature/my-feature
show me the last 5 commits

不只是给程序员用的

Claude Code 是一个终端 AI 助手,很多功能不需要编程知识:

场景 需要编程? 举例
分析文件 "总结一下这个 PDF 的要点"
文件批量处理 "把这 10 个 CSV 合并成一个"
搜索 "找到所有包含'报价'的文件"
翻译改写 "把 README.md 翻译成中文"
数据处理 "统计日志里出现最多的错误"
学习编程 初学即可 "解释这段代码在做什么"

新手技巧

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. Plan Mode 安全分析

不会修改文件,适合先了解情况:

claude --permission-mode plan

4. 常用快捷键

快捷键 功能
Esc 停止当前操作
Esc + Esc 撤回并恢复之前的代码
Ctrl+G 在文本编辑器中打开计划
Ctrl+R 搜索历史命令
Shift+Tab 切换权限模式

注意事项

  • Claude Code 可以操作你电脑上的文件 → 参见 Agent 安全指南
  • 重要操作前它会征求确认
  • API 费用按使用量计算,注意设置消费上限