Skip to content

feat: add context management support and corresponding beta handling - #1080

Merged
AlemTuzlak merged 2 commits into
TanStack:mainfrom
harshlocham:fix/anthropic-context-management-beta
Aug 20, 2026
Merged

feat: add context management support and corresponding beta handling#1080
AlemTuzlak merged 2 commits into
TanStack:mainfrom
harshlocham:fix/anthropic-context-management-beta

Conversation

@harshlocham

@harshlochamharshlocham commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Fixes#1074.

modelOptions.context_management was typed and forwarded on the Anthropic Messages body, but computeAnthropicBetas never attached the required context-management-2025-06-27 beta. Context editing therefore typechecked and could not work.

  • Add context-management-2025-06-27 when context_management != null (treat null as unset)
  • Unit coverage in computeAnthropicBetas
  • Wire-level adapter test asserting body + betas are both sent

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • Added support for Anthropic context management settings.
    • Automatically enables the required beta capability when context management is configured.
    • Supports using context management alongside interleaved thinking.
    • Keeps the beta capability disabled when context management is explicitly turned off.
  • Bug Fixes

    • Ensured context management settings are correctly included in Anthropic requests.
  • Documentation

    • Documented the required beta header for context management.

@coderabbitai

coderabbitaiBot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 69d70890-a5fd-4464-bbca-2fc74774ba16

📥 Commits

Reviewing files that changed from the base of the PR and between baa97ea and 294318e.

📒 Files selected for processing (1)
  • .changeset/little-guests-trade.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/little-guests-trade.md

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Anthropic adapter adds context-management-2025-06-27 when modelOptions.context_management is configured. Tests cover forwarding, null handling, and combination with interleaved thinking. A patch changeset documents the beta requirement.

Changes

Anthropic context management

Layer / File(s)Summary
Context management beta computation
packages/ai-anthropic/src/adapters/text.ts
computeAnthropicBetas accepts nullable context_management options and adds context-management-2025-06-27 when configured.
Adapter validation and release metadata
packages/ai-anthropic/tests/anthropic-adapter.test.ts, packages/ai-anthropic/tests/text.skills.test.ts, .changeset/little-guests-trade.md
Tests validate request forwarding, null handling, and beta combinations. The changeset documents the required Anthropic beta header.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk:⚪ Minimal · up to 29431

This localized change adds the required beta handling for context management and includes targeted tests; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
participant ModelOptions
participant AnthropicTextAdapter
participant AnthropicAPI
ModelOptions->>AnthropicTextAdapter: Provide context_management
AnthropicTextAdapter->>AnthropicTextAdapter: Compute context-management beta
AnthropicTextAdapter->>AnthropicAPI: Send context_management and beta header
Loading

Possibly related PRs

  • TanStack/ai#932: Both changes modify Anthropic beta selection in computeAnthropicBetas.

Suggested reviewers:alemtuzlak

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly summarizes the main change: Anthropic context management support and required beta handling.
Description check✅ PassedThe description follows the repository template, explains the fix, records testing, and includes the required changeset checklist item.
Linked Issues check✅ PassedThe changes satisfy issue #1074 by adding the required beta for non-null context management and covering body and beta forwarding with tests.
Out of Scope Changes check✅ PassedAll changes support issue #1074 and its stated objectives; no unrelated code or documentation changes are present.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR, @harshlocham! 🙌 @AlemTuzlak will take a look.

Automated pre-review checks

  • ✅ CI passing
  • ✅ No merge conflicts
  • ✅ Changeset present
  • ⚠️ No E2E test changes detected — behavior changes need coverage under testing/e2e/ (see CONTRIBUTING)

Automated triage — a human review follows.

@github-actionsgithub-actionsBot added the waiting-on: maintainer The ball is in the maintainers’ court label Aug 13, 2026
@harshlocham
harshlochamforce-pushed the fix/anthropic-context-management-beta branch 2 times, most recently from 85ce43a to 7aada67CompareAugust 15, 2026 14:28
@tombeckenham
tombeckenhamforce-pushed the fix/anthropic-context-management-beta branch from 7aada67 to baa97eaCompareAugust 20, 2026 10:12
@coderabbitai

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@tombeckenham

Copy link
Copy Markdown
Contributor

Maintainer sweep: rebased onto main (force-with-lease). CI approval handled if it was waiting.

@nx-cloud

nx-cloudBot commented Aug 20, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e6b5f24

CommandStatusDurationResult
nx run-many --targets=build --exclude=examples/...✅ Succeeded7sView ↗

☁️ Nx Cloud last updated this comment at 2026-08-20 10:55:57 UTC

harshlochamand others added 2 commits August 20, 2026 20:48
- Updated `computeAnthropicBetas` to include a new `context_management` option, which adds the `context-management-2025-06-27` beta when set.
- Enhanced the `buildServerToolResultBlock` documentation to reflect the new context management feature.
- Added tests to verify the correct forwarding of `context_management` and the attachment of the required beta in the adapter.
- Ensured that the beta is not added when `context_management` is null.
Closes issue TanStack#1074.
@tombeckenham
tombeckenhamforce-pushed the fix/anthropic-context-management-beta branch from 294318e to e6b5f24CompareAugust 20, 2026 10:49
@tombeckenham

Copy link
Copy Markdown
Contributor

Maintainer sweep: rebased onto main (force-with-lease). CI approval handled if it was waiting.

@pkg-pr-new

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@1080

@tanstack/ai-acp

npm i https://pkg.pr.new/@tanstack/ai-acp@1080

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@1080

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@1080

@tanstack/ai-bedrock

npm i https://pkg.pr.new/@tanstack/ai-bedrock@1080

@tanstack/ai-byteplus

npm i https://pkg.pr.new/@tanstack/ai-byteplus@1080

@tanstack/ai-claude-code

npm i https://pkg.pr.new/@tanstack/ai-claude-code@1080

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@1080

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@1080

@tanstack/ai-code-mode-snippets

npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1080

@tanstack/ai-codex

npm i https://pkg.pr.new/@tanstack/ai-codex@1080

@tanstack/ai-cohere

npm i https://pkg.pr.new/@tanstack/ai-cohere@1080

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1080

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1080

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1080

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@1080

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@1080

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@1080

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@1080

@tanstack/ai-grok-build

npm i https://pkg.pr.new/@tanstack/ai-grok-build@1080

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@1080

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1080

@tanstack/ai-isolate-daytona

npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1080

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1080

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1080

@tanstack/ai-isolate-quickjs-bun

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1080

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@1080

@tanstack/ai-memory

npm i https://pkg.pr.new/@tanstack/ai-memory@1080

@tanstack/ai-mistral

npm i https://pkg.pr.new/@tanstack/ai-mistral@1080

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@1080

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@1080

@tanstack/ai-opencode

npm i https://pkg.pr.new/@tanstack/ai-opencode@1080

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@1080

@tanstack/ai-perplexity

npm i https://pkg.pr.new/@tanstack/ai-perplexity@1080

@tanstack/ai-persistence

npm i https://pkg.pr.new/@tanstack/ai-persistence@1080

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@1080

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@1080

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@1080

@tanstack/ai-sandbox

npm i https://pkg.pr.new/@tanstack/ai-sandbox@1080

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1080

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1080

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1080

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1080

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1080

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1080

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@1080

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1080

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@1080

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@1080

@tanstack/ai-vercel-gateway

npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1080

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@1080

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1080

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@1080

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1080

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1080

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1080

commit: e6b5f24

@github-actionsgithub-actionsBot added waiting-on: author Waiting for the author to respond or update and removed waiting-on: maintainer The ball is in the maintainers’ court labels Aug 20, 2026
@AlemTuzlak
AlemTuzlak merged commit 3bb55f3 into TanStack:mainAug 20, 2026
9 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Aug 20, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on: authorWaiting for the author to respond or update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai-anthropic: modelOptions.context_management is forwarded to the wire but the required beta header is never sent

3 participants

@harshlocham@tombeckenham@AlemTuzlak