ClaudeCodeSDK.Auth.Providers.Anthropic (claude_code_sdk v0.2.2)

View Source

Anthropic-specific authentication via claude setup-token.

Summary

Functions

Returns the environment variable name for Claude OAuth tokens.

Executes claude setup-token and extracts the OAuth token.

Functions

oauth_env_var()

@spec oauth_env_var() :: String.t()

Returns the environment variable name for Claude OAuth tokens.

Examples

iex> ClaudeCodeSDK.Auth.Providers.Anthropic.oauth_env_var()
"CLAUDE_CODE_OAUTH_TOKEN"

setup_token()

@spec setup_token() :: {:ok, String.t(), DateTime.t()} | {:error, term()}

Executes claude setup-token and extracts the OAuth token.

This requires:

  • Claude Code CLI installed (v2.0.10+)
  • Active Claude subscription
  • Interactive terminal for OAuth flow

Process

  1. Opens browser to claude.ai/oauth/authorize
  2. User signs in with Claude account
  3. CLI displays OAuth token (sk-ant-oat01-...)
  4. Token is valid for 1 year

Token Format

Returns OAuth token: sk-ant-oat01-... Should be set as: export CLAUDE_CODE_OAUTH_TOKEN=<token>