Set up
Claude Code
Sign in to Claude Code with yourclaude.ai account using /login. Clear any existing ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, or apiKeyHelper values (such as from a previous OpenRouter API-key setup) so they do not override your claude.ai login, then point Claude Code at OpenRouter with your OpenRouter API key:
~/.claude/settings.json. Settings in that file override shell exports, so the empty ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY entries prevent leftover shell exports from overriding your subscription. Never put your OpenRouter API key in a repository’s .claude/settings.json.
/status in Claude Code to confirm Anthropic base URL is https://openrouter.ai/api and your claude.ai login is active.
Codex CLI
Sign in to Codex with your ChatGPT account usingcodex login. Export your OpenRouter API key in your shell profile (~/.zshrc, ~/.bashrc, or PowerShell $PROFILE):
~/.codex/config.toml (%USERPROFILE%\.codex\config.toml on Windows). Leave out env_key and [model_providers.openrouter.auth] so Codex sends your ChatGPT login instead of replacing it. Codex ignores model_provider and model_providers in project-local .codex/config.toml files.
codex from a shell with OPENROUTER_API_KEY set. If you use the Codex desktop app, make OPENROUTER_API_KEY visible to GUI apps as described in the Codex Desktop App guide.
What works and what does not
Not available at all
- Claude Desktop app: Does not read
ANTHROPIC_BASE_URLor~/.claude/settings.json, and its third-party gateway mode disablesclaude.aisubscriptions. - Cloud sessions (Claude Code on the web, Claude Tag, Codex cloud tasks): Provider-hosted cloud sessions bypass your local configuration.
- Compliance and data residency on subscription traffic: Subscription requests always go to your provider’s standard endpoint under your plan’s terms, not HIPAA, zero data retention, or regional endpoints.
Roll back
Claude Code
Unset the variables in your current shell:ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, and any empty ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY entries from your shell profile (~/.zshrc, ~/.bashrc, or PowerShell $PROFILE), from ~/.claude/settings.json, and from any project .claude/settings.local.json. Then open a new shell and restart claude.
Run /status to confirm Anthropic base URL is no longer set. If Claude Code prompts you to sign in, run /login.
Codex CLI
Removemodel_provider = "openrouter" and the [model_providers.openrouter] block from ~/.codex/config.toml, then restart codex. If Codex prompts you to sign in, run codex login.