feat: add OpenRouter proxy for Cursor CLI agent#3087
Open
Conversation
Cursor CLI uses a proprietary ConnectRPC/protobuf protocol with BiDi
streaming over HTTP/2. It validates API keys against Cursor's own servers
and hardcodes api2.cursor.sh for agent streaming — making direct
OpenRouter integration impossible.
This adds a local translation proxy that intercepts Cursor's protocol
and routes LLM traffic through OpenRouter:
Architecture:
Cursor CLI → Caddy (HTTPS/H2, port 443) → split routing:
/agent.v1.AgentService/* → H2C Node.js (BiDi streaming → OpenRouter)
everything else → HTTP/1.1 Node.js (fake auth, models, config)
Key components:
- cursor-proxy.ts: proxy scripts + deployment functions
- Caddy reverse proxy for TLS + HTTP/2 termination
- /etc/hosts spoofing to intercept api2.cursor.sh
- Hand-rolled protobuf codec for AgentServerMessage format
- SSE stream translation (OpenRouter → ConnectRPC protobuf frames)
Proto schemas reverse-engineered from Cursor CLI binary v2026.03.25:
- AgentServerMessage.InteractionUpdate.TextDeltaUpdate.text
- agent.v1.ModelDetails (model_id, display_model_id, display_name)
- TurnEndedUpdate (input_tokens, output_tokens)
Tested end-to-end on Sprite VM: Cursor CLI printed proxy response with
EXIT=0.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a local ConnectRPC-to-REST translation proxy that enables Cursor CLI to route LLM traffic through OpenRouter, bypassing Cursor's proprietary protocol lock-in.
Architecture
How it works
configure()— installs Caddy, uploads Node.js proxy scripts, configures hosts spoofingpreLaunch()— starts Caddy + two Node.js backends (systemd or setsid fallback)/v1/chat/completions(streaming) → encodes response asAgentServerMessageprotobuf framesProto schemas (reverse-engineered from CLI binary)
AgentServerMessage.InteractionUpdate.TextDeltaUpdate.textfor streaming textagent.v1.ModelDetails(model_id=1, display_model_id=3, display_name=4) for model listTurnEndedUpdate(field 14) for turn completionNew files
packages/cli/src/shared/cursor-proxy.ts— proxy scripts + deployment functionspackages/cli/src/__tests__/cursor-proxy.test.ts— 17 tests (protobuf, framing, deployment)Verified
Test plan
spawn cursor sprite→ verify proxy starts, Cursor CLI launchesspawn cursor hetzner→ verify works on non-Sprite cloud🤖 Generated with Claude Code