Claude Code 最新详细安装教程
一、Windows 系统安装
好消息:我们Windows用户再也不需要使用WSL虚拟机各种配置来使用 Claude Code,直接在 Windows 环境就可以直接体验到 Claude Code 编码的快乐了。
可视化的桌面应用可以下载(可选):https://github.com/getAsterisk/claudia
注意事項:大家一定要提前打开魔法工具🌐,否则无法使用。
大家肯定会问为什么要切换到Claude Code 而不是 Cursor?那是因为最新Cursor在抽风,给国内的IP断了,体验了一回被卡脖子的感觉🤦♂️,干脆就直接用Claude Code。😎😎
1. 准备工作
1. 打开命令提示符
-
在搜索栏输入:cmd,即可出现【命令提示符】,然后按下Enter回车键即可打开。
-
命令行工具,由于默认的是 Power Shell 无法运行 Claude Code , 所以推荐大家统一改成【命令提示符】,方便后期直接使用。(如果没有下面第二张图的,则可以忽略。)
2. 安装 nvm 工具
-
nvm 下载地址:https://nvm.uihtm.com/,选择最新版本的安装,安装过程中一直点击 【Next】 下一步,遇到需要同意协议的,点击【agree】即可。
-
安装教程详见: NVM 工具|Node 多版本管理工具
3. 安装 node 版本
- 版本推荐: 18+
nvm install 18
# 或者安装最新的22
# nvm install 22
4. 使用 node 版本
如果本地开发的时候用到了多个版本的node,在使用 Claude Code时候,请先切换到能启动的版本,比如:node V18以上的版本。
nvm use 18
# 或者使用最新版本22
nvm use 22
2. 安装 Claude Code
2.1 全局安装 Claude Code
npm install -g @anthropic-ai/claude-code
2.2 检查安装版本
- 出现具体的版本,说明安装成功。
C:\Users\Administrator>claude --version
1.0.53 (Claude Code)
2.3 配置系统常量
-
配置系统常量主要是电脑的不同用户都可以使用。
-
在搜索栏输入【环境变量】,即可出现【编辑系统环境变量】,然后按下 Enter 回车键即可打开。
-
然后点击【环境变量】,就可以在【系统变量】中 新建变量了。
-
系统常量参数如下,配置完成之后,记得点击【确定】按钮保存变量数据。
-
大家可以提前注册账户:注册入口,可以贈送100美元的額度,运气好可能还会跟我一样,多几十美元。😁🤩
ANTHROPIC_AUTH_TOKEN=sk-eYCNf0I6ceXXXXXXXXXXXXXXXXXXXXXXANTHROPIC_BASE_URL=https://anyrouter.top
2.4 启动 Claude Code
启动 Claude Code,强烈建议在项目根目录下使用。
-
打开项目目录,然后在命令行输入:
claude
, 我们就可以启动成功的界面内容了。 -
配置主题模式:可以上下切换模式,回车键为确认。
╭──────────────────────────╮
│ ✻ Welcome to Claude Code │
╰──────────────────────────╯Let's get started.Choose the text style that looks best with your terminal:To change this later, run /theme❯ 1. Dark mode✔2. Light mode3. Dark mode (colorblind-friendly)4. Light mode (colorblind-friendly)5. Dark mode (ANSI colors only)6. Light mode (ANSI colors only)Preview╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ 1 function greet() { ││ 2 - console.log("Hello, World!"); ││ 2 + console.log("Hello, Claude!"); ││ 3 } │╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
3. Claude Code 配置
3.1 安全注意事项
提示: 在使用Claude Code的时候,注意审查回复的内容,避免出现注入的风险。
接下来我们点击回车键继续。。。
╭──────────────────────────╮
│ ✻ Welcome to Claude Code │
╰──────────────────────────╯Security notes:1. Claude can make mistakesYou should always review Claude's responses, especially whenrunning code.2. Due to prompt injection risks, only use it with code you trustFor more details see:https://docs.anthropic.com/s/claude-code-securityPress Enter to continue…
3.2 信任文件确认
默认选择第一个,然后回车键确认即可。
上下键可以切换选项,如果是非项目目录,请选择第二个退出。
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Do you trust the files in this folder? │
│ │
│ D:\Project\Web │
│ │
│ Claude Code may read files in this folder. Reading untrusted files may lead Claude Code to behave in unexpected ways. │
│ │
│ With your permission Claude Code may execute files in this folder. Executing untrusted code is unsafe. │
│ │
│ https://docs.anthropic.com/s/claude-code-security │
│ │
│ ❯ 1. Yes, proceed │
│ 2. No, exit │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Enter to confirm · Esc to exit
3.3 运行登录命令
- 在提示框中,输入
/login
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Do you trust the files in this folder? │
│ │
│ F:\Codes\250701-App\Desktop │
│ │
│ Claude Code may read files in this folder. Reading untrusted files may lead Claude Code to behave in │
│ unexpected ways. │
│ │
│ With your permission Claude Code may execute files in this folder. Executing untrusted code is unsafe. │
│ │
│ https://docs.anthropic.com/s/claude-code-security │
│ │
│ ❯ 1. Yes, proceed │
│ 2. No, exit │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Enter to confirm · Esc to exit
╭─────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: F:\3-Codes\250701-App\Desktop │
╰─────────────────────────────────────────────────────╯Tips for getting started:1. Run /init to create a CLAUDE.md file with instructions for Claude2. Run /terminal-setup to set up terminal integration3. Use Claude to help with file analysis, editing, bash commands and git4. Be as specific as you would with another engineer for the best results※ Tip: Run /terminal-setup to enable convenient terminal integration like Shift + Enter for new line and more ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Try "fix lint errors" │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯? for shortcuts Missing API key · Run /login
3.4 登录成功
-
登录成功之后,我们可以选择两种计费方式,一种是官方的,一种使用Anthropic控制平台。
-
由于我们使用的
https://anyrouter.top
所以需要配置第二种,会自动跳转到官方网站,采用Google方式登录即可。
注意事项:如果没有配置系统变量或者没有重新打开命令提示符工具,则会出现下面的问题。重新按照前面的配置方式重新启动即可。
╭──────────────────────────╮
│ ✻ Welcome to Claude Code │
╰──────────────────────────╯██████╗██╗ █████╗ ██╗ ██╗██████╗ ███████╗██╔════╝██║ ██╔══██╗██║ ██║██╔══██╗██╔════╝██║ ██║ ███████║██║ ██║██║ ██║█████╗██║ ██║ ██╔══██║██║ ██║██║ ██║██╔══╝╚██████╗███████╗██║ ██║╚██████╔╝██████╔╝███████╗╚═════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝██████╗ ██████╗ ██████╗ ███████╗██╔════╝██╔═══██╗██╔══██╗██╔════╝██║ ██║ ██║██║ ██║█████╗██║ ██║ ██║██║ ██║██╔══╝╚██████╗╚██████╔╝██████╔╝███████╗╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝Claude Code can now be used with your Claude subscription or billed based on API usage through your Console account.Select login method:❯ 1. Claude account with subscriptionStarting at $20/mo for Pro, $100/mo for Max - Best value, predictable pricing2. Anthropic Console accountAPI usage billing
- 下面会出现一串权限的Code,需要复制到命令行工具里面去。
Paste code here if prompted > 这里输入下面的Code内容
4. 正式使用
- 启动之后,出现下面的
API Base URL: https://anyrouter.top
, 则代表我们配置成功了,现在可以开始使用了。
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: C:\Users\Administrator │
│ │
│ ─────────────────────────────────────────────── │
│ │
│ Overrides (via env): │
│ │
│ • API Base URL: https://anyrouter.top │
╰───────────────────────────────────────────────────╯Tips for getting started:1. Run /init to create a CLAUDE.md file with instructions for Claude2. Use Claude to help with file analysis, editing, bash commands and git3. Be as specific as you would with another engineer for the best resultsNote: You have launched claude in your home directory. For the best experience, launch it in a project directoryinstead.※ Tip: Use /theme to change the color theme╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Try "write a test for <filepath>" │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯? for shortcuts
恭喜您!已经完成了Claude Code 的本地安装,如果这篇文章对您有所帮助,欢迎您多多分享给身边的人,也能享受到技术红利,多给自己留些上班摸鱼的时间。😂😂
若在安装过程中有疑问的,欢迎大家留言评论❤️❤️❤️