Install
Install with PiG
pig install npm:@rifle-donkey/pi-cursor-providerInstall with Pi
pi install npm:@rifle-donkey/pi-cursor-providerPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.4.1 (README.md). PiG does not review it.
pi-cursor-provider
A Pi coding agent extension that adds a cursor provider, so Pi can use the models on your Cursor account. There are two ways to connect, both offered by /login:
- Cursor account (
/login→ Sign in with an account → Cursor). This is the browser login the Cursor CLI uses. Chat goes over Cursor's own agent protocol (agent.v1.AgentService/Run), the same way thecursor-agentCLI talks to Cursor. This protocol is private and reverse-engineered, see Terms of service. - Cursor API key (
/login→ Sign in with an API key → Cursor). This uses Cursor's official TypeScript SDK,@cursor/sdk.
Either way, Pi stays in charge of tools. Cursor's built-in tools are disabled, Cursor sees Pi's tools as MCP tools, and Pi runs them with its usual permissions and hooks.
This is an unofficial integration and is not affiliated with Cursor or Pi.
Requirements
- Pi (
@earendil-works/pi-coding-agent) 1.5 or newer - Node.js 22.13 or newer
- A Cursor account (for the account login) or a Cursor API key
Install
pi install npm:@rifle-donkey/pi-cursor-provider
The npm package pi-cursor-provider (without the scope) is a different project.
This package registers the provider id cursor, as do other community Cursor providers. Install only one of them: run pi list, and pi remove <source> for any other Cursor provider.
Log in
Cursor account
Run /login, choose Sign in with an account, then Cursor. Pi shows a cursor.com/loginDeepControl link. Open it, sign in, and Pi picks up the session within a few seconds: it polls api2.cursor.sh/auth/poll with a PKCE verifier. Pi stores the session in ~/.pi/agent/auth.json and refreshes it through api2.cursor.sh/oauth/token before it expires. When Cursor ends the session, the next request asks you to log in again. The same flow is available from the shell with pi auth login cursor.
For headless use, a Cursor session access token in CURSOR_ACCESS_TOKEN also selects this route.
Cursor API key
Run /login, choose Sign in with an API key, then Cursor. There are two options:
- Paste a Cursor API key created in the Cursor dashboard. The provider checks it with Cursor before saving it, and a key Cursor rejects is not stored.
- Sign in with the browser. This runs the SDK's own login (
Cursor.auth.login), which mints a user API key namedpi-cursor-providerthat expires after 90 days.
Without a stored login, the provider reads CURSOR_API_KEY.
Pi keeps one Cursor credential at a time; logging in again replaces it. The provider picks the route from the credential: a session token (a JWT) uses the agent protocol, and an API key uses the SDK. Run pi auth logout cursor to remove a stored login.
Use
Pick a Cursor model with /model, or with --model cursor/<id>, for example --model cursor/claude-opus-5:high. The model list comes from your login: AvailableModels, narrowed by GetUsableModels, for an account, or Cursor.models.list() for an API key. It refreshes at startup and is cached for offline starts. Before the first successful fetch, only cursor/composer-2 is listed.
Pi thinking levels (off through max) map onto each model's Cursor parameters: effort or reasoning values, and the boolean thinking toggle. Levels a model doesn't offer are marked unsupported, so Pi clamps them. Other parameters, such as context or fast, use the model's default variant. On the account route, a request names the matching variant's own id (for example claude-opus-5-high), as the Cursor CLI does.
Commands:
| Command | What it does |
|---|---|
/cursor-status | Shows which login is in use (account email or API-key owner), the route, the number of models, and open Cursor conversations |
/cursor-doctor | Checks login state, token expiry, active route, api2.cursor.sh reachability (HTTP/2 probe), client version override, and model list health. Does not use the Cursor desktop app or cursor-agent CLI |
/cursor-usage | For account logins, reads plan usage, on-demand spend, and recent billing events from Cursor's dashboard API, plus token totals for this Pi session from the transcript. SDK logins show session totals only |
/cursor-refresh-models | Fetches the Cursor model catalog again |
Use as a library
The package exports the provider factory:
import { createCursorProvider } from "@rifle-donkey/pi-cursor-provider";
const { provider } = createCursorProvider();
How it works
Cursor runs an agent loop on its side and calls tools on the client. Both routes bridge that loop to Pi's own tool loop:
- Pi's tools are offered to Cursor as MCP tools, and Cursor's native tools are disabled.
- When the model calls a tool, the provider emits it to Pi as a normal tool call and ends the Pi turn with
toolUse, leaving Cursor's run waiting ("parked"). - Pi runs the tool. On Pi's next request, the provider delivers the result to the waiting call and the same Cursor run continues streaming.
- If Pi's next request isn't exactly those results (you interrupted, forked, compacted, or switched models mid-loop), the parked run is cancelled and a new one starts from Pi's transcript.
The account route talks to Cursor's agent host over HTTP/2 and falls back to HTTP/1.1 when HTTP/2 is unavailable. Failed requests are retried once for region, Max Mode and resource_exhausted errors, before any output reaches Pi. The API-key route runs a local @cursor/sdk agent on an empty in-memory file tree. Protocol details: docs/architecture.md.
Errors
Failures are classified by Cursor's error name and message, on both routes.
- Context overflow (
ERROR_CONVERSATION_TOO_LONG, "prompt is too long", …) is reported as "Cursor: context window exceeded", which Pi recognizes, so it compacts and retries. - Region errors say that logging in again won't help.
- Auth errors point to
/login cursor. - Rate limits and usage limits keep their 429 status for Pi's own retry handling.
Configuration
All settings are optional environment variables.
| Variable | Default | Meaning |
|---|---|---|
CURSOR_API_KEY | API key used when no login is stored (SDK route) | |
CURSOR_ACCESS_TOKEN | Cursor session token used when no login or API key is set (account route) | |
PI_CURSOR_CLIENT_VERSION | cli-2026.09.23-86fc751 | Cursor CLI build announced on the account route. Cursor gates protocol features on it; set a newer released cursor-agent version if Cursor starts rejecting requests. |
PI_CURSOR_TRANSPORT | auto | Account route transport: auto (HTTP/2, with HTTP/1.1 fallback), h2, or h1 |
PI_CURSOR_AGENT_BASE_URL | discovered per account | Fixed HTTP/2 Run host for the account route; skips GetServerConfig |
PI_CURSOR_API_BASE_URL | https://api2.cursor.sh | Cursor API host: model lists, agent host lookup, and the HTTP/1.1 fallback |
PI_CURSOR_SYSTEM_PROMPT_MODE | rules | SDK route only. rules sends Pi's prompt as the project rule file (AGENTS.md) of the SDK's in-memory workspace. replace uses the SDK's systemPrompt option, which Cursor enables per account; without that, the first request fails with InvalidArgument. |
PI_CURSOR_MAX_TOOL_RESULT_BYTES | 38000 | Tool results sent to Cursor are cut to this size, below Cursor's 40 KB MCP spill-to-file threshold |
PI_CURSOR_TOOL_SETTLE_MS | 250 | How long to wait for more parallel tool calls before handing a batch to Pi, when Cursor didn't say how many to expect |
PI_CURSOR_IDLE_TIMEOUT_MS | 3600000 | Parked runs, held native runs, and idle conversations are closed after this long |
PI_CURSOR_HOLD_RUNS | on (0 disables) | Keep HTTP/2 native runs open between Pi turns instead of only checkpoint reuse |
PI_CURSOR_STATE_DIR | ~/.pi/agent/cursor-sdk | Where the Cursor SDK keeps local agent state (SDK route) |
Terms of service
The account route uses Cursor's private agent protocol and the CLI's login, outside Cursor's published APIs. Cursor's terms forbid reverse engineering the service and accessing it by unpermitted means, so using this route can get an account flagged or suspended. The protocol can also change without notice, since Cursor gates features on the announced client version. The schema in proto/cursor_agent.proto is a subset written for this package; its message shapes and field numbers follow the reverse-engineered schema in oh-my-pi (MIT). The API-key route uses only Cursor's official SDK.
Limitations
Both routes:
- No pricing data. Cost shows 0. Token counts come from Cursor's usage events.
- Model limits are estimates. The context window comes from the
contextparameter or Cursor's context limit, else 200K. Max output is assumed to be 32K. Pi's temperature and max-token options are ignored. - Parked runs live in memory. After a restart, fork, compaction, interrupted tool call, or model switch mid tool loop, the next request starts a new Cursor run from Pi's transcript.
- Large tool results are truncated to
PI_CURSOR_MAX_TOOL_RESULT_BYTES. - Cursor's native tools are off: file and shell tools, web search, subagents and planning.
- One provider id. This package collides with other packages that register
cursor.
Account route:
- Checkpoints and held runs. On the native route, Cursor's
conversationCheckpointUpdateblobs are cached per Pi session and reused on the next turn when Pi's history still lines up (no compaction fork). By default the HTTP/2 stream also stays open for up to an hour (PI_CURSOR_IDLE_TIMEOUT_MS,PI_CURSOR_HOLD_RUNS) so the follow-up can send anotherrunRequeston the same connection. If the stream is gone, a new run starts from the checkpoint instead of replaying the full transcript. Thinking from earlier turns still isn't replayed, and each earlier tool result is capped at 30 KB. - No parking over HTTP/1.1. On the fallback transport, tool calls are handed off and each tool round trip is a new run.
- Approval probes are approved. Cursor's "may this MCP call run?" probe is answered yes, because Pi applies its own permissions when it runs the tool.
API-key route:
- Cursor's prompt stays in place. Pi's prompt is a project rule on top of Cursor's harness prompt, unless the account has the
systemPromptfeature. - Text replay. When a new SDK agent is needed, the transcript is replayed as text, which costs extra input tokens and drops earlier images.
Development
Developer setup, tests and code layout: AGENTS.md.
License
MIT. The schema subset in proto/ credits oh-my-pi (MIT; Copyright (c) 2025 Mario Zechner, 2025-2026 Can Bölük, 2026 Stencil Labs, Inc.) for the message shapes and field numbers it follows. The runtime dependency @cursor/sdk is distributed by Cursor under its own proprietary license (see the license file in the @cursor/sdk package).