Skip to content

fix(cursor): continue the Cursor conversation across Claude Code turns - #219

Open
joboyx wants to merge 4 commits into
raine:mainfrom
joboyx:fix/cursor-conversation-continuation
Open

joboyx wants to merge 4 commits into
raine:mainfrom
joboyx:fix/cursor-conversation-continuation

Conversation

@joboyx

@joboyx joboyx commented Nov 26, 2026

Copy link
Copy Markdown

Summary

  • Keep the Cursor conversation of each Claude Code session in memory, keyed by session id, model, rendered system prompt and tool list: the conversation id, the last conversation_checkpoint_update bytes and the agent-store blobs (the client now answers SetBlob and GetBlob).
  • When the next request extends the transcript that conversation saw, send the stored checkpoint in AgentRunRequest.conversation_state with only the new messages. An edited transcript, a compaction or a changed tool list starts a new conversation with the full prompt, as before.
  • When a text-protocol <tool_use> ends the stream early, drain the Cursor run to the end of its turn in the background, so that the checkpoint holds the call. The next request waits up to 30 s for it.
  • Log cursor_conversation (the outcome per request) and cursor_turn_usage (Cursor's input, output, cache-read and cache-write token counts).
  • CCP_CURSOR_CONTINUATION=off restores the old behaviour. The docs describe the switch; the old "Session continuation" text described a session mapping and cursor_chat_id metadata that the code does not have.
  • cursor_cli_logout_does_not_error ran the real logout and deleted the developer's Cursor sign-in. The logout test now runs against an isolated home.

Why

Each request used a new conversation id and flattened the system prompt, the transcript and the tools into one user message. Cursor's prompt cache matches only at block boundaries, so every turn wrote the whole context to the cache again.

Validation

  • cargo test --all passed (991 lib tests and all integration test files) with isolated configuration. cargo fmt --all -- --check and cargo clippy --all-targets -- -D warnings passed.
  • New unit tests cover the delta rules and the checkpoint frame encoding. New integration tests in tests/cursor_native.rs cover a continued next turn, a tool result after a text-protocol tool call, and a changed history.
  • Live comparison on the same binary with Claude Opus 5.5 (high effort) and a Claude Code context of about 43k tokens. Numbers come from Cursor's usage dashboard:
Turn Continuation Cache write tokens Cost
First turn on 42,486 26.6¢
Next 5 turns (one is a text-protocol tool result) on 170–615 3.2–6.4¢
Every turn (5 turns) off 42,439–44,275 24.3–27.4¢
  • An interactive Claude Code session showed the same result: after the first turn, three turns continued one Cursor conversation and wrote 155–650 tokens to the cache each. The model also recalled its answer from the first turn.

Every Cursor run started a new conversation and flattened the whole
Claude Code transcript into one user message. The prompt cache then
matched only Cursor's own system prompt, so each new turn, and each
request after a tool call recovered from the text channel, wrote the
full context to the cache again.

Keep the conversation of each Claude Code session, model, system prompt
and tool set: the conversation id, the last checkpoint (kept byte for
byte, since prost drops the fields this crate does not model) and the
agent-store blobs. When the next request extends the transcript the run
saw, send the checkpoint back with only the new messages. A run stopped
on a text-channel tool call reads its turn to the end in the background
so its final checkpoint holds the call; the next request waits for it.
Any mismatch starts a new conversation as before.

Log the upstream token counts of each run next to whether it continued,
and add CCP_CURSOR_CONTINUATION=off to turn the behaviour off.
cursor_cli_logout_does_not_error called the real logout in process, so
running the test suite deleted the developer's stored Cursor credentials.
Cover cursor logout in the CLI test that already runs kimi logout in a
subprocess with an empty config directory and home.
Claude Code adds a system-role message after each user turn when a hook or output style is active. Continuation required every message after the stored reply to be a user turn, so those sessions always started a new conversation. Accept any message except another assistant reply.
@joboyx
joboyx marked this pull request as ready for review November 26, 2026 03:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant