All writing

Running OpenRouter coding models through Claude Code

July 26, 2026 (1d ago)

How I routed Claude Code through OpenRouter, selected coding models, and made the setup practical on Windows.

Claude Code is built for Anthropic's coding harness, but OpenRouter can sit behind the same interface if you give Claude Code an Anthropic-compatible endpoint.

That is the useful trick. You are not replacing the harness. You are changing where the harness sends requests.

OpenRouter's Claude Code guide uses three environment variables:

ANTHROPIC_BASE_URL="https://openrouter.ai/api"
ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
ANTHROPIC_API_KEY=""

The empty ANTHROPIC_API_KEY value matters. If an old Anthropic key or cached login wins, Claude Code can fall back to the wrong auth path and report confusing model errors.

OpenRouter also warns that Claude Code is optimized for Anthropic models. That warning is real. Some OpenRouter models can answer normal prompts but behave oddly once the harness starts using tools, subagents, or JSON output. I treat each model as something to test inside the harness, not something to trust because the model page looks good.

Pick models for the harness, not the leaderboard

For this setup I tested two free OpenRouter models:

Ling 3.0 Flash is listed as a 124B-parameter mixture-of-experts model with about 5.1B active parameters per token, free pricing, and a 262K context window.

North Mini Code is a coding-focused mixture-of-experts model with 30B total parameters and 3B active parameters. OpenRouter lists it with a 256K context window, tool use support, and an Apache 2.0 open-weight release.

Those facts are useful, but they are not enough. A coding harness needs more than text completion. It needs the model to follow the tool protocol, recover after tool output, and stop cleanly when the task is done.

My rule for testing was simple:

  1. Confirm Claude Code routes to OpenRouter.
  2. Confirm the selected model slug is the one in use.
  3. Run a normal prompt.
  4. Run a small tool task.
  5. Check whether the final answer survives after the tool result.

That last step caught the interesting difference. Ling behaved well enough for basic harness use. North executed the tool correctly, but it sometimes left the final result field empty in non-interactive JSON output even though the streamed answer and tool execution worked.

That is not a failed setup. It is a compatibility note. The model can be useful, but I would not use it blindly for a long autonomous coding task until that final-output behavior is acceptable for the workflow.

Keep secrets out of files you commit

The OpenRouter API key should stay in a local environment variable or a local-only settings file. Do not commit it.

For a project-scoped setup, OpenRouter documents .claude/settings.local.json. That file can set the Claude Code environment for the project, but it must stay local if it contains a token.

The safer pattern is:

If you previously logged in to Claude Code with Anthropic, run /logout inside Claude Code, quit it, and start it again with the OpenRouter environment active.

Windows setup

On Windows, I prefer a PowerShell wrapper because it makes the environment explicit for one session. It also avoids changing global shell state while I test a model.

The wrapper sets the OpenRouter base URL, maps the OpenRouter key to ANTHROPIC_AUTH_TOKEN, clears ANTHROPIC_API_KEY, and selects the model for Claude Code's main roles.

The shape is:

$env:ANTHROPIC_BASE_URL = "https://openrouter.ai/api"
$env:ANTHROPIC_AUTH_TOKEN = $env:OPENROUTER_API_KEY
$env:ANTHROPIC_API_KEY = ""

$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "inclusionai/ling-3.0-flash:free"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "inclusionai/ling-3.0-flash:free"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "inclusionai/ling-3.0-flash:free"
$env:CLAUDE_CODE_SUBAGENT_MODEL = "inclusionai/ling-3.0-flash:free"

claude @args

For my local machine, I kept two commands:

claude-ling
claude-north

The first command selects inclusionai/ling-3.0-flash:free. The second selects cohere/north-mini-code:free.

That small wrapper makes switching models boring, which is what I want. The interesting part should be whether the model works inside the harness, not whether I remembered to set six variables in the right terminal.

Verify the model like code

A model route is not proven because the prompt returned one answer.

I want three checks:

For coding agents, the final answer matters. If the tool ran but the result field is empty, a human in an interactive session may still see enough. A script, automation, or task runner may not.

That is the main lesson from this setup. OpenRouter can make Claude Code route through different coding models, but the harness is the test. Use the model only after it proves it can survive the parts of the loop your workflow depends on.

Sources