feat: add Anthropic (Claude Code) quota provider#30
Merged
slkiser merged 2 commits intoslkiser:mainfrom Mar 25, 2026
Merged
Conversation
Adds a new 'anthropic' provider that fetches the 5-hour and 7-day rate-limit windows from the Anthropic OAuth usage API using Claude Code credentials (file, macOS Keychain, or env var). Token refresh is delegated to the claude CLI when near expiry. Credential loading approach based on prior art from claude-lens and ClaudeBar. Refs slkiser#29.
Owner
|
@diogoleitao I made some changes, could you test locally, since I don't have an anthropic subscription? I took out the MacOS keychain only because I remember seeing some future feature like this being added to Opencode on a dev branch. Thanks! |
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.
Refs #29
Summary
src/lib/anthropic.ts: credential loading, token refresh viaclaudeCLI, and quota fetch fromGET https://api.anthropic.com/api/oauth/usagesrc/providers/anthropic.ts: normalizes 5-hour and 7-day windows intoQuotaToastEntryfor both classic and grouped toast stylessrc/providers/registry.ts: registersanthropicProviderfirst in the listtests/quota-provider-boundary.test.ts: addsanthropicto the registry snapshottests/lib.anthropic.test.ts: 23 tests covering credential resolution,isNearExpiry,parseUsageResponse, andqueryAnthropicQuota(fetch success, 401/403, network error, bad JSON, unexpected shape)tests/providers.anthropic.test.ts: 9 tests covering classic/grouped toast entries, worst-window selection, error mapping,matchesCurrentModel, andisAvailableREADME.md: adds Anthropic to the provider list, setup table, and provider-specific notes with attributionBehaviour
anthropicanthropicprovider~/.claude/.credentials.json→ macOS Keychain (Claude Code-credentials) →CLAUDE_CODE_OAUTH_TOKENenv varclaudeCLI for silent refresh — same pattern asopencode-claude-authClaude 5handClaude 7dentriesChecks
npm run typecheck✓npm test✓ (272 tests pass)npm run build✓Attribution
Credential loading and API endpoint approach based on prior art from claude-lens (Astro-Han) and ClaudeBar (tddworks).