OAuth
OpenClaw supports “subscription auth” via OAuth for providers that offer it (notably OpenAI Codex (ChatGPT OAuth)). For Anthropic subscriptions, new setup should use the local Claude CLI login path on the gateway host, but Anthropic changed third-party harness billing on April 4, 2026 at 12:00 PM PT / 8:00 PM BST: Anthropic says Claude subscription limits no longer cover OpenClaw and Anthropic now requires Extra Usage for that traffic. OpenAI Codex OAuth is explicitly supported for use in external tools like OpenClaw. This page explains: For Anthropic in production, API key auth is the safer recommended path.- how the OAuth token exchange works (PKCE)
- where tokens are stored (and why)
- how to handle multiple accounts (profiles + per-session overrides)
The token sink (why it exists)
OAuth providers commonly mint a new refresh token during login/refresh flows. Some providers (or OAuth clients) can invalidate older refresh tokens when a new one is issued for the same user/app. Practical symptom:- you log in via OpenClaw and via Claude Code / Codex CLI → one of them randomly gets “logged out” later
auth-profiles.json as a token sink:
- the runtime reads credentials from one place
- we can keep multiple profiles and route them deterministically
- when credentials are reused from an external CLI like Codex CLI, OpenClaw mirrors them with provenance and re-reads that external source instead of rotating the refresh token itself
Storage (where tokens live)
Secrets are stored per-agent:- Auth profiles (OAuth + API keys + optional value-level refs):
~/.openclaw/agents/<agentId>/agent/auth-profiles.json - Legacy compatibility file:
~/.openclaw/agents/<agentId>/agent/auth.json(staticapi_keyentries are scrubbed when discovered)
~/.openclaw/credentials/oauth.json(imported intoauth-profiles.jsonon first use)
$OPENCLAW_STATE_DIR (state dir override). Full reference: /gateway/configuration
For static secret refs and runtime snapshot activation behavior, see Secrets Management.
Anthropic legacy token compatibility
OpenClaw no longer offers Anthropic setup-token onboarding or auth commands for new setup. Existing legacy Anthropic token profiles are still honored at runtime if they are already configured.Anthropic Claude CLI migration
If Claude CLI is already installed and signed in on the gateway host, you can switch Anthropic model selection over to the local CLI backend. This is a supported OpenClaw path when you want to reuse a local Claude CLI login on the same host. Prerequisites:- the
claudebinary is installed on the gateway host - Claude CLI is already authenticated there via
claude auth login
anthropic/... to claude-cli/..., rewrites matching
Anthropic Claude fallbacks, and adds matching claude-cli/... allowlist
entries under agents.defaults.models.
Verify:
OAuth exchange (how login works)
OpenClaw’s interactive login flows are implemented in@mariozechner/pi-ai and wired into the wizards/commands.
Anthropic Claude CLI
Flow shape: Claude CLI path:- sign in with
claude auth loginon the gateway host - run
openclaw models auth login --provider anthropic --method cli --set-default - store no new auth profile; switch model selection to
claude-cli/... - keep existing Anthropic auth profiles for rollback
openclaw onboard/openclaw configure→ auth choiceanthropic-cli
OpenAI Codex (ChatGPT OAuth)
OpenAI Codex OAuth is explicitly supported for use outside the Codex CLI, including OpenClaw workflows. Flow shape (PKCE):- 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 }
openclaw onboard → auth choice openai-codex.
Refresh + expiry
Profiles store anexpires timestamp.
At runtime:
- if
expiresis in the future → use the stored access token - if expired → refresh (under a file lock) and overwrite the stored credentials
- exception: reused external CLI credentials stay externally managed; OpenClaw re-reads the CLI auth store and never spends the copied refresh token itself
Multiple accounts (profiles) + routing
Two patterns:1) Preferred: separate agents
If you want “personal” and “work” to never interact, use isolated agents (separate sessions + credentials + workspace):2) Advanced: multiple profiles in one agent
auth-profiles.json supports multiple profile IDs for the same provider.
Pick which profile is used:
- 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)
Related
- Authentication — model provider auth overview
- Secrets — credential storage and SecretRef
- Configuration Reference — auth config keys