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.
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 Populates /model with LunaRoute’s models; without it the picker lists only your ANTHROPIC_MODEL.
ANTHROPIC_CUSTOM_HEADERS X-LunaRoute-Client: claude-desktop Selects LunaRoute’s Claude-shaped alias list for /model — deliberate, not a typo.

Pick a model in /model — the list is LunaRoute’s Claude-shaped aliases (claude-opus-lr29, …) — or set ANTHROPIC_MODEL to a plain catalog id to skip aliases.

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 nothing — exit and you are done.
  • lunaroute setup claude-code wrote nothing either; it printed. Undo by deleting the lines you pasted (or the env block in ~/.claude/settings.json) and starting Claude Code again.
  • 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 the /model picker shows. The same request without the X-LunaRoute-Client header returns the normal catalog, which Claude Code rejects.

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.