Use Cursor subscription models from OpenCode by speaking Cursor's Connect-RPC agent protocol.
AI SDK LanguageModelV3 provider plus an OpenCode plugin for auth and model discovery. Runs encode/decode Cursor's protobuf agent protocol over HTTP/2 — not a generic chat-completions API.
OpenCode 1.x / 2.x natively, and unchanged through OCP on Kilo Code, MiMo Code, pi, oh-my-pi, and DeepSeek Harness. See Coding-agent compatibility.
Status: Auth, discovery, streaming, and tools work end-to-end. See Known limitations.
One package. Other hosts adapt through OCP — no provider fork.
| Coding agent | How this package runs |
|---|---|
| OpenCode 1.x | Native plugin — setup |
| OpenCode 2.x | cursor-opencode-provider/plugin/opencode2 — setup |
| Kilo / MiMo Code | Unchanged via OCP's OpenCode-clone layer |
| pi / oh-my-pi | Unchanged via @opencode-compat/pi-bridge |
| DeepSeek Harness | Unchanged via @opencode-compat/dsh-bridge |
Host guides: OpenCode clones · Pi family · DSH.
- Auth via browser OAuth (PKCE) or API key from cursor.com/settings
- Live model discovery with local cache; OpenCode 2.x refreshes an expired catalog on host activity without reloading the Location
- Streaming Runs with HTTP/2 health checks, held-tool continuations, and checkpoint-based recovery
- Tools from the advertised OpenCode catalog (Task →
task/subagent; OCP translates other host vocabularies) - Native Cursor compaction (
summarize_action) for Cursor models; image input only where live probes recorded a positive result - Reasoning deltas, plan/todo display bridges, and priced Fast / long-context catalog entries
| Host | Guide |
|---|---|
| OpenCode 1.x | docs/opencode-1.md — classic plugin, optional 1.18 plugin/v2 |
| OpenCode 2.x | docs/opencode-2.md — plugin/opencode2 only |
| Other agents | Coding-agent compatibility |
Do not load the 1.x and 2.x entrypoints in the same host.
OpenCode 1.x (~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["cursor-opencode-provider"]
}OpenCode 2.x (prefer a dedicated OPENCODE_CONFIG_DIR):
{
"plugins": ["cursor-opencode-provider/plugin/opencode2"]
}npm install cursor-opencode-provider # or: bun add cursor-opencode-provider
# pin if desired: cursor-opencode-provider@0.9.0From source: git clone … && bun install && bun run build. Local clones, plugin/v2, and leftover providers.cursor cleanup are in the host guides.
Follow OpenCode 1.x or OpenCode 2.x for host config and local wiring.
| Host | How |
|---|---|
| 1.x | opencode auth login → cursor |
| 2.x | /connect → Cursor (CURSOR_API_KEY is also picked up) |
Then use browser login (PKCE) or paste an API key (crsr_…) from cursor.com/settings.
After login, models land in <host-cache>/cursor-models.json. Conversation snapshots live under <host-cache>/cursor-conversations/ (gzip protobuf, one file per host session). Retention defaults to 24 h via CURSOR_PROVIDER_CACHE_TTL_MS. OpenCode 2.x also rechecks the model catalog after expiry on host activity; a failed refresh keeps the last good catalog.
Resolved in order: createCursor({ cacheDir }) → structural host path bridge → native OpenCode ($XDG_CACHE_HOME/opencode or ~/.cache/opencode).
| Kind | Default (OpenCode) |
|---|---|
| Model / conversation cache | ~/.cache/opencode/ |
Project metadata (agent-tools, terminals, …) |
~/.cache/opencode/projects/<slug>/ |
Auth (auth.json) |
~/.local/share/opencode/ ($XDG_DATA_HOME/opencode/ when set) |
| Config | ~/.config/opencode/ |
opencode run --model cursor/composer-2.5 "Hello from Cursor via OpenCode"Cursor parameters (effort, thinking, fast, context tier, …) appear as OpenCode model variants. The TUI variant dialog / variant_cycle (default ctrl+t) selects them; the map is sent as requested_model.parameters.
Picker keys are the delta after the model name (High, No Thinking Low, High 500k), not Cursor's full display string. Fast / dedicated-tier entries also drop a redundant Fast or tier token. An empty delta is keyed Standard (OpenCode reserves default for "no variant"). A pick saved under an old full-name key (for example grok-4.7#Grok 4.7 High 500k) no longer matches until re-selected: 1.x uses the entry default meanwhile; 2.x rejects the prompt.
When Cursor offers a long-context tier, the plugin adds <id>-1m (and similar for other marked tiers such as grok-4.7-500k) with that window's limit.context, only that tier's variants, and the real Cursor id in options.cursorModelId. Output limit is 128000 on 1M entries (32000 on base).
A published Fast rate becomes <id>-fast (or <id>-1m-fast). Reselect any saved Fast choice under the new entry.
Context limits prefer live AvailableModels, then the generated Cursor docs table, then a 200000 fallback. Docs never invent variants Cursor did not advertise.
Image input is advertised only for models with a positive probe in src/image-input-data.ts. Probe with bun run generate:images; check coverage with bun run generate:images:check. Attachments go through Cursor's selected-images path; generated / copied images save via cursor_image_save under host write permissions.
Max mode follows Cursor's variant markers (including *-1m and other max tiers) or providerOptions.cursor.maxMode. There is no separate Max Mode chrome in OpenCode.
On a Cursor model, OpenCode compaction uses Cursor's own summarize_action in place (same conversation), not a reminted history dump. Mid-turn compaction ends the held turn first, then summarizes once. OpenCode 2.x answers the compaction hook with that summary. Foreign-provider compaction still rebases from host history — see OpenCode 2.x.
import { createCursor } from "cursor-opencode-provider"
const cursor = createCursor({
name: "cursor",
accessToken: process.env.CURSOR_ACCESS_TOKEN,
// apiBaseURL, agentBaseURL, cacheDir, telemetryEnabled, retry, continuation
})
const model = cursor.languageModel("composer-2.5")One credential source, first wins: getAccessToken (renewable), then accessToken (JWT as-is), then apiKey (crsr_…, exchanged near expiry). Legacy baseURL aliases agentBaseURL. Without an explicit agent host, GetServerConfig resolves an HTTPS *.cursor.sh Run host once per process (in memory only).
Shell results, terminal files, and agent-tools/ spills are covered in OpenCode 1.x and OpenCode 2.x. Retry budgets and CURSOR_ENDLESS_RETRIES match Cursor CLI's Run loop with the same safety cutoffs (two stream-without-checkpoint resumes; 180 s stall window).
| Variable | Description |
|---|---|
CURSOR_WEBSITE_URL |
OAuth login base (default https://cursor.com) |
CURSOR_API_BASE_URL |
Auth / models / GetServerConfig (default https://api2.cursor.sh) |
CURSOR_GET_SERVER_CONFIG_TELEMETRY |
1 / true to opt GetServerConfig into telemetry |
HTTPS_PROXY / https_proxy |
HTTP CONNECT proxy for HTTPS (http:// only for the Run tunnel) |
NO_PROXY / no_proxy |
Hosts that bypass the proxy |
CURSOR_ENDLESS_RETRIES |
1 / true bypasses retry count limits; safety cutoffs remain |
CURSOR_PROGRESS_CONTINUATION |
0 / false / off / no turns off the progress-fragment follow-up Run |
CURSOR_PROVIDER_DEBUG |
1 wire debug; 2 / verbose per-frame |
CURSOR_PROVIDER_RECOVERY_DEBUG |
Recovery metadata only (same log path) |
CURSOR_PROVIDER_DEBUG_FILE |
Log path (default under $TMPDIR/cursor-provider-logs-<uid>/) |
CURSOR_PROVIDER_DEBUG_LOG_MODE |
trim (default) or rotate — rotation |
CURSOR_PROVIDER_DEBUG_ROTATE_MAX_BYTES |
Rotate at this size (default 50 MiB) |
CURSOR_PROVIDER_DEBUG_ROTATE_BACKUPS |
Archives to keep (1–100, default 5) |
CURSOR_PROVIDER_CACHE_TTL_MS |
Snapshot retention ms (default 86400000). Same value in every process that shares the cache |
CURSOR_AGENT_TRANSCRIPTS_FOLDER |
Existing directory advertised as past-chat transcripts; frozen per conversation |
CURSOR_OPENCODE2_DEV_ENTRY |
Absolute built entry for local 2.x (aisdk:file://…); set before opencode2 service start |
CURSOR_OPENCODE2_USE_LOCAL_DIST |
Local 2.x build publishes its dist/index.js unless 0; DEV_ENTRY wins |
CURSOR_OPENCODE2_TODOS |
1 / true registers in-memory 2.x todowrite / todoread |
XDG_CACHE_HOME / XDG_DATA_HOME |
Native OpenCode cache / auth roots when no bridge or cacheDir |
Docs index: docs/README.md. Review harness: docs/review-harness.md. Architecture and release gates: AGENTS.md.
bun install
bun run build
bun run typecheck
bun test
bun run test:node-http2
bun run live-test # needs CURSOR_API_KEY
bun run generate:pricing && bun run check:pricing
bun run generate:images # live image probes; :check for coverageCross-platform harness: python3 -B scripts/test-harness.py (--diagnose for prerequisites).
HARD STOP before a version bump or v* tag: in the same session, generate:pricing + check:pricing (map new display names, commit pricing data), generate:images (commit image-input-data.ts), finalize CHANGELOG.md, then bump package.json / tag. Publish CI regenerates rates as a backstop only.
OpenCode
└── CursorPlugin (auth, model cache)
└── createCursor() → LanguageModelV3
├── session / activity held Run + exec bridge
├── protocol/ protobuf, tools, thinking
└── transport/ Connect-RPC HTTP/2
Module ownership and invariants live in AGENTS.md. Cache / token / billing log reading: docs/cache-log-runbook.md.
| Export | Contents |
|---|---|
. |
createCursor, classic plugin |
./plugin |
Classic OpenCode 1.x plugin |
./plugin/v2 |
OpenCode 1.18 v2 (load beside classic) |
./plugin/opencode2 / ./server |
OpenCode 2.x plugin (server also re-exports classic for the 1.18 loader) |
./errors, ./models, ./pricing, ./auth, ./image-save |
Subpath APIs |
| Symptom | What to try |
|---|---|
| Disconnects / sleep-wake | CURSOR_PROVIDER_RECOVERY_DEBUG=1; search recovery: by hostSessionId |
| Auth / 401 mid-session | Browser sessions renew via /oauth/token; API keys re-exchange near JWT expiry. Sign in again if the session or key was rejected |
| Local 2.x loads npm package | Rebuild, load the worktree plugin (not node_modules), unset CURSOR_OPENCODE2_USE_LOCAL_DIST, restart; or set CURSOR_OPENCODE2_DEV_ENTRY |
| Silent HTTP 200 | Need turn_ended / trailers; enable CURSOR_PROVIDER_DEBUG=1 |
| Wire dumps | CURSOR_PROVIDER_DEBUG=1 or 2; optional CURSOR_PROVIDER_DEBUG_FILE |
Trust model and reporting: SECURITY.md. Disclaimer: DISCLAIMER.md.
- Progress-only fragments may get one follow-up Run so the model can call a tool or finish; opt out with
CURSOR_PROGRESS_CONTINUATION=0 - Title / compaction helper turns (
allowTools=false) do not continue that way - Auto stays unpriced when billing can vary by route; priced catalog rows use Cursor's published rates (including Fast and long-context)
- Conversation bindings survive restarts via private snapshots; a failed save invalidates the prior snapshot for that session
- Direct PDF / audio / video attachments are unsupported; tool-result images use Cursor's image fields within a 20 MiB continuation budget
See CHANGELOG.md.
