feat(auth): add Claude Code OAuth support for Anthropic provider#3299
Draft
sunipan wants to merge 3 commits intotailcallhq:mainfrom
Draft
feat(auth): add Claude Code OAuth support for Anthropic provider#3299sunipan wants to merge 3 commits intotailcallhq:mainfrom
sunipan wants to merge 3 commits intotailcallhq:mainfrom
Conversation
- Change claude_code redirect_uri to localhost:3456 for automatic callback capture - Add anthropic-client custom header to identify as Claude Code client - Enable provider-level custom headers in Anthropic provider - Add billing-header transform to zero out costs (OAuth subscription usage) - Apply billing-header transform to Anthropic request DTO This allows ForgeCode to authenticate via Anthropic's OAuth flow using the official Claude Code client_id, enabling Claude Pro/Max subscription usage through the CLI.
- Revert claude_code OAuth redirect_uri to https://platform.claude.com/oauth/code/callback - Update token_url to platform.claude.com and add user:mcp_servers, user:file_upload scopes - Parse full callback URLs, code#state, query strings, and raw codes when exchanging codes - Cap cache_control markers at Anthropic's 4-block limit, preferring newest breakpoints
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 Claude Code OAuth support for ForgeCode’s Anthropic provider.
This is a ForgeCode port of the Claude/Anthropic auth behavior from:
https://github.com/ex-machina-co/opencode-anthropic-auth
I’m opening this as a draft/community PR because it helps users who want to authenticate ForgeCode with Claude subscription-style OAuth rather than a normal Anthropic API key, but it includes provider-specific behavior that maintainers should explicitly review before deciding whether it belongs upstream.
Context
This PR was prepared with AI assistance.
I’ve mirrored the relevant changes from
opencode-anthropic-authfor ForgeCode’s Rust provider stack. I want to stress that using this provider for Claude Code may carry potential account or policy risks, although I personally have not had any issues.Changes
Add Claude Code OAuth provider config updates:
anthropic-clientcustom headerExtend Anthropic OAuth code exchange parsing:
code#statecode=...&state=...Update Anthropic request headers for OAuth:
Authorization: Bearer ...for OAuth credentialsAdd Claude Code request transforms for OAuth-backed Anthropic requests:
Cap Anthropic
cache_controlblocks at Anthropic’s 4-block limit.Source / Provenance
The Claude Code OAuth-specific behavior is ported from:
https://github.com/ex-machina-co/opencode-anthropic-auth
The current branch was reconciled against the source repo’s current mainline behavior, including Claude Code version/user-agent and billing metadata constants.
Risk / Maintainer Decision Points
This PR intentionally does not hide that the feature may have product, policy, or provider-relationship implications.
Things maintainers should decide before merging:
If maintainers prefer not to carry this behavior, I’m happy to close this PR and keep it as a fork-only patch or move toward an external proxy/plugin-style approach.
Testing
Ran:
Results:
billing_header: 4 passedset_cache: 20 passedauth::http::anthropic: 1 passedcargo check: passed for changed packages