ieslab_skills/claude-code.md
admin 10e200f191 更新 claude-code.md 安装方式与前置条件
- 改用官方脚本安装(curl/PowerShell),无需 Node.js
- 新增独立"前置条件"章节,注明科学上网要求

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 15:12:07 +08:00

139 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Claude Code 使用入门
Claude Code 是 Anthropic 官方出品的 AI 编程助手,运行在终端(命令行)中,可以直接读写代码文件、执行命令,适合需要深度 AI 辅助开发的场景。
---
## 前置条件
- **科学上网**(安装及使用全程需要)
- Windows 用户需额外安装 [Git for Windows](https://git-scm.com/downloads/win)
---
## 安装
根据你的系统选择对应命令,在终端中运行即可,会自动保持最新版本:
**macOS / Linux / WSL**
```bash
curl -fsSL https://claude.ai/install.sh | bash
```
**Windows PowerShell**
```powershell
irm https://claude.ai/install.ps1 | iex
```
---
## 注册账号 / 获取访问权限
Claude Code 支持两种方式:
### 方式一Claude.ai 订阅(推荐新手)
1. 打开 [https://claude.ai](https://claude.ai)
2. 点击 **Sign up**,推荐选择 **Continue with Google** 用谷歌账号登录
3. 订阅 **Pro 计划**$20/月)或 **Max 计划**,即可在 Claude Code 中直接使用,无需 API Key
> 没有谷歌账号?参考 [google-account.md](./google-account.md) 完成注册。
#### 国内如何购买订阅
Claude 官网不支持国内银行卡,推荐通过 **苹果 App Store 礼品卡** 完成订阅:
**前提条件**
- 一台苹果手机iPhone
- 一个 Apple ID地区设置为**美国**
- 一张国内银联卡(用于购买礼品卡)
- 手机保持科学上网(节点选美国)
**操作步骤**
1. **切换 Apple ID 地区到美国**
- 前往 [https://appleid.apple.com](https://appleid.apple.com) 登录
- 进入 **Personal Information → Country/Region**,切换为 **United States**
- 填写美国地址任意美国地址即可如填写免税州Oregon、Montana 等)
2. **在 App Store 下载 Claude**
- 打开手机 App Store搜索 **Claude**,下载安装(确保 App Store 账号地区为美国)
3. **购买 App Store 礼品卡**
- 打开苹果官方礼品卡购买页面:[https://www.apple.com/shop/buy-giftcard/giftcard](https://www.apple.com/shop/buy-giftcard/giftcard)
- 选择 **Email** 方式,金额建议 $25够一个月 Pro
- 用国内**银联卡**支付,礼品卡会发到邮箱
4. **兑换礼品卡**
- 打开 App Store → 点右上角头像 → **Redeem Gift Card or Code**
- 输入邮件中的兑换码
5. **在 Claude App 内购买订阅**
- 打开 Claude App进入设置选择订阅计划
- 通过 App Store 内购完成支付(使用刚充值的余额)
- 全程保持手机科学上网
### 方式二Anthropic API Key
1. 打开 [https://console.anthropic.com](https://console.anthropic.com) 注册账号
2. 进入 **API Keys** 页面创建一个 Key
3. 在终端中设置环境变量:
```bash
export ANTHROPIC_API_KEY="sk-ant-xxxxxxxx"
```
或在 `.bashrc` / `.zshrc` 中永久保存。
#### API 充值说明
Anthropic 官网**不支持国内银行卡充值**,有以下两种思路:
- **第三方中转**:可在淘宝、闲鱼搜索"Anthropic API 充值",有代充服务,价格和真实性自行甄别,风险自负
- **接入国内模型**(替代方案):通过兼容 OpenAI 格式的国内模型来使用 Claude Code免去充值问题以下两个模型质量较好
| 平台 | 链接 | 说明 |
|------|------|------|
| 智谱 GLM | [open.bigmodel.cn](https://open.bigmodel.cn/) | 有详细的 [Claude Code 配置教程](https://docs.bigmodel.cn/cn/coding-plan/tool/claude) |
| MiniMax | [platform.minimaxi.com](https://platform.minimaxi.com/) | 注册即有免费额度 |
> 与 Claude Opus 4.6 相比有差距,但日常编程辅助基本够用。
---
## 首次登录
在终端运行以下命令,按提示完成授权:
```bash
claude
```
首次运行会弹出浏览器进行账号授权,授权完成后即可使用。
---
## 基本使用
在项目目录下打开终端,输入:
```bash
claude
```
进入交互模式后,直接用自然语言描述你的需求即可,例如:
- `帮我写一个读取 CSV 文件的 Python 函数`
- `这段代码有什么 bug`
- `帮我给这个项目写单元测试`
Claude Code 会自动读取相关文件、修改代码、运行命令。
---
[Claude Code 官方使用文档](https://docs.anthropic.com/en/docs/claude-code)