Skip to content

feat(opencode): support Claude Code OAuth credentials for Anthropic provider#20080

Closed
sakithajayasinghe wants to merge 1 commit intoanomalyco:devfrom
sakithajayasinghe:feat/claude-code-oauth
Closed

feat(opencode): support Claude Code OAuth credentials for Anthropic provider#20080
sakithajayasinghe wants to merge 1 commit intoanomalyco:devfrom
sakithajayasinghe:feat/claude-code-oauth

Conversation

@sakithajayasinghe
Copy link
Copy Markdown

@sakithajayasinghe sakithajayasinghe commented Mar 30, 2026

Issue for this PR

Closes #20079

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds support for authenticating with Anthropic using Claude Code OAuth credentials (~/.claude/.credentials.json) when no ANTHROPIC_API_KEY is set.

Two files changed:

  • New claude-code-credential.ts — reads the credential file, caches the token (5 min TTL), checks expiry
  • Modified provider.ts — the Anthropic custom loader detects the OAuth token, passes it via authToken to createAnthropic(), adds OAuth beta headers, and injects the billing header + metadata in the fetch wrapper

API 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 errors
  • bun test test/provider/provider.test.ts — 70/70 pass
  • bun test test/provider/transform.test.ts — 119/119 pass
  • Ran bun dev with only ~/.claude/.credentials.json (no API key) — Claude Sonnet 4.6 loaded and responded successfully

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
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.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@rekram1-node
Copy link
Copy Markdown
Collaborator

We cannot legally support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]:Support Claude Code OAuth credentials for Anthropic provider

2 participants