GitHub - abyesilyurt/cursor-tab: Reverse-engineered Cursor tab completion client

1 min read Original article ↗

cursor_tab

Reverse-engineered Cursor tab completion client.

Install

Usage

from cursor_tab import CursorCompletionClient, apply_diff

client = CursorCompletionClient()
result = await client.complete("main.py", contents, line=6, col=27, language="python")
completed = apply_diff(contents, result.diff)

Example

Input (main.py with cursor at end of line 7):

def greet(name: str) -> str:
    return f"Hello, {name}!"


def main():
    fun = functools.partial(g|  # <- cursor here

Output (completed code):

import functools

def greet(name: str) -> str:
    return f"Hello, {name}!"


def main():
    fun = functools.partial(greet, "World")

Test it yourself, it will complete the file and overwrite it:

python examples/simple_completion.py examples/main.py

How It Works

Cursor's tab completion (Copilot++) uses Connect RPC over HTTP/2 to stream completions from their API.

Key Points

  • Endpoint: https://api2.cursor.sh/aiserver.v1.AiService/StreamCpp
  • Protocol: Connect RPC (protobuf over HTTP/2, not gRPC)
  • Auth: JWT token stored in ~/Library/Application Support/Cursor/User/globalStorage/state.vscdb

Request Flow

  1. Read auth token from Cursor's SQLite database
  2. Build protobuf request with file contents and cursor position
  3. POST to StreamCpp endpoint with Connect protocol headers
  4. Parse streaming response, extract completion text

Required Headers

Authorization: Bearer <jwt>
Content-Type: application/connect+proto
Connect-Protocol-Version: 1
x-cursor-client-version: 3.0.16