This gist shows how to implement your own OAuth workflow so your tool can acquire Anthropic OAuth tokens and write them in the format the Claude Code SDK expects at ~/.claude/.credentials.json.
Notes
- Uses an Authorization Code + PKCE flow via
https://claude.ai/oauth/authorizeand token exchange athttps://console.anthropic.com/v1/oauth/token. - Default client id commonly used by tools:
9d1c250a-e61b-44d9-88ed-5944d1962f5e(override with your own if issued). - The authorize endpoint supports a copy/paste mode (no local server). Your CLI opens/prints a URL; the user pastes a code back.
- Treat tokens as secrets; never log them.