This is a fork of oakimov/cursor-opencode-provider: upstream plus fixes we needed for daily work with OpenCode 2 and T3 Code (steering mid-turn, background shells, recovery from Cursor stalls and capacity refusals, a stop on Cursor's silent model fallback, skills, titles, cost, and more). Each fix is listed under
[Unreleased]in CHANGELOG.md; the larger behaviour differences are in This fork. To use it, build this repository and point OpenCode's provider package at the build (aisdk:file://<checkout>/dist/index.js). Issues are welcome here; upstream is synced regularly.
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.
- Parallel tool calls — when a step requests several calls, Cursor reports how many (
tool_requests_listed); the provider emits them in one AI SDK step so OpenCode runs them at once. Only calls it can tell are read-only run together: reads, searches, web fetches, subagents, waits, MCP tools whose name says they read, and shell lines made only of known read-only commands (git status,rg,ls,gh pr view, …). An edit, a write, any other shell command (including every background shell) or MCP tool starts only after the calls the model wrote before it finish, and the calls after it wait for it, in Cursor'stool_call_startedorder. Debug logs showstep-order: HELD/released. - Retries — an error Cursor sends three minutes or more into a step gets one retry; a second one with no progress in between ends the turn and suggests smaller steps. A Run Cursor refuses for capacity (
resource_exhausted,unavailable, HTTP 429/503) gets six attempts per turn over about a minute, apart from the normal budget. The stall deadline is held for the length of a Cursor-side AwaitShell wait. - Background shells on OpenCode 2.x — when a managed background shell ends, the plugin posts a completion note like OpenCode's own (exit code, last lines, record path), which starts a turn when the session is idle. Watches live in memory, so a server restart drops them.
- Compaction — when Cursor does not hold the host history (another model answered, no checkpoint, a history rewrite, a restart or a lost Run while tool calls were unanswered, a held turn that ended without
turn_ended, a request or steer Cursor never checkpointed or answered, or a model-switch stop rolled back past host tools or its own request), the history is first imported into a fresh conversation, then summarized. A summary that is empty, model marker tokens or under 100 visible characters once they are removed, or whose Run stores no new checkpoint, is asked for again once; a second one fails the compaction and the conversation keeps its checkpoint.
- 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: [email protected]From 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). Unlike Cursor CLI, a Run that owes the host nothing and sends only heartbeats for 15 minutes (continuation.heartbeatOnlyIdleMs) after its last other frame, delivered result, finished upload, or the block of a Cursor-side AwaitShell, ends with CURSOR_HEARTBEAT_ONLY_TIMEOUT and is retried like a server failure (at most 3 per turn); the debug log notes every 5 minutes of such silence.
| 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_PROVIDER_RPC_TIMEOUT_MS |
Per-attempt budget of AvailableModels / GetServerConfig (default 5000, at most 600000); a failed attempt is tried once more, and the 2.x cold-start readiness budget grows with it |
CURSOR_GET_SERVER_CONFIG_TELEMETRY |
1 / true to opt GetServerConfig into telemetry |
CURSOR_ALLOW_MODEL_FALLBACK |
1 / true lets a turn go on when Cursor's safety filter answers with another model (see Known limitations) |
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_TOOL_NICE |
2.x, Linux / macOS: nice increment for tool-call shells (default 10, at most 19, 0 off), so a busy test suite can't starve the OpenCode server; on Linux they also get OOM score 1000 |
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, saved at each turn end and once a Run has waited a second on host tools (a
question, a permission prompt, a long shell); 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
- A safety-filter model switch stops the turn — Cursor's safety filter can answer with another model (Claude Opus 4.8 for Opus 5.5) and marks the step it stores (a
fallbackblock). The provider stops the turn at the first marked step, ends it with a message naming both models, what already ran and the two choices, and moves the session to a fresh conversation from the checkpoint before that step. Rephrase to try the requested model again, or reply exactlycontinue with opus 4.8to resend the request and accept the other model for that turn.CURSOR_ALLOW_MODEL_FALLBACK=1turns the stop off. Limits:- Cursor stores a step only after its tool results, so the first switched step's tool calls have already run; the message lists them and the next request is told.
- The switched step's text stays visible above the message, though it is not kept.
- Accepting resends the stopped request's text, not its attached files.
- The reply counts as the override only when it is the user's only message after the stop. If its first Run is restarted before any output, it is handled as an ordinary message. A switch in a step whose pending tool a new user turn cancels is not caught.
- Early steers on OpenCode 2 have gaps — a plain-text steer sent mid-step is injected into the Run and answered there; the copy OpenCode promotes at the next step boundary is not sent again. Gaps:
- OpenCode records the promoted message after the reply that answered it; a Run without a checkpoint (history import or rebase) replays it as it stands.
- If auto-compaction runs exactly where an answered steer is promoted, it is answered again.
- A steer whose injection crosses Cursor's end of turn fails that turn.
- A steer Cursor did not take in time goes out as a follow-up Run; if the user stops that Run, a later promotion of the steer alone is dropped.
- During a background-shell wake, a new turn with a different model can be injected into the wake's Run, on the old model.
- A message with files promoted together with a later, answered plain steer does not reach Cursor.
See CHANGELOG.md.
