-
Notifications
You must be signed in to change notification settings - Fork 0
fix(anthropic): per-model thinking shape restores Claude reasoning on Copilot #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hunter-Thompson
merged 1 commit into
main
from
chat-our-sdk-anthropic-copilot-does-not-show-thinkning-l-wkeab8
Jul 7, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package anthropic | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Claude exposes two mutually incompatible extended-thinking request shapes, | ||
| // split by model generation: | ||
| // | ||
| // - thinking.type=enabled + budget_tokens: the classic shape, implemented by | ||
| // the 4.5-and-older generations (claude-haiku-4.5, claude-sonnet-4.5, | ||
| // claude-opus-4.5, claude-sonnet-4, claude-3-x). Effort-only models reject | ||
| // it (live 400: `"thinking.type.enabled" is not supported for this model. | ||
| // Use "thinking.type.adaptive" and "output_config.effort" ...`). | ||
| // - thinking.type=adaptive + output_config.effort: the effort-first shape | ||
| // introduced with the 4.6 generation (claude-sonnet-4.6, claude-opus-4.6+, | ||
| // claude-sonnet-5, claude-fable-5). Older models reject or ignore it — | ||
| // notably GitHub Copilot's /v1/messages shim returns no thinking blocks at | ||
| // all for adaptive requests against the 4.5 family, silently disabling | ||
| // visible reasoning. | ||
| // | ||
| // The split below mirrors the models.dev reasoning_options catalog for the | ||
| // "anthropic" and "github-copilot" providers (and opencode's per-model | ||
| // adaptive-thinking gating). Callers that guess wrong self-heal via the | ||
| // thinking-shape 400 retry in the providers layer. | ||
|
|
||
| // ModelSupportsAdaptiveThinking reports whether a Claude model accepts | ||
| // thinking.type=adaptive + output_config.effort: the fable family and every | ||
| // sonnet/opus/haiku generation from 4.6 upward. | ||
| func ModelSupportsAdaptiveThinking(model string) bool { | ||
| family, major, minor, ok := claudeThinkingGeneration(model) | ||
| if !ok { | ||
| return false | ||
| } | ||
| if family == "fable" { | ||
| return true | ||
| } | ||
| return major > 4 || (major == 4 && minor >= 6) | ||
| } | ||
|
|
||
| // ModelRequiresAdaptiveThinking reports whether a Claude model accepts ONLY | ||
| // the adaptive shape on the first-party Messages API, i.e. rejects | ||
| // thinking.type=enabled + budget_tokens: the fable family, opus 4.7+, and any | ||
| // generation 5 model. (claude-sonnet-4.6 and claude-opus-4.6 still accept | ||
| // budget_tokens on api.anthropic.com, so they are not in this set.) | ||
| func ModelRequiresAdaptiveThinking(model string) bool { | ||
| family, major, minor, ok := claudeThinkingGeneration(model) | ||
| if !ok { | ||
| return false | ||
| } | ||
| if family == "fable" { | ||
| return true | ||
| } | ||
| if major >= 5 { | ||
| return true | ||
| } | ||
| return family == "opus" && major == 4 && minor >= 7 | ||
| } | ||
|
|
||
| // claudeThinkingGeneration parses a Claude model identifier into its family | ||
| // and version. It tolerates the dotted (claude-sonnet-4.6), dashed | ||
| // (claude-sonnet-4-6), dated (claude-sonnet-4-5-20250929), and legacy | ||
| // version-first (claude-3-7-sonnet) naming forms; date stamps (>= 1000) are | ||
| // not version segments. ok is false for non-Claude models. | ||
| func claudeThinkingGeneration(model string) (family string, major, minor int, ok bool) { | ||
| normalized := strings.ToLower(strings.TrimSpace(model)) | ||
| if idx := strings.LastIndex(normalized, "/"); idx >= 0 { | ||
| normalized = normalized[idx+1:] | ||
| } | ||
| if !strings.Contains(normalized, "claude") { | ||
| return "", 0, 0, false | ||
| } | ||
|
|
||
| versionSeen := false | ||
| for _, token := range strings.Split(normalized, "-") { | ||
| switch token { | ||
| case "fable", "sonnet", "opus", "haiku": | ||
| if family == "" { | ||
| family = token | ||
| } | ||
| continue | ||
| } | ||
| if versionSeen && minor > 0 { | ||
| continue | ||
| } | ||
| // A token is a version segment when it is numeric ("4", "5") or | ||
| // dotted-numeric ("4.6"); 4+ digit numbers are date stamps. | ||
| for _, part := range strings.SplitN(token, ".", 2) { | ||
| n, err := strconv.Atoi(part) | ||
| if err != nil || n >= 1000 { | ||
| break | ||
| } | ||
| if !versionSeen { | ||
| major = n | ||
| versionSeen = true | ||
| } else if minor == 0 { | ||
| minor = n | ||
| } | ||
| } | ||
| } | ||
| if family == "" && !versionSeen { | ||
| return "", 0, 0, false | ||
| } | ||
| return family, major, minor, true | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package anthropic | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestModelThinkingShapeCapabilities pins the per-generation thinking-shape | ||
| // split mirrored from the models.dev reasoning_options catalogs: the 4.5 | ||
| // generation and older only implement enabled+budget_tokens, 4.6+/fable/5.x | ||
| // implement adaptive+output_config.effort, and only the effort-only models | ||
| // (fable, opus 4.7+, generation 5) reject enabled on the first-party API. | ||
| func TestModelThinkingShapeCapabilities(t *testing.T) { | ||
| cases := []struct { | ||
| model string | ||
| supports bool // ModelSupportsAdaptiveThinking | ||
| requires bool // ModelRequiresAdaptiveThinking | ||
| }{ | ||
| // Budget-only generation (Copilot's /v1/messages shim returns no | ||
| // thinking blocks for adaptive requests against these). | ||
| {"claude-haiku-4.5", false, false}, | ||
| {"claude-haiku-4-5", false, false}, | ||
| {"claude-haiku-4-5-20251001", false, false}, | ||
| {"claude-sonnet-4.5", false, false}, | ||
| {"claude-sonnet-4-5-20250929", false, false}, | ||
| {"claude-opus-4.5", false, false}, | ||
| {"claude-opus-4-5-20251101", false, false}, | ||
| {"claude-sonnet-4", false, false}, | ||
| {"claude-sonnet-4-20250514", false, false}, | ||
| {"claude-opus-4-1", false, false}, | ||
| {"claude-3-7-sonnet", false, false}, | ||
| {"claude-3-5-haiku-20241022", false, false}, | ||
|
|
||
| // Adaptive-capable, budget still accepted on api.anthropic.com. | ||
| {"claude-sonnet-4.6", true, false}, | ||
| {"claude-sonnet-4-6", true, false}, | ||
| {"claude-opus-4.6", true, false}, | ||
| {"claude-opus-4-6", true, false}, | ||
|
|
||
| // Effort-only models: adaptive everywhere. | ||
| {"claude-opus-4.7", true, true}, | ||
| {"claude-opus-4-7", true, true}, | ||
| {"claude-opus-4.8", true, true}, | ||
| {"claude-sonnet-5", true, true}, | ||
| {"claude-fable-5", true, true}, | ||
| {"claude-fable-5-20260601", true, true}, | ||
|
|
||
| // Prefixed model IDs are tolerated. | ||
| {"copilot/claude-sonnet-4.5", false, false}, | ||
| {"anthropic/claude-fable-5", true, true}, | ||
|
|
||
| // Non-Claude models never match. | ||
| {"gpt-5.2", false, false}, | ||
| {"gemini-3-pro", false, false}, | ||
| {"", false, false}, | ||
| } | ||
| for _, tc := range cases { | ||
| if got := ModelSupportsAdaptiveThinking(tc.model); got != tc.supports { | ||
| t.Errorf("ModelSupportsAdaptiveThinking(%q) = %v, want %v", tc.model, got, tc.supports) | ||
| } | ||
| if got := ModelRequiresAdaptiveThinking(tc.model); got != tc.requires { | ||
| t.Errorf("ModelRequiresAdaptiveThinking(%q) = %v, want %v", tc.model, got, tc.requires) | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a shape-related 400 is followed by a failed retry (for example a transient 429/5xx/network error, or the opposite shape is also invalid), this stores the flipped shape before any successful response proves it works. Because the same
AnthropicModelcan be reused for later attempts or turns, subsequent calls bypass the per-model heuristic and are forced to the unverified shape, causing avoidable repeated failures or silently disabling thinking for models that needed the original shape.Useful? React with 👍 / 👎.