豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

fix: merge SDK anthropic-beta headers with base endpoint betas#4945

Merged
TylerLeonhardt merged 1 commit intomainfrom
dev/bhavyau/fix-claude-beta-header-merge
Apr 3, 2026
Merged

fix: merge SDK anthropic-beta headers with base endpoint betas#4945
TylerLeonhardt merged 1 commit intomainfrom
dev/bhavyau/fix-claude-beta-header-merge

Conversation

@bhavyaus
Copy link
Copy Markdown
Contributor

@bhavyaus bhavyaus commented Apr 2, 2026

Problem

When contextEditing.mode is enabled (e.g. clear-tooluse), the Claude agent fails with:

400 {"type":"error","error":{"type":"invalid_request_error","message":"context_management: Extra inputs are not permitted"}}

Root Cause

In ClaudeStreamingPassThroughEndpoint.getExtraHeaders(), the SDK's anthropic-beta header was overwriting the base endpoint's beta headers instead of merging with them.

  1. The base chatEndpoint.getExtraHeaders() adds context-management-2025-06-27 to anthropic-beta (driven by the contextEditing.mode config)
  2. createMessagesRequestBody adds context_management to the request body
  3. Then the SDK's anthropic-beta header (which doesn't include context-management) replaces the base's value
  4. CAPI receives context_management in the body without the required beta header → 400 error

Fix

Merge the SDK's filtered betas with the base endpoint's betas using a Set to deduplicate, instead of overwriting.

Fixes microsoft/vscode#298471

The ClaudeStreamingPassThroughEndpoint.getExtraHeaders() was overwriting
the base endpoint's anthropic-beta header with the SDK's filtered betas
instead of merging them. This caused context editing to fail because the
context-management beta header (set by chatEndpoint based on config) was
lost when the SDK sent its own anthropic-beta header.

Now uses a Set to merge and deduplicate both sources of beta headers.

Fixes microsoft/vscode#298471
Copilot AI review requested due to automatic review settings April 2, 2026 18:56
@bhavyaus bhavyaus self-assigned this Apr 2, 2026
@bhavyaus bhavyaus requested a review from TylerLeonhardt April 2, 2026 18:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Claude Code “context_management: Extra inputs are not permitted” failures by ensuring the SDK-provided anthropic-beta header does not overwrite (but instead merges with) beta headers added by the base endpoint (e.g., context-management-2025-06-27 when context editing is enabled).

Changes:

  • Merge base endpoint anthropic-beta values with SDK-provided, filtered betas using a Set for deduplication.
  • Preserve config-driven betas while still filtering incoming SDK betas to supported values.

Comment thread src/extension/chatSessions/claude/node/claudeLanguageModelServer.ts
Copy link
Copy Markdown
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but it's not how I'd like it to work.

I want the Claude agent to be the only thing that adds Anthropic-related stuff (body/headers) to the request.

Let it decide how it wants to use the Messages API.

The exception would be any CAPI specific weirdness.

@TylerLeonhardt TylerLeonhardt added this pull request to the merge queue Apr 3, 2026
Merged via the queue into main with commit 2493369 Apr 3, 2026
23 checks passed
@TylerLeonhardt TylerLeonhardt deleted the dev/bhavyau/fix-claude-beta-header-merge branch April 3, 2026 11:18
@bhavyaus
Copy link
Copy Markdown
Contributor Author

bhavyaus commented Apr 7, 2026

better fix with microsoft/vscode#308387

bhavyaus added a commit to microsoft/vscode that referenced this pull request Apr 17, 2026
Callers can now opt into Anthropic features (context editing, tool
search, etc.) by setting modelCapabilities on the request itself,
as introduced in #308387. The base endpoint no longer needs to inject
beta headers — the Claude agent controls its own headers.

Reverts the merge logic from microsoft/vscode-copilot-chat#4945.
bhavyaus added a commit to microsoft/vscode that referenced this pull request Apr 17, 2026
…nt (#310908)

Callers can now opt into Anthropic features (context editing, tool
search, etc.) by setting modelCapabilities on the request itself,
as introduced in #308387. The base endpoint no longer needs to inject
beta headers — the Claude agent controls its own headers.

Reverts the merge logic from microsoft/vscode-copilot-chat#4945.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude agent doesn't work with context editing enabled

3 participants