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

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