在 Cursor 中使用 Claude

Cursor 是一款基于 VS Code 的 AI 驱动代码编辑器,内置了强大的 AI 编程功能。通过配置 Claude API 中转站,你可以在 Cursor 中使用 Claude 模型进行代码生成、编辑和对话。本文提供详细的配置步骤。

为什么在 Cursor 中使用 Claude?

配置步骤

方法一:通过 Cursor 设置配置

  1. 打开 Cursor,进入 SettingsCmd+,Ctrl+,
  2. 搜索 "OpenAI" 或 "API"
  3. 找到 Models 相关设置
  4. 配置 API Key 和 Base URL

方法二:使用 OpenAI 兼容模式

许多中转站支持 OpenAI 兼容的 API 格式,Cursor 原生支持这种方式:

  1. 在 Cursor 设置中找到 OpenAI API Key
  2. 输入你的中转站 API Key
  3. 设置 Base URL 为中转站的 OpenAI 兼容端点
# Cursor 的 OpenAI 兼容配置
API Key: your-relay-key
Base URL: https://claude4u.com/openai

方法三:通过 Anthropic API 配置

Cursor 也支持直接配置 Anthropic API:

  1. 在设置中找到 Anthropic API Key 选项
  2. 输入中转站的 API Key
  3. 设置 Anthropic Base URL
# Cursor 的 Anthropic 配置
Anthropic API Key: your-relay-key
Anthropic Base URL: https://claude4u.com

模型选择

配置完成后,你可以在 Cursor 中选择 Claude 模型:

Cursor 中 Claude 的使用方式

1. 内联编辑(Cmd+K)

选中代码后按 Cmd+K(Mac)或 Ctrl+K(Windows),输入指令让 Claude 修改选中的代码:

2. Chat 面板(Cmd+L)

Cmd+L 打开 AI Chat 面板,可以与 Claude 对话:

3. Composer(Cmd+I)

使用 Composer 进行多文件的批量修改,适合需要跨文件操作的场景。

配置验证

配置完成后,验证 Claude 是否正常工作:

  1. 打开 Chat 面板(Cmd+L
  2. 确认顶部的模型选择为 Claude
  3. 输入 "Hello, which model are you?"
  4. 如果 Claude 正常回复,说明配置成功

常见问题

API Key 格式不正确

确保使用中转站的 Key 格式(如 cr_ 前缀),不要使用官方格式(sk-ant-)。

模型列表不显示 Claude

检查 Base URL 是否正确,尝试清除 Cursor 缓存后重启。

响应速度慢

注意:Cursor 的自带 AI 功能(Cursor Tab、Cursor++)需要 Cursor 订阅。通过 API 配置 Claude 属于"Bring Your Own Key"模式,部分功能可能受限。
提示:轻舟 AI(claude4u.com)支持 OpenAI 兼容和 Anthropic 原生两种 API 格式,完美兼容 Cursor 的各种配置方式,配置一次即可在 Cursor 中流畅使用 Claude。

Start Using 轻舟 AI

Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more

Sign Up Now