Claude OpenRouter
Use OpenRouter models in Claude Code without giving up your native login or connectors.
Claude OpenRouter is a small, dependency-free CLI and loopback router. It
indexes OpenRouter's live catalog, gives you a searchable multi-select picker,
and places those favorites beside Claude's built-in models in /model. Native
Claude requests keep using Anthropic; explicitly labeled OpenRouter favorites
use your OpenRouter key. After setup, run the normal claude command.
Install
curl -LsSf https://xhluca.github.io/claude-openrouter/install.sh | sh
The installer prompts for your OpenRouter key without echoing it, fetches the
current catalog, and opens the model picker immediately. It installs for the
current user on Linux or macOS. If a credential already exists, setup shows its
path and asks whether to reuse it before offering a masked replacement prompt.
Max routing requires an existing Claude.ai login; run claude auth login first
if Claude Code is newly installed.
Or use uv:
uv tool install claude-openrouter
clor setup
For a one-off setup without installing the package first:
uvx claude-openrouter setup
pipx install claude-openrouter works too. The full command is
claude-openrouter; clor is the shorthand. Claude Code 2.1.242 or newer is
required for the multi-model picker.
Upgrade the installation in place at any time:
clor update
The updater uses the manager that owns the current installation, reports the
installed version before and after, and restarts an existing hybrid service.
clor upgrade is an alias. When moving from an older direct-routing release to
0.4.x, run clor setup once to activate hybrid routing.
Quick start
Refresh the local catalog:
clor index
fetch is an alias for index. index is the canonical name because the
result is a persistent local catalog used by selection and search.
Search refreshes the index first. Plain terms are case-insensitive substring
globs; *, ?, and bracket expressions use shell-style matching:
clor search claude
clor search 'anthropic/*' '*coder*'
clor search --regex '^(anthropic|google)/.*(sonnet|gemini)'
Select one exact model, several exact models, or open the interactive picker:
clor select anthropic/claude-sonnet-4.6
clor select --model openai/gpt-5.4
clor select --models anthropic/claude-opus-4.6 google/gemini-3.1-pro-preview
clor select
The positional value is shorthand for --model. Each non-interactive call
replaces the saved favorite set. In the picker, type a search and press Down or
Enter to browse its results. Press Enter or Space to select and deselect; press
Up past the first result or Esc to focus the search again. Press s while
browsing results, or Shift-S/Ctrl-S while typing a search, to save.
Launch Claude Code normally, then switch models normally:
claude
> /model
The selected rows are Claude Code's native picker rows, and model requests use
the provider shown in the row. Every local Claude Code entry point reads the
same settings, including claude --continue, claude --agent NAME, background
agents, and the claude agents view.
/model choice |
Upstream | Billing credential |
|---|---|---|
| Built-in Opus, Sonnet, or Haiku | Anthropic | Claude Max OAuth by default |
A row labeled · OpenRouter |
OpenRouter | Stored OpenRouter key |
The router never infers a provider from a bare third-party ID. OpenRouter rows
use a private clor/openrouter/ namespace, and an unknown or unfavorited model
fails closed. Selecting Opus cannot silently send it to OpenRouter.
Claude Code keeps its native Claude.ai authentication, so connectors remain available and the external-auth warning is absent. If you prefer direct Anthropic API billing for built-in Claude models, configure it separately:
clor setup --anthropic-auth api
# or, after setup:
clor config --anthropic-auth api
# Return native Claude models to Max subscription billing:
clor config --anthropic-auth max
The Anthropic API key is stored inside the router and is not exported as
ANTHROPIC_API_KEY, preserving Claude's native login and connectors. clor config --anthropic-key-stdin is available for non-interactive secret input.
Deferred tool loading is disabled because non-Anthropic OpenRouter models
reject that Anthropic-specific protocol; connector tools remain available and
are loaded eagerly instead. This is required for GLM in claude agents.
Commands
| Command | Purpose |
|---|---|
clor index |
Fetch and cache the current OpenRouter model catalog |
clor fetch |
Alias for index |
clor search QUERY... |
Refresh, then search names, IDs, and descriptions |
clor setup |
Run the install-time key and model setup again |
clor select [MODEL] |
Replace /model favorites exactly |
clor config |
Replace and validate the stored OpenRouter key |
clor doctor |
Check the service, favorites, and native Claude login |
clor claude [ARGS...] |
Compatibility alias for claude [ARGS...] |
clor update |
Install the latest release and report the version change |
clor reset |
Restore the original Claude settings and delete tool data |
clor uninstall |
Reset the integration and remove a curl/uv installation |
Every catalog command also accepts --json where useful. API keys are never
accepted as command-line arguments; automation can pipe one to setup --key-stdin or config --key-stdin.
What it changes
┌─ Claude model ─────► Anthropic
Claude Code ─► 127.0.0.1 router ────┤
└─ clor/openrouter/* ► OpenRouter
- Stores the key at
~/.config/claude-openrouter/credentialwith mode0600. - Runs a loopback-only router on
127.0.0.1:9417, supervised by a systemd user service on Linux or a LaunchAgent on macOS. Minimal containers without a service manager use a detached process for the container lifetime. - Adds the local endpoint, a random local-service token, and OpenRouter picker
rows to
~/.claude/settings.json. Provider API keys never appear there. - Does not set
ANTHROPIC_API_KEYorapiKeyHelperwhen a native login exists. - Strips OAuth and Anthropic keys before OpenRouter requests, strips the OpenRouter key before Anthropic requests, and allows only selected OpenRouter model IDs.
- Saves the fields it replaces in a private, versioned backup and restores them
exactly with
clor resetorclor uninstall. - Migrates settings created by older claude-openrouter releases automatically the next time setup or selection runs.
Claude Code itself applies one endpoint and authentication context to an entire process. The local router supplies the missing per-model boundary while keeping Claude Code unmodified. If the router is unavailable or cannot classify a model, the request errors instead of falling back to another paid provider.
Claude Code is optimized for Anthropic models. OpenRouter can accept other model IDs through its Anthropic-compatible endpoint, but models differ in tool use, thinking blocks, context handling, and Claude Code compatibility. Prefer models that OpenRouter documents as suitable for agentic tool use.
Reset and uninstall
Stop the router, restore the pre-install Claude settings, and keep the command:
clor reset
Restore settings, remove the credential and index, and uninstall a curl/uv tool installation:
clor uninstall
Reset and uninstall only reverse fields managed by Claude OpenRouter in
~/.claude/settings.json. They intentionally leave project-owned settings such
as .claude/settings.local.json unchanged. If Claude Code reports an unsafe
project permission after uninstalling, open /permissions, select the named
local allow rule, and remove it. Do not replace it with a broader wildcard.
Demo
The animation above is rendered in real time from an end-to-end asciinema
capture: the public curl installer, progressively masked key entry, a live
OpenRouter search for z-ai/glm-5.3-flash, exact selection, Claude Code's
native /model picker launched through plain claude, and a real model response.
The scripts verify the saved assistant turn and reject any cast containing the
credential before publishing it. Sanitization replaces the randomized temporary
path with ~; release-only command, settings-path, and version labels may be
rebased without altering the captured Claude interaction or model response.
Watch the MP4 or reproduce the capture.
Development
git clone https://github.com/xhluca/claude-openrouter.git
cd claude-openrouter
uv run --with pytest pytest
uv run --with ruff ruff check .
scripts/live-docker-check.sh /path/to/openrouter-key ~/.claude
The Docker check mounts temporary copies of Claude OAuth state and the key only
at runtime. It makes live, billable Max and OpenRouter calls, dispatches a GLM
5.3 Flash background agent, and launches the real claude agents terminal UI.
License
Acknowledgements
Claude Code Router (CCR)
helped establish the broader Claude Code routing space. CCR is a full,
self-contained routing and UI-based management system spanning providers,
profiles, routing rules, and more. Claude OpenRouter is intentionally narrower:
it is a simple connection from Claude Code to OpenRouter, installs with one
small Bash command (or uv/uvx), and does not aim to cover CCR's full
management spectrum.
Metadata
Release files for claude-openrouter 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| claude_openrouter-0.4.0.tar.gz | 645.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| claude_openrouter-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 682.7 kB
Release files / claude_openrouter-0.4.0.tar.gz
| Download URL | claude_openrouter-0.4.0.tar.gz |
|---|---|
| Size | 645.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c75c46162eaba992c2e8984112131bf7aa314cf865dfdd67c1540a664d85e419
|
|
BLAKE2b-256 checksum How to use checksums |
819ee19af07134547839e92176ad604815621b6b27f586f4004b1c1949c4a48f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / claude_openrouter-0.4.0-py3-none-any.whl
| Download URL | claude_openrouter-0.4.0-py3-none-any.whl |
|---|---|
| Size | 37.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f6190b43dcb1ba820baceb03927041328e871e3b77271a6341447c6ffe5f55c
|
|
BLAKE2b-256 checksum How to use checksums |
b6eca34e9e7946c6a24a4f3fddc7f51f534727b1c3e1eb1b37e3d456c0a41cdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|