-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(cli): align Claude adaptive thinking detection #12617
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -606,31 +606,21 @@ function openaiCompatibleReasoningEfforts(id: string) { | |
| return gpt5CodexReasoningEfforts(apiId) ?? versionedGpt5ReasoningEfforts(apiId) ?? OPENAI_EFFORTS | ||
| } | ||
|
|
||
| function anthropicOpus47OrLater(apiId: string) { | ||
| // Matches "opus-4.7" (Anthropic/Bedrock/Vertex) and "claude-4.7-opus" (SAP AI Core inverted). | ||
| // Greedy \d+ correctly extends to multi-digit majors (e.g. "claude-10.0-opus") for forward compatibility. | ||
| const version = /opus-(\d+)[.-](\d+)(?:[.@-]|$)|claude-(\d+)[.-](\d+)-opus(?:[.@-]|$)/i.exec(apiId) | ||
| if (!version) return false | ||
| const major = Number(version[1] ?? version[3]) | ||
| const minor = Number(version[2] ?? version[4]) | ||
| function anthropicUsesModernAdaptiveThinking(apiId: string) { | ||
| if (!apiId.toLowerCase().includes("claude-")) return false | ||
| // Covers family-first IDs such as claude-opus-4.7 and version-first IDs such as claude-4.7-opus. | ||
| // Limit minors to two digits so release dates in IDs such as claude-opus-4-20250514 are not versions. | ||
| const version = /claude-(?:[a-z]+-)?(\d+)(?:[.-](\d{1,2}))?(?:[.@-]|$)/i.exec(apiId) | ||
| if (!version) return true | ||
| const major = Number(version[1]) | ||
| const minor = Number(version[2] ?? 0) | ||
| return major > 4 || (major === 4 && minor >= 7) | ||
| } | ||
|
|
||
| // kilocode_change start - Claude 5+ models are adaptive thinking models like opus-4.7/4.8 | ||
| function anthropicClaude5(apiId: string) { | ||
| const id = apiId.toLowerCase() | ||
| if (id.includes("fable")) return true | ||
| const version = /(?:opus|sonnet)[.-](\d+)(?:[.@-]|$)|claude-(\d+)(?:[.-]\d+)?-(?:opus|sonnet)(?:[.@-]|$)/.exec(id) | ||
| return Number(version?.[1] ?? version?.[2]) >= 5 | ||
| } | ||
| // kilocode_change end | ||
|
|
||
| function anthropicAdaptiveEfforts(apiId: string): string[] | null { | ||
| // kilocode_change start - include Claude 5+ models | ||
| if (anthropicOpus47OrLater(apiId) || anthropicClaude5(apiId)) { | ||
| if (anthropicUsesModernAdaptiveThinking(apiId)) { | ||
| return ["low", "medium", "high", "xhigh", "max"] | ||
| } | ||
| // kilocode_change end | ||
| if ( | ||
| ["opus-4-6", "opus-4.6", "4-6-opus", "4.6-opus", "sonnet-4-6", "sonnet-4.6", "4-6-sonnet", "4.6-sonnet"].some((v) => | ||
| apiId.includes(v), | ||
|
|
@@ -642,7 +632,7 @@ function anthropicAdaptiveEfforts(apiId: string): string[] | null { | |
| } | ||
|
|
||
| function anthropicOmitsThinking(apiId: string) { | ||
| return anthropicOpus47OrLater(apiId) || anthropicClaude5(apiId) // kilocode_change - include Kilo's Claude 5 aliases | ||
| return anthropicUsesModernAdaptiveThinking(apiId) | ||
| } | ||
|
|
||
| function googleThinkingLevelEfforts(apiId: string) { | ||
|
|
@@ -982,7 +972,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a | |
| if ( | ||
| model.api.id.includes("opus-4.7") || | ||
| model.api.id.includes("opus-4.8") || | ||
| anthropicClaude5(model.api.id) | ||
| anthropicUsesModernAdaptiveThinking(model.api.id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Redundant substring checks now dead code
Reply with |
||
| ) { | ||
| efforts = ["medium"] | ||
| } | ||
|
|
||
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.
WARNING: Unversioned
claude-IDs silently default to "modern adaptive"When the regex doesn't match at all (
!version), the function now returnstrueinstead of the oldfalse. In practice every current test case that reaches this function has a digit somewhere in the id (e.g.claude-fable-5matches viamajor=5), so this fallback branch is currently untested. A future unversioned alias for a non-adaptive/legacy Claude model (no digits at all afterclaude-) would be misclassified as using modern adaptive thinking, which changes request shape (thinking/reasoning params) sent to the provider. Consider either keeping the previous safer default (false) for truly unversioned ids, or add a test that exercises this exact fallback path so a future regression is caught.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.