feat(auth): add Anthropic OAuth support for Claude Pro/Max subscriptions#119
Merged
spachava753 merged 4 commits intomainfrom Dec 21, 2025
Merged
feat(auth): add Anthropic OAuth support for Claude Pro/Max subscriptions#119spachava753 merged 4 commits intomainfrom
spachava753 merged 4 commits intomainfrom
Conversation
This adds OAuth-based authentication for Anthropic, allowing users to use their Claude Pro/Max subscription credits instead of API keys. New `cpe auth` commands enable authentication management: - `cpe auth login anthropic` - Start OAuth flow via browser - `cpe auth logout anthropic` - Remove stored credentials - `cpe auth status` - Show authentication status The implementation follows Anthropic's OAuth 2.0 flow with PKCE, storing tokens at `~/.config/cpe/auth.json`. When OAuth credentials exist, they're used automatically for Anthropic requests; otherwise falls back to API key authentication. Closes #109
…ection Adds `auth_method` field to model configuration, allowing explicit control over authentication. This enables users to define separate model refs for OAuth and API key authentication, supporting the pattern of falling back to API credits when subscription limits are reached. Validation uses `required_unless` struct tag for `api_key_env` and custom validation to ensure `oauth` is only valid for the anthropic provider.
Anthropic requires OAuth tokens to include a specific system prompt identifier to validate that the request is coming from an authorized Claude Code client. Without this, requests fail with "This credential is only authorized for use with Claude Code." The fix prepends "You are Claude Code, Anthropic's official CLI for Claude." as the first system message when using OAuth authentication, matching the pattern used by other Claude Code implementations like OpenCode. Also improves beta header handling in the OAuth transport to properly merge existing and required headers without duplicates.
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 OAuth authentication support for Anthropic, allowing users to authenticate with their Claude Pro/Max subscription instead of API keys. This enables using subscription credits directly.
Closes #109
Changes
internal/auth/package with PKCE flow, token storage, and OAuth transportcpe auth login anthropic,cpe auth logout anthropic, andcpe auth statuscommandsauth_method: oauthconfig option for Anthropic modelsUsage