Skip to content

[backend] Port 1M context / adaptive thinking for Opus 4.6 (upstream #12338) #150

Description

@randomm

Description

Port upstream PR anomalyco#12342 to enable 1M context window and adaptive thinking for Claude Opus 4.6.

Scope

This is a major AI SDK upgrade (v5→v6) with breaking changes. Not a simple cherry-pick.

Changes Required

Phase 1 - Minimal (just headers + adaptive thinking):

  • Add context-1m-2025-08-07 beta header to Anthropic provider
  • Add adaptive-thinking-2026-01-28 beta header
  • Add adaptive thinking detection for Opus 4.6 in transform.ts
  • Convert budgetTokens → effort for Opus 4.6 models

Phase 2 - SDK Upgrade (breaking changes):

  • Upgrade ai 5.0.124 → 6.0.72
  • Upgrade all @ai-sdk/* packages (18+ packages)
  • Migrate LanguageModelV2 → LanguageModelV3
  • Make toModelMessages async
  • Rename tool factory functions
  • Update test suites for new usage types
  • Fix compaction token counting bug

Key Files

  • packages/opencode/src/provider/provider.ts - Beta headers
  • packages/opencode/src/provider/transform.ts - Adaptive thinking logic
  • packages/opencode/src/session/compaction.ts - Token counting
  • packages/opencode/src/session/llm.ts - Async migration
  • packages/opencode/src/session/prompt.ts - Type migration
  • packages/opencode/src/provider/sdk/copilot/responses/tool/* - Factory renames

Upstream Reference

Quality Gates

  • Tests pass
  • Type checking passes
  • Manual test: Opus 4.6 with >200k tokens

Activity

  1. randomm commented on Feb 6, 2026

    @randomm
    OwnerAuthor

    Merged in PR #152 - 1M context headers and adaptive thinking for Opus 4.6

  2. okhsunrog commented on Feb 6, 2026

    @okhsunrog

    @randomm could you explain to me what's happening here? I didn't get any review on my PR and I see a PR with a similar name getting merged, but obviously incomplete, as it doesn't actually enable adaptive thinking.
    type: "enabled" is for manual thinking with budgetTokens. Adaptive thinking requires type: "adaptive".

  3. okhsunrog commented on Feb 6, 2026

    @okhsunrog

    ah, sorry, I see that it's your fork, not opencode official repo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions