Skip to content
Advertisement

How to Use Claude Code for Free (OpenRouter Setup Guide)

SumitSumit···11 min read
Claude Code terminal connected to OpenRouter free models

Claude Code is one of the best AI coding agents around, but running it on Anthropic's API gets expensive fast. A long session on Claude Opus 5.5 can cost several dollars before lunch.

The fix is to point Claude Code at OpenRouter, an API aggregator that gives you one endpoint for hundreds of models, including a rotating set of free ones. OpenRouter speaks the same API format as Anthropic, so Claude Code connects to it natively. No proxy, no wrapper script.

Why Run Claude Code Through OpenRouter?

  • Free models with real coding ability. Several open-weight coding models are free on OpenRouter, and the best of them score close to last year's paid frontier models on agentic coding benchmarks.
  • One key, many models. Swap between free models, cheap paid ones, and Claude itself with a single /model command.
  • Automatic failover. If one provider is rate limited or down, OpenRouter reroutes to another instead of throwing an error mid-session.
  • Per-task model mixing. Claude Code uses different model slots for heavy reasoning, everyday coding, and quick background jobs. You can fill each slot with a different model.

What You Need

  • Claude Code installed (curl -fsSL https://claude.ai/install.sh | bash, or npm install -g @anthropic-ai/claude-code)
  • A free OpenRouter account and an API key

You do not need an Anthropic account or API key for this setup.

How to Set Up Claude Code with OpenRouter

1. Create an OpenRouter API key

Log in to openrouter.ai, open Settings > API Keys, and create a new key. Copy it somewhere safe; it is only shown once.

2. Add the environment variables

Open your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish) and add:

export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

What each line does:

  • ANTHROPIC_BASE_URL sends every request to OpenRouter instead of Anthropic.
  • ANTHROPIC_AUTH_TOKEN is the key Claude Code sends. It must come after the OPENROUTER_API_KEY line, or it expands to nothing.
  • The blank ANTHROPIC_API_KEY is intentional. It stops Claude Code from using an Anthropic key that may already be set elsewhere.
  • CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY lets the /model picker list OpenRouter models, not just Claude ones.

Prefer per-project config? Put the same values in .claude/settings.local.json in your project root:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
    "ANTHROPIC_AUTH_TOKEN": "sk-or-v1-your-key-here",
    "ANTHROPIC_API_KEY": "",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}

The .local file is git-ignored by default, so your key stays out of the repo.

3. Reload and log out of Anthropic

source ~/.zshrc

If you were previously signed in to Claude Code with an Anthropic account, run /logout inside Claude Code once, then restart it.

4. Verify the connection

Launch claude in a project folder and run:

/status

You should see ANTHROPIC_AUTH_TOKEN as the auth source and https://openrouter.ai/api as the base URL. Send a test prompt and watch it appear on the OpenRouter Activity page.

How to Switch Models in Claude Code

Per session: the /model command

/model poolside/laguna-s-2.1:free

This switches the active model immediately. Use the full OpenRouter ID, in provider/model-name format. Free variants end in :free.

Permanently: map the model slots

Claude Code does not ask for "a model". It asks for an Opus-class, Sonnet-class, or Haiku-class model depending on the job, and spawns sub-agents for side tasks. Each slot has its own variable:

VariableWhat Claude Code uses it for
ANTHROPIC_DEFAULT_OPUS_MODELPlanning and harder reasoning
ANTHROPIC_DEFAULT_SONNET_MODELEveryday coding (the one that matters most)
ANTHROPIC_DEFAULT_HAIKU_MODELQuick background jobs like titles and summaries
CLAUDE_CODE_SUBAGENT_MODELSub-agents spawned during a task

A free setup that works well:

export ANTHROPIC_DEFAULT_OPUS_MODEL="thinkingmachines/inkling:free"
export ANTHROPIC_DEFAULT_SONNET_MODEL="poolside/laguna-s-2.1:free"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="cohere/north-mini-code:free"
export CLAUDE_CODE_SUBAGENT_MODEL="cohere/north-mini-code:free"

Spreading slots across different providers also spreads the load, so one busy model is less likely to stall the whole session.

Hands off: openrouter/free

OpenRouter's free router picks a free model at random for each request, filtered to models that support what the request needs (tool calling, images, and so on):

export ANTHROPIC_DEFAULT_SONNET_MODEL="openrouter/free"

It is the lowest-effort option, but quality jumps around from request to request. Fine for quick questions, frustrating for a long refactor.

Best Free Models for Claude Code

OpenRouter currently lists 17 free models. Some are tiny, some are domain models for health or finance, and one is a content-safety filter. These are the ones that hold up for coding in an agent loop. All support tool calling, which Claude Code needs to read files, edit code, and run commands.

Top picks

Poolside Laguna S 2.1 (poolside/laguna-s-2.1:free)

The best free coding model right now, and the one to start with. It is built specifically as a coding agent: 118B parameters with only 8B active, so it is quick. Poolside reports 70.2% on Terminal-Bench 2.1, ahead of models more than ten times its size, plus 78.5% on SWE-Bench Multilingual. Context is 256K tokens, with up to 32K tokens of output per reply. Weights are open, so you can self-host it later if you outgrow the free tier.

Thinking Machines Inkling (thinkingmachines/inkling:free)

A 975B-parameter general model with a 1M-token context window and image input. It scores 63.8% on Terminal-Bench 2.1, a step below Laguna S for pure coding, but the huge context and image support make it the better choice for planning across a big codebase or working from UI screenshots. A good fit for the Opus slot.

NVIDIA Nemotron 3 Ultra (nvidia/nemotron-3-ultra-550b-a55b:free)

NVIDIA's largest open reasoning model, with a 1M-token context window. It scored 56.4% on Terminal-Bench 2.1, so it trails the two above on coding, but it is a strong reasoner and one of the most-used free models on OpenRouter. Use it as the backup when the top two are busy.

Fast and light

Cohere North Mini Code (cohere/north-mini-code:free)

A small coding model (30B total, 3B active) that Cohere says scores 67.6% on SWE-bench Verified. It is fast, which makes it ideal for the Haiku and sub-agent slots where speed matters more than depth.

Qwen3.8 27B (qwen/qwen3.8-27b:free) and Gemma 4 31B (google/gemma-4-31b-it:free)

Dense mid-size models with 256K context and image input. Both handle boilerplate, docs, tests, and explaining code well. Less reliable on long multi-step edits.

Skip these for coding

  • liquid/lfm-2.5-2.6b:free: Liquid itself advises against using it for agentic coding.
  • inclusionai/ling-3.0-flash-sante:free and -fin:free: tuned for health and finance.
  • nvidia/nemotron-3.5-content-safety:free: a moderation filter with no tool calling.

Quick reference

Model IDContextImagesBest slot
poolside/laguna-s-2.1:free256KNoSonnet (daily coding)
thinkingmachines/inkling:free1MYesOpus (planning, big repos)
nvidia/nemotron-3-ultra-550b-a55b:free1MNoBackup for Sonnet or Opus
cohere/north-mini-code:free256KNoHaiku, sub-agents
qwen/qwen3.8-27b:free256KYesBoilerplate, docs, screenshots
google/gemma-4-31b-it:free256KYesFallback, vision + code
poolside/laguna-xs-2.1:free256KNoLightweight coding
openrouter/freevariesvariesHands-off, random free model

Model list and context sizes from the OpenRouter models API, checked 2026-09-26. Benchmark scores are the model makers' own published numbers (Poolside, Cohere).

Free Tier Rate Limits (and How to Work Around Them)

OpenRouter's limits for :free models:

AccountPer minutePer day
Never bought credits (under $10 lifetime)20 requests50 requests
Bought $10+ in credits at any point20 requests1,000 requests

Source: OpenRouter API limits docs, checked 2026-09-26.

Fifty a day is tight. Claude Code is chatty: one task can mean a dozen requests as it reads files, edits, and runs commands. Your options:

Buy $10 of credits once. This is the real answer for anyone using Claude Code regularly. The 1,000/day limit is unlocked by your lifetime purchases, not your balance, so free-model use does not burn the credits. They stay available for the occasional paid model call.

Switch models when one is busy. Popular free models get congested, and the provider returns a 429 error even if you are under your own limit. Switching to another free model usually fixes it instantly:

/model thinkingmachines/inkling:free

This does not raise your daily cap, which is shared across all free models.

Keep cheap jobs off your best model. Mapping the Haiku and sub-agent slots to North Mini Code (as in the setup above) keeps background traffic from competing with your main coding model.

Limitations to Know About

Tool calling is the weak spot. Claude Code's file edits, bash commands, and sub-agents all run on structured tool calls, and Claude models are trained heavily for exactly this pattern. Free models vary: Laguna S and North Mini Code are built for agent loops and hold up well, while general models can loop, forget to call tools, or format edits wrong on long tasks.

Some Claude Code features are Claude-only. Extended thinking, prompt caching, and fast mode are built around Anthropic's models. They may be ignored or behave differently on other models. If output looks strange, switch to anthropic/claude-sonnet-5 briefly: if the problem disappears, it was the free model, not your setup.

Free prompts may be logged. Some free providers log prompts or use them for training. Do not send proprietary code or secrets through free models. Check each model's provider policy on its OpenRouter page.

Not for production. OpenRouter's own docs note that Claude Code is optimised for Anthropic models. Free models are great for side projects, learning, and low-stakes work. For client code or automated pipelines, use a paid model.

For a fully offline alternative on your phone, see our guide to running a local LLM on Android. If you are building your own agents, our look at Google Home MCP for AI agents shows how the same tool-calling protocol reaches beyond code. And for a broader list of free tools to self-host, see our best open source projects for home labs.

FAQs

Is it allowed to use Claude Code with OpenRouter?
Yes. Claude Code officially supports custom API gateways through ANTHROPIC_BASE_URL, and OpenRouter publishes a dedicated Claude Code integration guide.
Is Claude Code itself free?
The Claude Code app is free to install. What costs money is the model behind it. Pointing it at OpenRouter's free models lets you use it without paying for any model usage, within the daily rate limits.
Which free model is best for Claude Code?
Poolside Laguna S 2.1 (poolside/laguna-s-2.1:free) is the strongest free coding model on OpenRouter right now. Use Thinking Machines Inkling for large codebases and Cohere North Mini Code for background tasks.
Can I still use paid Claude models through OpenRouter?
Yes. Every Claude model on OpenRouter works, including anthropic/claude-sonnet-5 and anthropic/claude-opus-5.5. You pay OpenRouter's per-token price, which matches or slightly exceeds Anthropic's direct pricing, in exchange for failover across providers.
Why do I get 'No endpoints found that support tool use'?
The model you picked does not support tool calling, or its only tool-capable provider is down. Switch to a model from the table above, all of which support tools.
What happens when a free model goes offline mid-session?
The next request fails with an error. Run /model with another free model ID and carry on; your conversation context is kept.
Can I use free models in CI/CD pipelines?
Technically yes, but even the 1,000 requests a day limit runs out quickly with automated runs, and free providers may log your code. Use a paid model with a spending cap set in OpenRouter instead.
How do I switch back to Anthropic's API?
Remove or comment out ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and the blank ANTHROPIC_API_KEY from your shell profile (or delete .claude/settings.local.json), reload your shell, and log in to Claude Code with your Anthropic account.

The Bottom Line

Free models on OpenRouter are good enough for real coding sessions now. Laguna S 2.1 in particular handles multi-file edits and terminal work at a level that cost money a year ago.

Setup takes five minutes. The only real decision is whether to buy $10 of credits once to lift the daily cap from 50 to 1,000 requests. If you use Claude Code more than casually, do it.

SSumit

Sumit

Contributor

Hi, I'm Sumit, Being an introvert I have always been obsessed with technology-computers and reading dozens of posts to learn, find answers out of my curiosity. I love to write as I explore more.

175 articles writtenView all posts by Sumit →

Related articles

See all