Skip to content

Claude agent host: native (BYOK) transport (Phases 18–19) - #323037

Merged
TylerLeonhardt merged 2 commits into
mainfrom
tyleonha/claude-byo-anthropic
Jun 26, 2026
Merged

TylerLeonhardt merged 2 commits into
mainfrom
tyleonha/claude-byo-anthropic

Conversation

@TylerLeonhardt

@TylerLeonhardt TylerLeonhardt commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What

Fixes #314952

Adds native (BYOK) access for the Claude agent host and the transport-branched model source it builds on (roadmap Phases 18 & 19).

When claudeUseCopilotProxy: false, the Claude Agent SDK uses whatever Claude is configured with directly on the user's own credentials — no Copilot proxy in the request path. Proxy mode (the default) is unchanged.

How to use

This is only through the Agent Host, so first apply these VS Code settings:

"chat.agentHost.enabled": true,
"chat.editor.claude.preferAgentHost": true,
"chat.agents.claude.preferAgentHost": true

Then, we need to apply Agent Host Settings so right click on an agent host session in the Agents Window:
image

Choose "Open Host Settings" and then add claudeUseCopilotProxy: false to that.

Highlights

  • Phase 18 — transport-branched model source. Proxy mode lists Claude models from CAPI; native mode enumerates via the SDK's query().supportedModels(). Single branch point (_refreshModels → proxy/native).
  • Phase 19 — direct Claude access. Native transport omits the proxy base-url/auth-token and lets the SDK resolve credentials itself.
  • Native auth = subprocess env. ANTHROPIC_API_KEY, or a subscription OAuth token in CLAUDE_CODE_OAUTH_TOKEN (from claude setup-token). Fixes SDK ≥0.3 env-replace semantics by spreading process.env in native mode so the token + PATH actually reach the claude subprocess (previously wiped → "Not logged in").
  • IClaudeAgentSdkService stays 1:1 with the SDK. Adds a query() passthrough; the model-enumeration orchestration moved to the caller, which close()s the throwaway query (leak guard, covered by a test).
  • Cleanup: removed the speculative native-binary-path feature (it only selects which claude build runs, never the credentials); moved ClaudeTransport into claudeProxyService.ts; dropped a trivial model-list helper; simplified buildSubprocessEnv.

Note: the interactive claude login keychain session is not used in headless/SDK mode — verified empirically. Headless subscription auth requires CLAUDE_CODE_OAUTH_TOKEN.

Test plan

  • ./scripts/test.sh --grep "claude|Claude" — all green (incl. native env-inheritance, native model enumeration, and the new close()/leak-guard test).
  • npm run typecheck-client — clean.
  • E2E: launched Code OSS --agents with claudeUseCopilotProxy: false + CLAUDE_CODE_OAUTH_TOKEN; native turns authenticate and the model picker shows native models with no proxy started.

Draft — opening for early review.

…hed models (Phases 18–19)

- Phase 18: single transport-branched model source. Proxy mode fetches Claude
  models from CAPI; native mode enumerates via the SDK's query().supportedModels().
- Phase 19: direct (non-proxied) Claude access. claudeUseCopilotProxy: false
  routes the SDK to Anthropic on the user's own credentials, no proxy in path.
- Native auth comes from the subprocess env (ANTHROPIC_API_KEY, or
  CLAUDE_CODE_OAUTH_TOKEN from `claude setup-token`). Fixes the SDK >=0.3
  env-replace semantics by spreading process.env in native mode so the token
  + PATH actually reach the claude subprocess.
- IClaudeAgentSdkService keeps its 1:1-with-SDK contract: adds a query()
  passthrough; enumeration orchestration moved to the caller and closes the
  throwaway query (leak guard, covered by a new test).
- Cleanup: removed the speculative native-binary-path feature; moved
  ClaudeTransport into claudeProxyService.ts; dropped a trivial model-list
  helper; tightened buildSubprocessEnv env construction.
Copilot AI review requested due to automatic review settings June 25, 2026 22:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a host-level “native” (BYO-Anthropic) transport for the Claude agent host, so the Claude Agent SDK can talk directly to Anthropic using user credentials when claudeUseCopilotProxy: false, while keeping the existing Copilot-proxied flow as the default. The change also introduces a transport-branched model source (CAPI models in proxy mode vs Query.supportedModels() in native mode), and updates subprocess environment handling to preserve the user’s auth/PATH in native mode.

Changes:

  • Introduce a ClaudeTransport discriminated union and thread it through session materialization and SDK option construction (proxy vs native).
  • Implement native model enumeration via an ephemeral SDK query() + supportedModels() + close() flow; add projection ModelInfo -> IAgentModelInfo without Copilot commercial metadata.
  • Add RootConfigState key claudeUseCopilotProxy (default true) and tests covering env inheritance, transport behavior, and native model enumeration/cleanup.
Show a summary per file
File Description
src/vs/platform/agentHost/common/agentHostCustomizationConfig.ts Adds claudeUseCopilotProxy root config key + schema metadata (default proxy).
src/vs/platform/agentHost/node/claude/claudeProxyService.ts Defines ClaudeTransport union (proxy/native).
src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts Refactors buildOptions/buildSubprocessEnv for transport; adds native model-enumeration Options.
src/vs/platform/agentHost/node/claude/claudeAgentSdkService.ts Adds 1:1 query() passthrough binding to the SDK (lazy-load shim).
src/vs/platform/agentHost/node/claude/claudeAgent.ts Resolves transport mode from root config; implements native model enumeration and proxy/native auth/resource behavior.
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts Threads transport through materialize/rematerialize; gates Copilot credit overlays on proxy transport; persists transport in overlay update.
src/vs/platform/agentHost/node/claude/claudeSessionMetadataStore.ts Persists/reads forward-compat claude.transport session overlay metadata.
src/vs/platform/agentHost/test/node/claudeSdkOptions.test.ts Adds coverage for native env inheritance and proxy-vs-native buildOptions env behavior.
src/vs/platform/agentHost/test/node/claudeAgent.test.ts Adds native transport tests (protected resources, model enumeration + query close, proxy not started).
src/vs/platform/agentHost/test/node/claudeSubagentResolver.test.ts Updates test fake to match new IClaudeAgentSdkService.query() signature.
src/vs/platform/agentHost/test/node/claudeAgent.integrationTest.ts Updates integration fake to implement new query() method.
src/vs/platform/agentHost/node/claude/roadmap.md Documents Phase 18/19 completion and rationale/background.
src/vs/platform/agentHost/node/claude/phase18-plan.md Adds Phase 18 plan doc (implemented).
src/vs/platform/agentHost/node/claude/phase19-plan.md Adds Phase 19 plan doc (implemented), but currently has drift vs implementation (see comments).

Copilot's findings

  • Files reviewed: 14/14 changed files
  • Comments generated: 4

- _fetchNativeModels: abort the enumeration options' abortController in the
  finally (alongside query.close()) so teardown is explicit.
- buildModelEnumerationOptions doc: the caller, not the SDK service, aborts the
  controller at teardown.
- phase19-plan: reflect the 1:1 query() passthrough (enumeration lifecycle lives
  in ClaudeAgent, not a supportedModels() service method); fix the
  ClaudeTransport home (claudeProxyService.ts) and helper signatures.
@TylerLeonhardt TylerLeonhardt changed the title Claude agent host: native (BYO-Anthropic) transport (Phases 18–19) Claude agent host: native (BYOK) transport (Phases 18–19) Jun 25, 2026
@TylerLeonhardt

Copy link
Copy Markdown
Member Author

/azp run Dependencies Check

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@TylerLeonhardt

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

auto-merge was automatically disabled June 25, 2026 23:59

Pull request was closed

@TylerLeonhardt
TylerLeonhardt enabled auto-merge (squash) June 26, 2026 00:00
@TylerLeonhardt
TylerLeonhardt merged commit 8a73e45 into main Jun 26, 2026
54 checks passed
@TylerLeonhardt
TylerLeonhardt deleted the tyleonha/claude-byo-anthropic branch June 26, 2026 00:40
@vs-code-engineering vs-code-engineering Bot added this to the 1.127.0 milestone Jun 26, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Claude Agent to run through Anthropic subscription instead of Copilot quota

3 participants