fix(claude-code): add oauthToken config for subscription SDK auth #12

Merged
jleibl merged 1 commits from fix/claude-code-oauth-token into main 2026-05-21 12:56:28 +00:00
Owner

claude login alone does not authorize SDK / non-interactive
(claude -p) usage. Anthropic gates that behind a separate long-lived
token minted by claude setup-token. Without it, subscription users
hit billing_error from the SDK even though interactive Claude Code
works fine.

Changes:

  • ClaudeCodeConfig.oauthToken: new optional field. When set, the
    provider exports it as CLAUDE_CODE_OAUTH_TOKEN before invoking the
    SDK, which makes the SDK bill against the user's Pro/Max
    subscription instead of API credits.
  • apiKey continues to work for users with a console API key. If both
    are present, oauthToken takes precedence.
  • billing_error / authentication_failed messages now point users at
    claude setup-token so the fix is obvious from the error alone.
  • README: rewrite the Claude Code section to document both modes and
    the claude setup-token step explicitly.
  • examples/claude-code.ts: read CLAUDE_CODE_OAUTH_TOKEN from env so
    the smoke test actually works for subscribers.
`claude login` alone does not authorize SDK / non-interactive (`claude -p`) usage. Anthropic gates that behind a separate long-lived token minted by `claude setup-token`. Without it, subscription users hit `billing_error` from the SDK even though interactive Claude Code works fine. Changes: - ClaudeCodeConfig.oauthToken: new optional field. When set, the provider exports it as CLAUDE_CODE_OAUTH_TOKEN before invoking the SDK, which makes the SDK bill against the user's Pro/Max subscription instead of API credits. - apiKey continues to work for users with a console API key. If both are present, oauthToken takes precedence. - billing_error / authentication_failed messages now point users at `claude setup-token` so the fix is obvious from the error alone. - README: rewrite the Claude Code section to document both modes and the `claude setup-token` step explicitly. - examples/claude-code.ts: read CLAUDE_CODE_OAUTH_TOKEN from env so the smoke test actually works for subscribers.
jleibl added 1 commit 2026-05-21 12:56:25 +00:00
`claude login` alone does not authorize SDK / non-interactive
(`claude -p`) usage. Anthropic gates that behind a separate long-lived
token minted by `claude setup-token`. Without it, subscription users
hit `billing_error` from the SDK even though interactive Claude Code
works fine.

Changes:

- ClaudeCodeConfig.oauthToken: new optional field. When set, the
  provider exports it as CLAUDE_CODE_OAUTH_TOKEN before invoking the
  SDK, which makes the SDK bill against the user's Pro/Max
  subscription instead of API credits.
- apiKey continues to work for users with a console API key. If both
  are present, oauthToken takes precedence.
- billing_error / authentication_failed messages now point users at
  `claude setup-token` so the fix is obvious from the error alone.
- README: rewrite the Claude Code section to document both modes and
  the `claude setup-token` step explicitly.
- examples/claude-code.ts: read CLAUDE_CODE_OAUTH_TOKEN from env so
  the smoke test actually works for subscribers.
jleibl merged commit b99707c629 into main 2026-05-21 12:56:28 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jleibl/simple-ai-provider#12