feat(providers): add anthropic-oauth provider for subscription plan auth#1923
Closed
cjfit wants to merge 1 commit into
Closed
feat(providers): add anthropic-oauth provider for subscription plan auth#1923cjfit wants to merge 1 commit into
cjfit wants to merge 1 commit into
Conversation
Add an `anthropic-oauth` provider type (alias `claude-plan`) so sandboxes can run Claude Code on an Anthropic Pro/Max subscription. The OAuth token is harvested, stored, and refreshed entirely outside the sandbox and injected only at the egress boundary; it is never written into the sandbox environment, filesystem, or logs. - inference: new anthropic-oauth profile (Authorization: Bearer plus a mandatory anthropic-beta: oauth-2025-04-20 default header) - router: merge the mandatory anthropic-beta flag with any client-sent value so the sandbox cannot drop it - server: mark ANTHROPIC_OAUTH_TOKEN non-injectable (proxy-only) - cli: add `provider create --from-claude-login` to read the local Claude Code login (macOS Keychain or ~/.claude/.credentials.json) and wire the gateway's OAuth2 background refresh - docs: add the Anthropic Subscription provider page and update gateway architecture and provider tables The macOS path (Keychain) is validated end-to-end. Linux reads the same ~/.claude/.credentials.json file and should work unchanged, but has not yet been validated on Linux. Signed-off-by: Cedric Fitzgerald <soulcedric2@gmail.com>
|
Thank you for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text: I have read the DCO document and I hereby sign the DCO. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot. |
|
Thank you for your interest in contributing to OpenShell, @cjfit. This project uses a vouch system for first-time contributors. Before submitting a pull request, you need to be vouched by a maintainer. To get vouched:
See CONTRIBUTING.md for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
anthropic-oauthprovider type (aliasclaude-plan) so sandboxes can run Claude Code on an Anthropic Pro/Max subscription plan instead of a metered API key. The subscription OAuth token is harvested, stored, and refreshed entirely outside the sandbox and injected only at the egress proxy boundary — it is never written into the sandbox environment, filesystem, or logs. This reuses the existing gateway-side OAuth2 refresh machinery and the non-injectable/proxy-only credential path (the same pattern as the Vertex--from-gcloud-adcflow).Related Issue
N/A — no tracking issue.
Changes
openshell-core): newanthropic-oauthprofile —Authorization: Bearerplus a mandatoryanthropic-beta: oauth-2025-04-20default header (subscription tokens require it where API keys do not).normalize_inference_provider_typealiasesclaude-plan.openshell-router): merge the mandatoryanthropic-betaflag with any client-sentanthropic-betavalue into a single header, so a sandbox client cannot drop the OAuth flag (and we never emit a duplicate header).openshell-server): markANTHROPIC_OAUTH_TOKENnon-injectable so it rides the inference route bundle but is never exported into the sandbox env.openshell-cli):provider create --from-claude-loginreads the local Claude Code login (macOS KeychainClaude Code-credentialsor~/.claude/.credentials.json), stores the access token as the proxy-only credential, and configures the gateway'sOauth2RefreshTokenbackground refresh (Anthropic publicclient_id, no client secret). Includes create-failure rollback.providers/anthropic-oauth.yaml.docs/providers/anthropic-subscription.mdx; updatedarchitecture/gateway.mdand the provider table indocs/sandboxes/manage-providers.mdx.Testing
mise run pre-commitpasses (lint, format, license headers, full unit suite — clippy-D warningsclean).resolve_provider_environmentassertion that the access token is never returned to the sandbox; the routeranthropic-betamerge (mandatory flag survives, no duplicate, Bearer injected); CLI credential JSON parsing (field extraction, ms/seconds expiry normalization, missing-field errors).claude loginon host →openshell provider create --name claude-plan --type anthropic-oauth --from-claude-login→openshell inference set --provider claude-plan --model claude-sonnet-4-6→ sandbox bound to the provider →ANTHROPIC_BASE_URL=https://inference.local ANTHROPIC_API_KEY=unused claude -p "…"returns a 200 completion.Authorization: Bearerheader is applied at the egress boundary, not by the sandbox.~/.claude/.credentials.json, which is where Claude Code writes its login on Linux. This should work unchanged but has not been validated on Linux (and a keyring-backed Linux login, if any, is not yet supported).Note for maintainers (ghcr images)
The supervisor applies the Bearer +
anthropic-betaheaders at the sandbox boundary, so thesupervisorimage must be rebuilt for this feature to take effect — a stale supervisor silently drops the headers and Anthropic rejects the request. On merge tomain,release-dev.ymlrebuilds and republishesgateway:devandsupervisor:dev, so keep the two on the same build.Checklist
architecture/gateway.md) and user docs added (docs/providers/anthropic-subscription.mdx)