Browse docs
Docs / concepts / oauth
OAuth
OAuth
- how the OAuth token exchange works (PKCE)
- where tokens are stored (and why)
- how to handle multiple accounts (profiles + per-session overrides)
text
openclaw models auth login --provider <id>The token sink (why it exists)
- you log in via OpenClaw and via Claude Code / Codex CLI → one of them randomly gets “logged out” later
- the runtime reads credentials from one place
- we can keep multiple profiles and route them deterministically
Storage (where tokens live)
- Auth profiles (OAuth + API keys):
~/.openclaw/agents/<agentId>/agent/auth-profiles.json - Runtime cache (managed automatically; don’t edit):
~/.openclaw/agents/<agentId>/agent/auth.json
~/.openclaw/credentials/oauth.json(imported intoauth-profiles.jsonon first use)
Anthropic setup-token (subscription auth)
text
openclaw models auth setup-token --provider anthropictext
openclaw models auth paste-token --provider anthropictext
openclaw models statusOAuth exchange (how login works)
Anthropic (Claude Pro/Max) setup-token
- run
claude setup-token - paste the token into OpenClaw
- store as a token auth profile (no refresh)
OpenAI Codex (ChatGPT OAuth)
- generate PKCE verifier/challenge + random
state - open
https://auth.openai.com/oauth/authorize?... - try to capture callback on
http://127.0.0.1:1455/auth/callback - if callback can’t bind (or you’re remote/headless), paste the redirect URL/code
- exchange at
https://auth.openai.com/oauth/token - extract
accountIdfrom the access token and store{ access, refresh, expires, accountId }
Refresh + expiry
- if
expiresis in the future → use the stored access token - if expired → refresh (under a file lock) and overwrite the stored credentials
Multiple accounts (profiles) + routing
1) Preferred: separate agents
text
openclaw agents add work
openclaw agents add personal2) Advanced: multiple profiles in one agent
- globally via config ordering (
auth.order) - per-session via
/model ...@<profileId>
/model Opus@anthropic:work
openclaw channels list --json(showsauth[])
- /concepts/model-failover (rotation + cooldown rules)
- /tools/slash-commands (command surface)