feat(opencode): forward Claude Code session ID as x-opencode-session - #166
Open
alecchen wants to merge 2 commits into
Open
feat(opencode): forward Claude Code session ID as x-opencode-session#166alecchen wants to merge 2 commits into
alecchen wants to merge 2 commits into
Conversation
OpenCode Go requires an x-opencode-session header (one stable ID per conversation) or requests may error after 09/06. Claude Code sends the conversation UUID as x-claude-code-session-id on every /v1/messages request; forward it verbatim to OpenCode Go so it can group requests by conversation. - Resolve the inbound header once in HandleMessages and carry it via context (core.WithSessionID / SessionIDFromContext), so it reaches every provider call and every fallback attempt. - Set x-opencode-session in all OpenCode Go request builders (provider executeAnthropic/streamAnthropic/doRequest, plus the legacy client's ChatCompletion/SendAnthropicRequest/ResponsesCompletion/ GeminiCompletion). - Scope: OpenCode Go only. Zen, Bedrock, and OpenRouter are untouched. - Missing inbound header falls back to a per-request UUID so the upstream header is always present. - Tests cover streaming + non-streaming propagation, same/different session stability, UUID fallback, fallback-attempt sharing, and the Zen/Bedrock/OpenRouter scope boundary. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
alecchen
marked this pull request as ready for review
September 3, 2026 15:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
OpenCode Go uses an
x-opencode-sessionheader to group requests by conversation, and has said requests without it may error after 09/06. Claude Code 2.1.259 already sends the conversation UUID asx-claude-code-session-idon every/v1/messagesrequest. The proxy was dropping that header. This change forwards it verbatim to OpenCode Go.The value is stable across turns in one conversation and differs between conversations. It is the same UUID Claude Code uses for its local transcript.
Design
HandleMessages, right after theX-Request-IDblock and before any dispatch. Carry it oncontext.Contextviacore.WithSessionID/SessionIDFromContext, so every provider call and every fallback attempt sees the same value.x-opencode-sessionin every OpenCode Go request builder: the provider'sexecuteAnthropic,streamAnthropic, anddoRequest(chat and Responses), plus the legacy client'sChatCompletion,SendAnthropicRequest,ResponsesCompletion, andGeminiCompletion.config.ProviderOpenCodeGo.Tests
Stream. A Zen request omits the header end to end.x-opencode-sessionabsent, and check opencode-go sets it while opencode-zen does not.go test -race ./...passes across all packages.make lintand gofmt are clean.🤖 Generated with Claude Code