一、必须先装:Git for Windows
Claude Code 在 Windows 上依赖 Git Bash,必须先装:
下载:https://git-scm.com/download/win
安装:
全程默认,一路 Next
关键步:Adjusting your PATH 选默认:
✅ Git from the command line and also from 3rd-party software
验证(PowerShell/CMD):
bash
运行
git --version
输出版本号即可。
二、安装 Claude Code(两种方式,选其一)
方式 A:官方一键安装(推荐,不用 Node.js)
打开 PowerShell(普通用户即可,不用管理员):
powershell
irm https://claude.ai/install.ps1 | iex
等待跑完,自动加入环境变量。
方式 B:npm 安装(适合已有 Node.js)
先装 Node.js(18+,LTS 版):https://nodejs.org/
然后:
bash
运行
npm install -g @anthropic-ai/claude-code
验证安装
bash
运行
claude --version
输出版本号即成功。
三、登录账号(必做)
在项目文件夹打开 PowerShell/CMD:
bash
运行
claude
首次运行会提示登录:
选 Claude Pro/Max 账号(订阅)或 Anthropic Console(API 按量)
按提示浏览器授权,或粘贴 API Key
国内网络:需能正常访问 claude.ai 或 Anthropic API。
四、日常使用(极简)
- 进入你的代码项目目录
bash
运行
cd D:\projects\my_python_project
- 启动 Claude Code
bash
运行
claude
- 直接发中文指令(例子)
plaintext
帮我修复这个项目里的 Python 报错
帮我优化 main.py,加异常捕获和注释
帮我生成 requirements.txt
帮我解释当前文件夹的代码结构
- 它会自动做(Agent 流程)
读取文件(Read)
分析代码 / 报错
修改代码(Edit)→ 你确认后保存
运行命令(Bash):python main.py、pip install 等
循环迭代直到解决
五、VS Code 插件(更方便,推荐)
VS Code 扩展商店搜索:Claude Code(Anthropic 官方)
安装后,侧边栏点 Claude 图标
登录同上面步骤
直接在编辑器里对话、修 Bug、改代码
软件 VS Code Claude Code 插件
六、常见问题(Windows)
提示找不到 bash.exe
手动指定路径(PowerShell):
powershell
claude config set env.CLAUDE_CODE_GIT_BASH_PATH "C:\Program Files\Git\bin\bash.exe"
PowerShell 执行策略报错(少见)
管理员身份 PowerShell 运行:
powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
网络连不上
检查代理 / 防火墙,确保能访问 claude.ai 及 api.anthropic.com。
七、收费(快速回顾)
订阅:Pro 20/月、Max 100 / 月(VS Code / 终端直接用)
API 按量:Sonnet 输入 3/1M、输出 15/1M(适合偶尔用)
新账号:有少量免费额度(够试几个小任务)