Claude Code 使用教程

在 VS Code / Cursor 中配置和使用 Claude Code

快速开始

1
安装 Claude Code 扩展
推荐 方式一:扩展商店安装
  1. 打开 VS Code / Cursor
  2. Ctrl+Shift+X(Mac: Cmd+Shift+X)打开扩展面板
  3. 搜索 Claude Code for VS Code
  4. 点击 Install 安装扩展
VS Code 扩展安装截图
2
配置 API 端点

⚠️ 重要步骤

必须先禁用登录提示,然后配置第三方 API 端点才能使用本站服务

步骤 2.1:禁用登录提示

推荐 方式一:快捷链接

点击链接直接打开设置:vscode://settings/claudeCode.disableLoginPrompt

方式二:手动搜索
  1. 打开 IDE 设置(Ctrl+, / Cmd+,
  2. 搜索 claudeCode.disableLoginPrompt
  3. 勾选 Disable Login Prompt 选项
禁用登录提示设置截图

步骤 2.2:配置 settings.json

编辑 Claude Code 配置文件 ~/.claude/settings.json

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "替换成自己的KEY",
    "ANTHROPIC_BASE_URL": "https://anapi.xn--vuq861bvij35ps8cv0uohm.com",
    "API_TIMEOUT_MS": "600000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

📁 配置文件位置

  • Windows: C:\Users\用户名\.claude\settings.json
  • macOS/Linux: ~/.claude/settings.json
3
开始使用 Claude Code

打开 Claude Code 面板

常用命令

/help查看帮助
/model切换模型
/compact压缩历史
/resume恢复对话

常见工作流示例

🔍 代码理解

> what does this project do?
> explain the folder structure
> where is the main entry point?

✏️ 代码编辑

> add input validation to the form
> refactor to use async/await
> fix the bug where users can submit empty

🔧 Git 操作

> what files have I changed?
> commit with a descriptive message
> help me resolve merge conflicts

🧪 测试与文档

> write unit tests for calculator
> update README with instructions
> review my changes and suggest improvements

常见问题

Q: 扩展无法安装?

确保 VS Code 版本 ≥ 1.98.0,或尝试使用命令行安装方式。

Q: Claude Code 不响应?

检查 settings.json 配置是否正确,确保 API 端点和 Key 填写无误。

Q: 如何切换模型?

在对话中输入 /model 命令即可切换不同的 Claude 模型。

API 使用示例

cURL 请求示例

curl https://anapi.xn--vuq861bvij35ps8cv0uohm.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk-your-api-key" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

流式请求

{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "stream": true,
  "messages": [...]
}

Thinking 模式

{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 16000,
  "thinking": {
    "type": "enabled",
    "budget_tokens": 10000
  },
  "messages": [...]
}