Files
plugins/packages/cursor
geoqiao cf0de01e2a cursor 0.2.1: an id 0.1.x listed, at an effort only its other branch has, goes as its own branch's nearest, not as the default's id with parameters that contradict it (review of #51) (#54)
An old id names a branch of a model's variants (claude-opus-5 is the Opus 5
without thinking). When the effort asked for exists only in the other branch,
no variant matched and the request went as the default's legacySlug with the
parameters it had been given: cursor/claude-opus-5 at xhigh went as
claude-opus-5-thinking-high with thinking=false, effort=xhigh. On this
account Opus 5 without thinking stops at high, so it happens today: 40 of
5040 old id × effort × fast combinations, all claude-opus-5. 0.1.11 sent
claude-opus-5-high there.

Now, for an old id, a request no variant matches goes as the variant of
its own branch (every parameter but the effort as asked) at the nearest
effort it has (branch()): claude-opus-5 at xhigh or max is claude-opus-5-high,
-fast at xhigh is claude-opus-5-high-fast, as 0.1.11 sent them. Where the
default differs from what is asked in the effort alone, the effort still goes
as asked. A listed id is not changed.

context.test.mjs adds a picker shaped like this account's Opus 5 and checks
those cases and that every id sent agrees with its parameters (which holds
where the default's branch is complete, as in this picker; see Not covered);
it fails on 8cd5a0f's index.mjs. HOME=$(mktemp -d) bun test packages/cursor:
49 pass, 0 fail; check.mjs cursor passes. Offline against this account's
picker and usable list: the contradicting requests go from 40 to 0.

With a real Cursor account, this version installed into magpie (packed from
this code plus one temporary line logging what request() returns):
cursor/claude-opus-5 at reasoning_effort xhigh (max_tokens 16) went as
claude-opus-5-high with thinking=false, context=300k, effort=high,
fast=false, maxMode=false, and answered 200 ("ok", 14 in / 4 out, 5.2s;
magpie's usage log: effort xhigh, status 200). On 0.2.0 the contradicting
request cursor/claude-opus-5-low at xhigh also answered 200, so it failed
silently.

Not covered. branch() steps aside when what is asked differs from the
default variant in the effort alone, so that an effort goes as asked, as
for a listed model (the existing claude-opus-5-5-xhigh test expects
effort=xhigh). So when the branch that stops short is the default's own,
the request still goes as the default's slug with the effort asked: with a
default of m-high (no thinking, low to high) and a thinking branch up to
max, m at xhigh goes as m-high with effort=xhigh. Dropping that early
return fixes it (effort=high) and changes that one assertion; left for the
maintainer to decide. On this account no model's default branch is the
shorter one (of 20 models with two or more branches, only non-default
branches stop short: claude-opus-5's without thinking, and gpt-5.4's fast
one after the usable list).
2026-10-09 00:25:32 +08:00
..
cursor 0.1.10: far from Cursor a conversation's tool steps add up to what Cursor counted, cache included (yetone/magpie#1053, #33). The tool-step usage-event wait of 0.1.9 (first ask at 1.5 s, every 0.5 s, up to 6 s) never met an event on the reporter's network (Windows, mainland China: a GetFilteredUsageEvents round trip of ~4.2 s, the event 4–5 s after the Run closes), so tool steps were counted as their whole prompt estimated with no cache (fable 13/13 steps, 0% cached; opus 27%) where Cursor counted 95–99%, and every tool step waited the full 6 s. A tool step's Run is now owed by its conversation (only when a conversation_id names the session): the step counts every event of the conversation's owed Runs that shows within the same wait, its own or earlier ones, and says 0 used when none has; the conversation's next Runs collect the rest in the background from 5 s after the owed Run closed, and a step that ends the turn waits for whatever is still owed (in-flight collections, then a poll for the rest). Events are claimed once, by count, so the conversation's prompt, cache read, cache write and output add up to Cursor's dashboard, some of it a step late. After 3 steps in a row left something owed an account's tool steps stop waiting (asked again every 10th). A Run that fails after collecting gives it back; an account that can't read its events (4xx) and a Run with no session id are estimated as before. latency.test.mjs runs whole conversations through the plugin against a fake Cursor with the reporter's latency scaled 1/20 and the reporter's literal events (in 2 / cacheRead 63457 / cacheWrite 3081, in 2 / 66538 / 14756, in 4 / 67872 / 2392): on 0.1.9 the 3-step conversation sums to 137936 prompt / 131329 cached instead of 218104 / 197867, and skipped steps still wait the full window (292 ms > 150); both pass now, 20 of 20 runs, and stepusage + latency pass with --rerun-each 20. HOME=$(mktemp -d) bun test: 682 pass, 0 fail; check.mjs cursor passes. Not tried with a real Cursor account on a high-latency network.
2026-10-07 03:17:08 +08:00
cursor 0.1.10: far from Cursor a conversation's tool steps add up to what Cursor counted, cache included (yetone/magpie#1053, #33). The tool-step usage-event wait of 0.1.9 (first ask at 1.5 s, every 0.5 s, up to 6 s) never met an event on the reporter's network (Windows, mainland China: a GetFilteredUsageEvents round trip of ~4.2 s, the event 4–5 s after the Run closes), so tool steps were counted as their whole prompt estimated with no cache (fable 13/13 steps, 0% cached; opus 27%) where Cursor counted 95–99%, and every tool step waited the full 6 s. A tool step's Run is now owed by its conversation (only when a conversation_id names the session): the step counts every event of the conversation's owed Runs that shows within the same wait, its own or earlier ones, and says 0 used when none has; the conversation's next Runs collect the rest in the background from 5 s after the owed Run closed, and a step that ends the turn waits for whatever is still owed (in-flight collections, then a poll for the rest). Events are claimed once, by count, so the conversation's prompt, cache read, cache write and output add up to Cursor's dashboard, some of it a step late. After 3 steps in a row left something owed an account's tool steps stop waiting (asked again every 10th). A Run that fails after collecting gives it back; an account that can't read its events (4xx) and a Run with no session id are estimated as before. latency.test.mjs runs whole conversations through the plugin against a fake Cursor with the reporter's latency scaled 1/20 and the reporter's literal events (in 2 / cacheRead 63457 / cacheWrite 3081, in 2 / 66538 / 14756, in 4 / 67872 / 2392): on 0.1.9 the 3-step conversation sums to 137936 prompt / 131329 cached instead of 218104 / 197867, and skipped steps still wait the full window (292 ms > 150); both pass now, 20 of 20 runs, and stepusage + latency pass with --rerun-each 20. HOME=$(mktemp -d) bun test: 682 pass, 0 fail; check.mjs cursor passes. Not tried with a real Cursor account on a high-latency network.
2026-10-07 03:17:08 +08:00

@magpie-community/opencode-cursor-auth

Signs in to a Cursor subscription (Pro, Pro+, Ultra, Teams) and makes its requests on the API cursor-agent talks to, in OpenCode and in magpie. Provider id: cursor.

Signing in

An account is a Cursor access token. There are three ways to get one:

  • Cursor (browser): the sign-in cursor-agent login does. The page cursor.com/loginDeepControl is opened with a PKCE challenge, and the plugin polls api2.cursor.sh/auth/poll until the browser has signed in. The account is named by its email (DashboardService/GetMe).
  • cursor-agent's sign-in: takes the account cursor-agent login signed in to. Its token is read on every request from where the CLI keeps it: the macOS keychain (cursor-access-token), else its auth.json (~/.cursor/, $XDG_CONFIG_HOME/cursor/ or %APPDATA%\Cursor\). The plugin never writes it; when it has less than 5 minutes left, cursor-agent status is run, which renews it.
  • Cursor API key: a key from cursor.com/dashboard → Integrations. It is exchanged for a token at /auth/exchange_user_api_key, as the CLI does with CURSOR_API_KEY, and exchanged again when the token runs out.

Sign-ins are kept where OpenCode keeps them (auth.json; in magpie, plugin-auth.json). A browser sign-in's token lasts about two months. Cursor gives the CLI no way to renew it, so after that you sign in again.

Requests

OpenCode speaks chat completions (@ai-sdk/openai-compatible); the plugin's fetch answers them on Cursor's agent API:

  • The agent API is the one ServerConfigService/GetServerConfig names for the account (a team may be served in one region only), else agentn.global.api5.cursor.sh. A refusal that names a region is tried once more with the config asked again.
  • Each request is one agent.v1.AgentService/Run, a Connect stream both ways over HTTP/2, with the CLI's headers (x-cursor-client-type: cli, its version, privacy mode on).
  • The whole conversation goes each time, as AI SDK messages kept as blobs the server asks for. The caller's tools are MCP tools, listed in the system prompt; the model calls them through Cursor's CallDynamicTool, and the calls come back as chat completion tool calls. Cursor's own tools (shell, file reads, edits) are never run.
  • A conversation's Runs share one conversation_id, so Cursor sends them to the machine that has the prompt cached (Grok on Cursor caches by machine). It is made from what names the session — the request's prompt_cache_key (Codex's thread id), else the session the chat.headers hook is told — and the conversation's first user message, so subagents under one session are conversations of their own. With nothing naming the session, each Run has a new one.
  • Text, thinking (reasoning_content) and token usage come back streamed or not. Cursor's input_tokens counts the cached prompt too: the cache read and written is taken out of it, and given as cached_tokens and cache_write_tokens, so it is counted once; its reasoning tokens are reasoning_tokens. A step that calls tools gets no usage in its Run (Cursor tells it only once the tools' results come back in the same Run), so once the Run is closed its usage is read from the dashboard's usage events, by the Run's conversation id: it shows in about 2.5 s, and is looked for up to 6 s. Far from Cursor it shows later than that (yetone/magpie#1053), so the step says 0 used and the conversation owes it: its next steps collect the event in the background and count it with their own, and a step that ends the turn waits for what is still owed, so the conversation adds up to what Cursor counted. An account whose events miss the wait 3 steps in a row stops waiting for them. With nothing naming the session (so no later step to collect it), or an account that can't read its usage events, the step is estimated as before. Failures keep their statuses: 401 to sign in again, 429 at the usage limit, 400 for a prompt too long, 403 for a region refusal.

Models

The config hook declares auto (Cursor's pick). Once signed in, the provider.models hook lists the account's models from Cursor's model picker (AiService/AvailableModels, as the CLI asks for it, cached 10 minutes), the way pi-cursor-sdk lists Cursor's catalog:

  • A model with a context parameter is listed once per size, as <model>@<size> named <name> @ <size> (claude-opus-5-5@300k, "Claude Opus 5.5 @ 300k"), its window that many tokens. A model with none is listed once, its window Cursor's contextTokenLimit (Max Mode's for a model served only in Max Mode); 200K when Cursor gives none.
  • Effort is not a model of its own: the model's efforts are its variants, and the request's reasoning_effort (fitted to the nearest there is) is sent as the model's effort parameter. none turns a Claude's thinking off.
  • Fast is not a model of its own either: a service_tier of priority or fast sends fast=true, anything else fast=false (it costs more, so only when asked).
  • A request goes as the picker's variant those parameters pick, in Max Mode when that variant is Max Mode's (a 1M size, say), as the CLI turns it on. A size with no variant goes in Max Mode when it is over Cursor's limit outside it. A model Cursor still answers "Max Mode Required" for is asked again in Max Mode, and so from then on.
  • Hidden, Tab-only and chat-only models stay out, as in the CLI's picker.
  • The usable list (AgentService/GetUsableModels, what cursor-agent models shows) says which variants the account has: a variant whose own id isn't in it is neither offered nor asked for (Sonnet 4.6 at any effort but medium, say), and a request for one goes as the nearest the account has. A model the usable list has nothing of is the picker's alone (GLM-5.3) and is kept whole; so is every model when Cursor can't give the usable list.
  • An id from before 0.2.0 still runs. A variant's own id (claude-opus-5-5-high) is that variant; a family 0.1.x listed (claude-opus-5-5, claude-opus-5-5-fast, claude-haiku-5-5-thinking, cursor-grok-4.6) is its variant nearest the default, fast for a -fast one; the picker's name for a model or a legacy slug of it is its default. Each is at the default context size, the request's reasoning_effort and service_tier counting as for a listed model. The list doesn't show these ids: pick the @<size> model for a window that is the model's.

Not included

  • Usage and plan limits.
  • Web search: Cursor's own web search is refused like its other tools.
  • Switching between several accounts. OpenCode keeps one sign-in per provider.
  • The Responses and Messages APIs: only chat completions are answered.