Skip to content
LUNAROUTEDocs

Claude Code

Claude Code routes through LunaRoute with environment variables: ANTHROPIC_BASE_URL points it at the gateway and ANTHROPIC_AUTH_TOKEN carries your lr_ key as a Bearer token. Both are read from the environment, so nothing here edits Claude Code’s own config.

Install the CLI (CLI setup) and sign in once:

Terminal window
npm install -g @lunaroute/cli
lunaroute login
lunaroute run claude-code

run starts Claude Code wired to LunaRoute for that session only — it sets the variables in the child process, writes no file, and edits nothing in ~/.claude/. Quit, and you are back to your normal setup. That makes it the cheapest way to try LunaRoute; claude is an alias for the same command, so lunaroute run claude behaves identically.

  • lunaroute run claude-code --model <id> starts on a specific model (default: the first chat model in your catalog).
  • Everything after -- goes straight to Claude Code: lunaroute run claude-code -- --resume.
  • It uses your stored login, so run lunaroute login first (a LUNAROUTE_API_KEY in your environment is not enough for run — it errors with Not logged in).
  • Claude Code must already be installed; run only launches it.
  • The /model picker lists your whole catalog for that session too: run passes the lineup inline as --settings (same list setup writes permanently), so no file is needed.
Terminal window
lunaroute setup claude-code

It prints the variables to add to your shell profile:

Variable Value Why
LUNAROUTE_API_KEY your lr_… key The credential every other line references.
ANTHROPIC_BASE_URL https://gw.lunaroute.com Routing root; Claude Code appends /v1/messages itself.
ANTHROPIC_AUTH_TOKEN $LUNAROUTE_API_KEY Sent as Authorization: Bearer. lr_ keys are recognised and stripped before the request is forwarded.
ANTHROPIC_MODEL a catalog model id Your default model.
ANTHROPIC_DEFAULT_HAIKU_MODEL the same model id Pins Claude Code’s background model (titles, summaries, compaction) at LunaRoute instead of Anthropic’s Haiku id, which LunaRoute does not serve.
CLAUDE_CODE_GATEWAY_HINT_HEADERS 1 Lets LunaRoute fast-path auxiliary requests (auto-mode classifier) instead of queueing them behind your session.
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY 1 Fallback only (Claude Code < 2.1.242): populates /model by discovery. Current builds read the lineup setup writes instead.
ANTHROPIC_CUSTOM_HEADERS X-LunaRoute-Client: claude-desktop Fallback only (Claude Code < 2.1.242): selects LunaRoute’s Claude-shaped alias list for that discovery.
CLAUDE_CODE_MAX_CONTEXT_TOKENS the pinned model’s window Claude Code assumes 200K for any model id it does not recognize, whatever /v1/models reports. A below-200K model would otherwise run until LunaRoute rejects the prompt.
CLAUDE_CODE_MAX_OUTPUT_TOKENS the pinned model’s output cap Otherwise Claude Code asks for 32K max_tokens. Claude Code clamps this to its own maximum, so a bigger model cap buys what your build allows and no more.

Both window variables are omitted when the catalog has no such number for the model (a BYOK endpoint, say) — LunaRoute will not invent a default for you.

Pick a model in /model. It lists every model your organization can reach — including models LunaRoute routes rather than serves, so a BYOK provider you connected shows up too. The list comes from the modelPicker lineup setup writes into ~/.claude/settings.json (Claude Code 2.1.242+), whose rows are sent verbatim, so a plain catalog id routes as itself. Rows you already had are kept as written, ours are added or removed on every run to match your catalog (a row we added keeps its label), so setup never takes over your own lineup.

Older builds ignore that key and fall back to gateway discovery, which keeps only ids containing claude/anthropic — hence the ANTHROPIC_CUSTOM_HEADERS fallback, whose picker lists LunaRoute’s Claude-shaped aliases (claude-opus-lr29, …) instead. Either way you can set ANTHROPIC_MODEL to a plain catalog id and skip the picker.

setup prints them and writes nothing to your shell profile — paste them in yourself:

  • Linux/macOS — add the exports to ~/.zshrc/~/.bashrc, then restart Claude Code. Or run lunaroute run claude-code in the meantime.
  • Windows (PowerShell, 5.1-safe) — the CLI prints $env:NAME = 'value' lines for the session plus the persistent form, and tells you to open a new window: user-scope variables do not reach shells that are already running. Add these to your shell profile does not apply on Windows.

If you would rather use ~/.claude/settings.json, note that its env values are literal — the key would be written into the file instead of read from $LUNAROUTE_API_KEY. That reaches the Claude Code CLI on any platform, but it is still not how Claude Desktop routes.

  • lunaroute run claude-code wrote no file — it passes the same lineup as a one-session --settings value and sets the rest in the child process. Exit and you are done.
  • lunaroute setup claude-code merges one key into ~/.claude/settings.json: the modelPicker lineup for /model. Everything else in that file (permissions, hooks, theme) is untouched, and the rest of the setup still only prints — it writes nothing to your shell profile. Undo with lunaroute setup claude-code --remove, which prints the variables to delete — POSIX and PowerShell, including the persistent Windows user variables — with a caution to drop from that list anything you did not add, and names the rows to delete — the ones whose description is Managed by LunaRoute; rows you wrote yourself, and every other key in the file, stay. --remove itself changes nothing.
  • The CLI keeps its own credential separately, outside Claude Code: lunaroute login (or setup --key) stores your lr_… key in ~/.config/lunaroute/. If you want that gone too, run lunaroute logout. Neither command above uploaded or edited anything else.
  • Nothing here touches Claude Desktop. To undo the Desktop app, use lunaroute setup claude-desktop --remove.
Terminal window
curl https://gw.lunaroute.com/v1/models \
-H "Authorization: Bearer $LUNAROUTE_API_KEY" \
-H "X-LunaRoute-Client: claude-desktop"

On Windows (PowerShell, 5.1-safe) — never the bare name curl, which PowerShell 5.1 aliases to Invoke-WebRequest; curl.exe is also fine and ships with Windows 10 1803+:

Terminal window
Invoke-RestMethod -Uri https://gw.lunaroute.com/v1/models `
-Headers @{ Authorization = "Bearer $env:LUNAROUTE_API_KEY"; "X-LunaRoute-Client" = "claude-desktop" }

You should get the Claude-shaped alias list that the fallback picker path shows (Claude Code before 2.1.242). The same request without the X-LunaRoute-Client header returns the normal catalog — which is exactly what the modelPicker lineup lists, so claude + /model on a current build shows those same ids under your models’ own names.

The CLI, run and setup claude-code are verified on Linux; the Windows forms above are the ones the CLI itself prints. WSL is a separate environment — Windows user variables do not cross into a distribution (WSLENV is the bridge), the npm/Node install is separate per side, and a lunaroute login on one side is invisible on the other. Install, log in and run again inside the distribution; CLI setup covers the details, including the npx failure modes on Windows.

  • Claude Desktop — the desktop app, whose routing is not env vars.
  • CLI — install, run, setup, and the Windows/WSL notes.
  • Harness setup — the other harnesses.
  • Models API — the catalog /v1/models serves.