Skip to content

Support adaptive thinking for Claude Opus 4.6 #12485

Closed

Description

@leeweisern

Anthropic has deprecated thinking.type: "enabled" with budget_tokens on Opus 4.6 and will remove it in a future release. The recommended replacement is adaptive thinking:

{
  "thinking": { "type": "adaptive" },
  "output_config": { "effort": "high" }
}

Docs: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking

Currently variants() in transform.ts uses the deprecated config for all Anthropic models, including Opus 4.6:

high: { thinking: { type: "enabled", budgetTokens: ... } },
max:  { thinking: { type: "enabled", budgetTokens: ... } },

A few things to consider:

  • Only Opus 4.6 supports adaptive — older models still need type: "enabled"
  • effort: "max" is Opus 4.6 exclusive
  • maxOutputTokens() assumes a known budgetTokens for the subtraction — adaptive doesn't have one
  • Depends on @ai-sdk/anthropic supporting type: "adaptive" upstream

Activity

  1. BouquetAntoine commented on Feb 6, 2026

    @BouquetAntoine

    OpenCode currently depends on @ai-sdk/anthropic v2.x. Simply bumping the dependency to v3.x and rebuilding isn't enough — there are several breaking changes in the SDK that need to be addressed in the codebase.

    Below is a summary of every breaking change identified so far, tried different fixes in my codebase but that's a lot of work.


    1. finishReason format change

    v2.x returns a plain string:

    finishReason: "end_turn" | "tool_use" | "stop_sequence" | ...

    v3.x returns an object with unified and raw properties:

    finishReason: {
      unified: "stop" | "tool-calls" | "error" | "other" | ...
      raw: string | undefined
    }

    2. usage token counts format change

    v2.x returns flat numbers:

    usage: {
      inputTokens: 1234,
      outputTokens: 567,
      cachedInputTokens: 100,
      reasoningTokens: 200,
    }

    v3.x returns nested objects:

    usage: {
      inputTokens:    { total: 1234, noCache: 1034, cacheRead: 200 },
      outputTokens:   { total: 567, text: undefined },
      reasoningTokens: 200, // may also be an object
    }

    3. New providerOptions schema (thinking / effort)

    v2.x supports a limited thinking config:

    thinking: {
      type: "enabled" | "disabled",
      budgetTokens?: number,
    }
    // No "effort" field

    v3.x adds an adaptive mode and a new top-level effort field:

    thinking: {
      type: "adaptive" | "enabled" | "disabled",
      budgetTokens?: number, // only required when type is "enabled"
    }
    effort: "low" | "medium" | "high" | "max" // NEW

    Fix

    Update config schema validation (e.g. Zod schemas or type definitions) to accept the new "adaptive" type and the effort field.


    Problem is that we probably need to update all ai-sdk to last version for compatibility across models

  2. avarayr commented on Feb 6, 2026

    @avarayr

    I was able to temporarily hack this to work until fix is in place.

    Note: this is not a long term solution, just an unblocker until this issue is fixed.

    // File: ~/.opencode/plugins/adaptiveThinking.ts
    export const adaptiveThinking: import("@opencode-ai/plugin").Plugin =
      async () => ({
          loader: async () => {
            return {
              fetch: async (url: RequestInfo | URL, init?: RequestInit) => {
                const body = init?.body
                  ? JSON.parse(init.body as string)
                  : undefined;
                  
                if (body?.thinking?.budget_tokens === -1) {
                  body.thinking = { type: "adaptive" };
                  return fetch(url, { ...init, body: JSON.stringify(body) });
                }
                return fetch(url, init);
              },
            };
          },
        },
    
        // Shim: rewrite adaptive -> enabled with sentinel budget so SDK Zod passes,
        // then the custom fetch above detects budget_tokens:-1 and patches to adaptive.
        "chat.params": async (_input, output) => {
          if (output.options?.thinking?.type === "adaptive") {
            output.options.thinking = { type: "enabled", budgetTokens: -1 };
          }
        },
      });
    // File: ~/.config/opencode/opencode.jsonc
    {
       "plugin": [
            "file:///Users/<USERNAME>/.opencode/plugin/adaptiveThinking.ts",
        ],
    	"provider": {
    	        "anthropic": { // <-- replace with your provider of choice
    	            "models": {
    	                "claude-opus-4-6@20260205": { // might need replacement based on provider
    	                    "id": "claude-opus-4-6",
    	                    "name": "Claude Opus 4.6",
    	                    "family": "claude-opus",
    	                    "attachment": true,
    	                    "reasoning": true,
    	                    "tool_call": true,
    	                    "temperature": true,
    	                    "knowledge": "2025-05",
    	                    "release_date": "2026-02-05",
    	                    "last_updated": "2026-02-05",
    	                    "modalities": {
    	                        "input": [
    	                            "text",
    	                            "image",
    	                            "pdf"
    	                        ],
    	                        "output": [
    	                            "text"
    	                        ]
    	                    },
    	                    "open_weights": false,
    	                    "cost": {
    	                        "input": 5,
    	                        "output": 25,
    	                        "cache_read": 0.5,
    	                        "cache_write": 6.25,
    	                        "context_over_200k": {
    	                            "input": 10,
    	                            "output": 37.5,
    	                            "cache_read": 1,
    	                            "cache_write": 12.5
    	                        }
    	                    },
    	                    "limit": {
    	                        "context": 200000,
    	                        "output": 128000
    	                    },
    	                    "variants": {
    	                        "adaptive": {
    	                            "thinking": {
    	                                "type": "adaptive" // special case handled by plugin
    	                            }
    	                        },
    	                        "high": {
    	                            "thinking": {
    	                                "type": "enabled",
    	                                "budgetTokens": 16000
    	                            }
    	                        },
    	                        "max": {
    	                            "thinking": {
    	                                "type": "enabled",
    	                                "budgetTokens": 128000
    	                            }
    	                        }
    	                    }
    	                }
    	            }
    	        }
    	    },
    }
  3. BouquetAntoine commented on Feb 6, 2026

    @BouquetAntoine

    #12342 will fix this soon

  4. github-actions commented on Apr 8, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions