feat(opencode): support Claude Code OAuth credentials for Anthropic provider#20080
Closed
sakithajayasinghe wants to merge 1 commit intoanomalyco:devfrom
Closed
feat(opencode): support Claude Code OAuth credentials for Anthropic provider#20080sakithajayasinghe wants to merge 1 commit intoanomalyco:devfrom
sakithajayasinghe wants to merge 1 commit intoanomalyco:devfrom
Conversation
…rovider Auto-detect ~/.claude/.credentials.json and use OAuth token when no ANTHROPIC_API_KEY is configured. Uses @ai-sdk/anthropic's authToken option for Bearer auth with required OAuth beta headers. Fixes #20079
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
The current PR #20080 is the only one directly addressing Claude Code OAuth credentials detection and Anthropic authentication in the way described. PR #18674 appears to handle OAuth plugin vendoring and PKCE security, which could be relevant context for understanding the overall OAuth implementation approach. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Collaborator
|
We cannot legally support this. |
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.
Issue for this PR
Closes #20079
Type of change
What does this PR do?
Adds support for authenticating with Anthropic using Claude Code OAuth credentials (
~/.claude/.credentials.json) when noANTHROPIC_API_KEYis set.Two files changed:
claude-code-credential.ts— reads the credential file, caches the token (5 min TTL), checks expiryprovider.ts— the Anthropic custom loader detects the OAuth token, passes it viaauthTokentocreateAnthropic(), adds OAuth beta headers, and injects the billing header + metadata in the fetch wrapperAPI key always takes precedence. No behavior change for users without Claude Code credentials.
How did you verify your code works?
npx tsc --noEmit— zero type errorsbun test test/provider/provider.test.ts— 70/70 passbun test test/provider/transform.test.ts— 119/119 passbun devwith only~/.claude/.credentials.json(no API key) — Claude Sonnet 4.6 loaded and responded successfullyScreenshots / recordings
N/A — no UI changes.
Checklist