"Not the mind. The gateway to it."
Quick Start • Features • How It Works • Config • Desktop App • 中文
Use your Cursor subscription to power Claude Code. No separate Anthropic API key needed — Thalamus bridges the gap so Claude Code runs seamlessly on Cursor's models.
- Claude Code is Anthropic's terminal-based AI coding agent — it edits files, runs commands, and manages projects autonomously. But it requires a paid Anthropic API key.
- Cursor is an AI-powered IDE with its own subscription that includes access to powerful models (Claude, GPT, etc.) — but only inside Cursor's editor.
- Thalamus connects the two: it runs on your machine, pretends to be Anthropic's API, and forwards everything to Cursor's backend. Claude Code thinks it's talking to Anthropic, but it's actually using your existing Cursor subscription.
Result: You get Claude Code's full autonomous coding power, paid for by the Cursor subscription you already have.
Claude Code Cursor API
│ ▲
│ POST /v1/messages │
│ (Anthropic format) │
▼ │
┌──────────────────────────────────────────────────────────────────┐
│ T H A L A M U S │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────────────────┐ │
│ │ Protocol │ │ Tool Call │ │ Model Fallback │ │
│ │ Translation │→ │ Enhancement │→ │ & Auto-Continuation │ │
│ │ │ │ (LTLP) │ │ │ │
│ └─────────────┘ └──────────────┘ └─────────────────────────┘ │
│ │
│ Anthropic ↔ Protobuf │ Lazy stubs → full schema │ Retry │
└──────────────────────────────────────────────────────────────────┘
Problem: Claude Code registers 40+ tools (file read, file write, bash, search, etc.) — that's ~27,000 tokens of tool definitions sent with every request. Cursor's API doesn't natively support tool definitions, so other proxies either skip tools entirely or bloat every prompt.
Solution: Thalamus compresses all tool definitions into ultra-compact one-line stubs (~1KB total). When the model tries to use a tool, Thalamus teaches it the correct parameters on-the-fly:
Turn 1: Model sees stub "Write – create/overwrite files" → tries to call with guessed args
Turn 2: Thalamus intercepts, returns full schema as context → model learns the correct format
Turn 3: Model calls correctly — and remembers for all subsequent calls
Problem: Cursor's API doesn't tell us why the model stopped responding (did it finish? is it thinking? did it get confused?). Other proxies just assume "done" — causing Claude Code to stop mid-task, often after just describing what it would do without actually doing it.
Solution: Thalamus adds a task_complete signal. If the model outputs text but doesn't call any tool and doesn't explicitly say "I'm done," Thalamus nudges it: "You described the plan, now execute it." The text and subsequent tool calls get merged into one seamless response. Claude Code never sees the retry.
Problem: Sometimes a model is overloaded, rate-limited, or just slow. Your coding session shouldn't stall because of it.
Solution: If the first response token doesn't arrive within a configurable timeout (default 10s), Thalamus automatically retries with the next model in a priority chain. No manual switching needed.
Thalamus serves both Anthropic (/v1/messages) and OpenAI (/v1/chat/completions) formats from the same backend. This means you can use it with:
- Claude Code (Anthropic format)
- aider, Open WebUI, LangChain (OpenAI format)
- Any custom script using the
openaioranthropicPython SDK
| Requirement | Why | How to check |
|---|---|---|
| Python 3.10+ | Thalamus is a Python server | python3 --version |
| Cursor Pro/Business | Provides the model access you'll use | You're logged into cursor.com |
| Claude Code CLI | The agent that Thalamus powers | claude --version (install: npm install -g @anthropic-ai/claude-code) |
| Node.js 18+ | Required by Claude Code CLI | node --version |
git clone https://github.com/guojun21/thalamus.git
cd thalamus
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txtThalamus needs your Cursor authentication token to make API calls on your behalf. Choose one method:
Option A: Browser Login (easiest)
python server.py # Start the server first
# Open http://localhost:3013/cursor/login in your browser
# Log in with your Cursor account — token is saved automaticallyOption B: Extract from Cursor IDE
- Open Cursor IDE
- Open DevTools:
Cmd+Shift+I(Mac) /Ctrl+Shift+I(Windows/Linux) - Go to the Network tab
- Type anything in the chat to trigger a request
- Click any request to
api2.cursor.sh - Find the
Authorizationheader — copy the full value (starts withuser_) - Create your config:
cp .env.example .env
# Edit .env and paste your token:
# CURSOR_TOKEN=user_xxxxx::eyJhbGciOi...How long does a token last? Typically ~60 days. When it expires, you'll see authentication errors — just repeat this step to get a fresh one.
python server.pyExpected output:
INFO: Uvicorn running on http://0.0.0.0:3013
Verify it's working:
curl http://localhost:3013/health
# Expected: {"status":"ok","has_token":true}
#
# If you see "has_token":false, your token isn't configured — go back to Step 2Tell Claude Code to talk to Thalamus instead of Anthropic's servers:
export ANTHROPIC_BASE_URL=http://localhost:3013
export ANTHROPIC_API_KEY=thalamus-proxyWhy a fake API key? Claude Code refuses to start without
ANTHROPIC_API_KEY. Since Thalamus handles auth via your Cursor token, this value is never sent anywhere. Any non-empty string works.
Make it permanent — add to your shell config so you don't have to set it every time:
echo 'export ANTHROPIC_BASE_URL=http://localhost:3013' >> ~/.zshrc echo 'export ANTHROPIC_API_KEY=thalamus-proxy' >> ~/.zshrc source ~/.zshrc
claudeThat's it. Claude Code is now running on your Cursor subscription. All capabilities work: file editing, bash execution, web search, MCP tools — everything.
Send a direct test request:
curl -s http://localhost:3013/v1/messages \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 50,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}' | python3 -m json.toolIf you see a JSON response with the model's reply, everything is working.
Thalamus translates between Anthropic's Messages API and Cursor's private protobuf-based gRPC API in real time. Requests arrive as standard Anthropic JSON, get encoded into Cursor's protobuf format, streamed over HTTP/2, and the response is decoded back into Anthropic SSE events.
Instead of injecting all 40+ tool definitions (27K tokens) into every prompt, Thalamus:
- Generates stubs dynamically from the incoming
tools[]parameter — one line per tool, no hardcoding - Detects stub calls when the model tries to use a tool with missing/incomplete arguments
- Returns the full schema as a
tool_result, giving the model few-shot context - Periodically reminds the model about available tools every N turns to prevent attention decay
The entire mechanism is transparent — Claude Code sees standard Anthropic responses.
When the model produces text without calling any tool or task_complete:
- Thalamus appends a continuation prompt and re-calls the upstream API
- If the retry produces tool calls → merged with the original text into one response
- If the retry produces
task_complete→ returnsstop_reason: end_turn - Safety valve after max retries → falls through as
end_turn
Thalamus isn't just for Claude Code — anything that talks to OpenAI or Anthropic APIs can use it:
# aider (AI pair programming)
export ANTHROPIC_BASE_URL=http://localhost:3013
export ANTHROPIC_API_KEY=thalamus-proxy
aider
# Python openai SDK
import openai
client = openai.OpenAI(base_url="http://localhost:3013/v1", api_key="thalamus-proxy")
response = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello"}]
)
# Python anthropic SDK
import anthropic
client = anthropic.Anthropic(base_url="http://localhost:3013", api_key="thalamus-proxy")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
)
# curl (OpenAI format)
curl http://localhost:3013/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-4-20250514","messages":[{"role":"user","content":"Hi"}]}'All settings go in .env (copy from .env.example). Most users only need CURSOR_TOKEN.
| Variable | What it does | Default |
|---|---|---|
PORT |
Port Thalamus listens on | 3013 |
CURSOR_TOKEN |
Your Cursor auth token (the only required setting) | — |
CURSOR_CLIENT_VERSION |
Cursor version to impersonate (change if Cursor updates break things) | 2.5.25 |
CURSOR_CLOUDFLARE_IP |
IP address for api2.cursor.sh (rarely needs changing) | 104.18.19.125 |
CLAUDE_CODE_MODEL_FALLBACK_ENABLED |
Auto-switch to another model on timeout | true |
CLAUDE_CODE_MAX_MODEL_ATTEMPTS |
How many models to try before giving up | 5 |
CLAUDE_CODE_FIRST_TOKEN_TIMEOUT_MS |
How long to wait for first response (ms) | 10000 |
CLAUDE_CODE_FIRST_TOKEN_TIMEOUT_ENABLED |
Enable/disable timeout detection | true |
| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check (includes token status) |
| POST | /v1/messages |
Anthropic Messages API (primary) |
| POST | /v1/chat/completions |
OpenAI Chat Completions API |
| GET | /v1/models |
List available models |
| GET | /cursor/login |
Initiate PKCE browser login |
| POST | /token/update |
Update Cursor token |
| GET | /token/status |
Check current token |
| Thalamus | Cursor-To-OpenAI | CCProxy | LiteLLM | |
|---|---|---|---|---|
| Lazy Tool Loading (LTLP) | ✅ | ❌ | ❌ | ❌ |
| Auto-continuation | ✅ | ❌ | ❌ | ❌ |
| Stub reminders | ✅ | ❌ | ❌ | ❌ |
| Model fallback chain | ✅ | ❌ | Partial | ✅ |
| Anthropic API output | ✅ | ❌ | ❌ | ✅ |
| OpenAI API output | ✅ | ✅ | ✅ | ✅ |
| Cursor → Protobuf | ✅ | ✅ | ❌ | ❌ |
| Works with Claude Code | ✅ | ❌ | ✅ | ✅ |
⬇ Download Thalamus.app for macOS (currently macOS only, Windows/Linux coming soon)
A native macOS desktop launcher — no terminal needed, just double-click and go.
| Feature | Description |
|---|---|
| One-click start | Double-click the app, thalamus-py backend starts automatically |
| Built-in login | Cursor PKCE login right in the app, token saved automatically |
| API test panel | Fetch model list, send test messages, switch models — all in the UI |
| Lightweight | Swift + WKWebView, ~270KB, no Electron |
- macOS 10.15+ (Catalina or later)
- Python 3.10+ installed on your system (
python3 --versionto check) - Cursor Pro/Business subscription
Step 1: Set up Python environment
You need to clone the repo and install dependencies first — the app uses this as its backend:
git clone https://github.com/guojun21/thalamus.git
cd thalamus
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txtStep 2: Download and install the app
- Download
Thalamus-macOS.zip - Unzip it
- Drag
Thalamus.appto your/Applicationsfolder (or anywhere you like)
If macOS says "Thalamus can't be opened because it is from an unidentified developer", go to System Settings → Privacy & Security and click Open Anyway.
Step 3: Launch
Double-click Thalamus.app. You'll see:
- The app window opens with service status
- Backend starts automatically (status turns green when ready)
- If you haven't logged in before, click 🔑 登录 Cursor 账号 — your browser opens the Cursor login page
- Complete login in the browser — the app detects it and saves your token
- Done! Token persists across restarts (~60 days validity)
If you prefer to build the .app yourself instead of downloading:
cd thalamus/desktop-app
bash build.sh
# Output: dist/Thalamus.appRequires Xcode Command Line Tools (xcode-select --install) for the Swift compiler.
| Platform | Status |
|---|---|
| macOS (Apple Silicon & Intel) | ✅ Available now |
| Windows | 🚧 Planned |
| Linux | 🚧 Planned |
Windows and Linux users: use the command-line setup for now.
thalamus/
├── server.py # FastAPI entry point
├── config/
│ ├── fallback_config.py # Model fallback strategies
│ ├── system_prompt.py # System prompt injection
│ └── tool_registry.py # Tool normalization & validation
├── core/
│ ├── cursor_h2_client.py # HTTP/2 client (api2.cursor.sh)
│ ├── cursor_pkce_login.py # PKCE browser login flow
│ ├── protobuf_builder.py # Request protobuf encoding
│ ├── protobuf_frame_parser.py # Response protobuf decoding
│ └── token_manager.py # Token persistence & rotation
├── claude_code/
│ ├── pipeline.py # Main request pipeline (LTLP + continuation + fallback)
│ ├── tool_lazy_loader.py # Stub generation, schema store, LTLP core
│ ├── tool_prompt_builder.py # Prompt injection & periodic reminders
│ ├── tool_parser.py # Tool call extraction from text
│ ├── sse_assembler.py # Anthropic SSE event assembly
│ ├── openai_sse_assembler.py # OpenAI SSE event assembly
│ └── normalizers.py # Request/response normalization
├── routes/
│ ├── anthropic_messages.py # POST /v1/messages
│ ├── openai_chat.py # POST /v1/chat/completions
│ └── login_routes.py # PKCE login endpoints
├── proto/
│ ├── cursor_api.proto # Protobuf schema
│ └── cursor_api_pb2.py # Generated Python code
└── utils/
└── structured_logging.py # Multi-dimensional log partitioning
| Component | Technology |
|---|---|
| Language | Python 3.10+ |
| Framework | FastAPI + Uvicorn |
| HTTP/2 | httpx, h2 |
| Serialization | protobuf |
| Validation | Pydantic |
Is this free? Do I need to pay anything?
You need a Cursor subscription (Pro at $20/month or Business). That's it. You do NOT need an Anthropic API key. Thalamus itself is free and open source.
Is this against Cursor's Terms of Service?
Thalamus uses your own authenticated Cursor account to make API calls — the same calls Cursor IDE makes internally. It does not share accounts, bypass rate limits, or redistribute access. Use at your own discretion.
Which models can I use?
Whatever models your Cursor subscription includes. Typically: Claude Sonnet 4, Claude Haiku, GPT-4o, GPT-4.1, etc. Run curl http://localhost:3013/v1/models to see the full list.
Does Claude Code work normally? Can it edit files, run bash, use tools?
Yes. All of Claude Code's capabilities work: file editing (Read/Write/Edit), bash execution, web search, MCP tools, task management — everything. Thalamus translates the protocol transparently; Claude Code doesn't know it's not talking to Anthropic directly.
"has_token": false — health check shows no token
Your CURSOR_TOKEN is not set or is invalid. Either:
- Visit
http://localhost:3013/cursor/loginto login via browser, or - Check your
.envfile — make sureCURSOR_TOKEN=has a value (no quotes needed)
Claude Code says "connection refused" or "ECONNREFUSED"
Thalamus is not running. Make sure:
python server.pyis running in a terminal- The port matches: default is
3013 - Your env vars are set:
ANTHROPIC_BASE_URL=http://localhost:3013
Token expired / "Model name is not valid" errors
Your Cursor token may have expired. Tokens typically last ~60 days. Re-login:
- Visit
http://localhost:3013/cursor/login - Or extract a fresh token from Cursor IDE's DevTools (Network tab → any request to
api2.cursor.sh→ copyAuthorizationheader)
Can I use this with tools other than Claude Code?
Yes. Thalamus serves both Anthropic (/v1/messages) and OpenAI (/v1/chat/completions) formats. You can use it with:
- aider —
export ANTHROPIC_BASE_URL=http://localhost:3013 - Open WebUI — set the API base URL in settings
- Python scripts — use the
openaioranthropicSDK with custom base URL - Any tool that supports custom API endpoints
How is this different from cursor2api / Cursor-To-OpenAI?
Those projects do basic protocol conversion. Thalamus adds three mechanisms that make Claude Code actually work reliably:
- LTLP — compresses 40+ tool definitions from 27K tokens to 1KB stubs (without this, tool calling often fails)
- Auto-continuation — prevents the model from stopping mid-task when it outputs text without tools
- Model fallback — automatically retries with different models when one is slow/unavailable
Without these, Claude Code frequently breaks: tools don't get called, tasks stop halfway, or the model times out.
Windows support?
Thalamus itself runs on Windows (Python + FastAPI). However, Claude Code CLI currently only supports macOS and Linux. If you're on Windows, use WSL2.
Contributions are welcome. Please open an issue first to discuss what you'd like to change.
用你的 Cursor 订阅来跑 Claude Code,不需要额外买 Anthropic API key。
- Claude Code 是 Anthropic 出的终端 AI 编程 agent,能自主编辑文件、执行命令、管理项目。但它需要 Anthropic API key(按量付费,很贵)。
- Cursor 是 AI 编辑器,订阅后可以用 Claude/GPT 等模型,但只能在 Cursor 编辑器里用。
- Thalamus 把两者打通:在本地跑一个代理服务器,伪装成 Anthropic API,实际调用 Cursor 的后端。Claude Code 以为自己在跟 Anthropic 通信,其实用的是你已有的 Cursor 订阅额度。
丘脑是大脑中所有感觉信号的中继站——它不产生智能,但让智能可达。这正是本项目的定位:不是大脑本身,而是通往大脑的门户。
其他项目(cursor2api、Cursor-To-OpenAI 等)只做简单的协议转换。但 Claude Code 有 40+ 个工具定义(文件读写、bash 执行、搜索等),Cursor API 不原生支持这些,所以直接转发会导致:
- 工具调不通(模型不知道参数格式)
- 任务做到一半就停了(模型输出文字后被误判为"完成")
- 模型超时无响应
Thalamus 解决了这三个核心问题:
| 机制 | 解决什么 |
|---|---|
| 🔮 懒加载 Tool 协议 (LTLP) | 40+ 工具定义(27K tokens)压缩为 1KB 的精简描述,按需加载完整定义,模型通过上下文自动学会正确参数 |
| 🔄 自动续接 | 模型输出纯文字但没执行操作时,自动提醒它继续执行,把文字和操作合并为一个完整响应 |
| 🛡️ 智能模型回退 | 模型响应慢或不可用时,自动切换到下一个可用模型,不需要手动干预 |
| 需要什么 | 为什么 | 怎么检查 |
|---|---|---|
| Python 3.10+ | Thalamus 是 Python 写的 | python3 --version |
| Cursor Pro/Business 订阅 | 提供模型访问额度 | 已登录 cursor.com |
| Node.js 18+ | Claude Code CLI 需要 | node --version |
| Claude Code CLI | 要跑的 AI agent | claude --version(安装:npm install -g @anthropic-ai/claude-code) |
git clone https://github.com/guojun21/thalamus.git
cd thalamus
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txtThalamus 需要你的 Cursor 登录凭证来代你调用 API。两种方式:
方式 A:浏览器登录(最简单)
python server.py # 先启动服务
# 浏览器打开 http://localhost:3013/cursor/login
# 用 Cursor 账号登录,token 自动保存方式 B:从 Cursor IDE 手动提取
- 打开 Cursor IDE
- 打开开发者工具:
Cmd+Shift+I(Mac)/Ctrl+Shift+I(Windows/Linux) - 切到 Network(网络) 标签页
- 在聊天框随便输入点东西,触发一个请求
- 点击任意一个发往
api2.cursor.sh的请求 - 找到
Authorization请求头,复制完整值(以user_开头) - 配置:
cp .env.example .env
# 编辑 .env,粘贴 token:
# CURSOR_TOKEN=user_xxxxx::eyJhbGciOi...Token 有效期: 大约 60 天。过期后会报认证错误,重新获取即可。
python server.py看到这个就说明启动成功了:
INFO: Uvicorn running on http://0.0.0.0:3013
验证一下:
curl http://localhost:3013/health
# 期望输出:{"status":"ok","has_token":true}
# 如果 has_token 是 false,说明 token 没配好,回第二步告诉 Claude Code 连 Thalamus 而不是 Anthropic:
export ANTHROPIC_BASE_URL=http://localhost:3013
export ANTHROPIC_API_KEY=thalamus-proxy为什么要设一个假的 API key? Claude Code 启动时会检查
ANTHROPIC_API_KEY是否存在,不存在就拒绝启动。这个值不会被发送到任何地方,随便填个非空字符串就行。
持久化配置(不用每次都设):
echo 'export ANTHROPIC_BASE_URL=http://localhost:3013' >> ~/.zshrc echo 'export ANTHROPIC_API_KEY=thalamus-proxy' >> ~/.zshrc source ~/.zshrc
claude搞定。现在 Claude Code 用的就是你的 Cursor 订阅额度。所有功能正常:文件编辑、bash 执行、搜索、MCP 工具——全部可用。
可以接入任何支持自定义 base URL 的工具(aider、Open WebUI、LangChain 等):
export OPENAI_BASE_URL=http://localhost:3013/v1
export OPENAI_API_KEY=thalamus-proxy原生 macOS 桌面启动器,不用终端,双击即用。
前置条件: macOS 10.15+、Python 3.10+、Cursor Pro/Business 订阅
安装步骤:
- 先克隆仓库并安装 Python 依赖(app 需要这些作为后端):
git clone https://github.com/guojun21/thalamus.git
cd thalamus
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt- 下载
Thalamus-macOS.zip,解压后拖到/Applications - 双击打开 Thalamus.app
如果 macOS 提示"无法打开",去 系统设置 → 隐私与安全性,点击 仍要打开。
首次使用:
- 打开 app → 等待服务状态变绿(运行中)
- 点击「🔑 登录 Cursor 账号」→ 浏览器自动打开登录页
- 在浏览器完成登录 → app 自动检测并保存 Token
- 搞定!Token 会一直保存(约 60 天有效),下次打开不用重新登录
从源码构建:
cd thalamus/desktop-app && bash build.sh需要 Xcode 命令行工具(xcode-select --install)。
| 平台 | 状态 |
|---|---|
| macOS(Apple Silicon & Intel) | ✅ 已支持 |
| Windows | 🚧 计划中 |
| Linux | 🚧 计划中 |
Windows / Linux 用户请用命令行方式。
Q: 要花钱吗? A: 你需要 Cursor 订阅(Pro $20/月)。不需要 Anthropic API key。Thalamus 本身免费开源。
Q: 违反 Cursor 服务条款吗? A: Thalamus 用的是你自己的 Cursor 账号发起 API 调用,和 Cursor IDE 内部的调用方式一样。不共享账号、不绕过限速、不转售访问权限。请自行判断。
Q: Token 过期了怎么办?
A: 重新访问 http://localhost:3013/cursor/login 登录,或从 Cursor IDE DevTools 重新提取。
Q: Windows 能用吗? A: Thalamus 本身支持 Windows。但 Claude Code CLI 目前只支持 macOS 和 Linux,Windows 用户请用 WSL2。


