Skip to content

fix: replay Opus reasoning, stream thinking, keep inline system messages - #7

Merged
voidsteed merged 1 commit into
masterfrom
fix/opus-reasoning-roundtrip
Sep 24, 2026
Merged

voidsteed merged 1 commit into
masterfrom
fix/opus-reasoning-roundtrip

Conversation

@voidsteed

Copy link
Copy Markdown
Owner

Summary

Opus 5.5 through the proxy was much slower than it needed to be, and Claude Code looked frozen during long turns. Three fixes:

  • Replay prior reasoning to Copilot. The proxy dropped earlier thinking blocks, so Opus worked out its plan again from scratch on every tool call. Signed thinking now goes back as reasoning_text and reasoning_opaque, which is what VS Code's Copilot client does. Unsigned blocks are still dropped.
  • Stream thinking to Claude Code. Copilot's reasoning_text and reasoning_opaque are forwarded as thinking_delta and signature_delta events, or as a thinking block when not streaming, so long turns show progress.
  • Keep inline role: "system" messages. Claude Code sends SessionStart hook context and reminders inside messages[]. They were stripped as an "assistant prefill" or attributed to the model. They now reach Copilot as user context, on both the chat-completions and Responses paths.

Results

Same real Claude Code 2.1.281 task (Opus 5.5, read 3 files and grep tests), run one at a time:

Effort Before After
xhigh 209 s / 266 s / 379 s 98 s / 99 s / 105 s
max didn't finish in 15 min 702 s

Tradeoffs

  • Prompts are 15–40% larger on long tool chains because reasoning is kept. Copilot still caches them.
  • The first 3–12 s of a turn stay silent. Copilot sends nothing, not even headers, before its first token.

Testing

  • bun test: 219 pass. New tests cover reasoning replay, signature-only blocks, thinking/signature streaming, and inline system messages.
  • Two of the new replay tests fail when replay is disabled. The third checks that unsigned reasoning is never replayed, which holds either way.
  • Typecheck and lint are clean.

🤖 Generated with Claude Code

- Send signed prior thinking back to Copilot as reasoning_text and
  reasoning_opaque. Dropping it made Opus re-plan on every tool turn;
  the same Opus 5.5 xhigh Claude Code task went from 209-379s to ~100s.
- Forward Copilot's reasoning_text/reasoning_opaque to Claude Code as
  thinking and signature deltas (and thinking blocks when not
  streaming), so long turns show progress instead of looking frozen.
- Keep role:"system" messages inside messages[] (SessionStart hook
  context, reminders) as user context. They were stripped as an
  assistant prefill or attributed to the model.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@voidsteed
voidsteed merged commit 822f839 into master Sep 24, 2026
1 check passed
@voidsteed
voidsteed deleted the fix/opus-reasoning-roundtrip branch September 24, 2026 16:13
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