Claude Code for FREE Forever: OpenRouter Setup Guide (2026)

Claude Code is one of the most powerful AI coding assistants available today — but its default Anthropic API pricing can add up fast for heavy users. The good news: you can connect Claude Code to OpenRouter and use it completely free, tapping into a library of capable open-source models with zero monthly cost. In this guide, based on the Thetips4you tutorial, you’ll learn exactly how to set that up in minutes.


What You’ll Learn in This Post

  • What OpenRouter is and why it’s a game-changer for Claude Code users
  • How to create your free OpenRouter account and generate an API key
  • The exact environment variables and configuration needed
  • How to verify your connection is working
  • Which free models work best for coding tasks
  • Rate limits to be aware of on the free tier

Watch the Full Video Tutorial

If you prefer to follow along visually, watch the complete step-by-step tutorial below:

 https://www.youtube.com/embed/GRUjApPqCoE

Tutorial by Thetips4you


What Is OpenRouter and Why Use It With Claude Code?

OpenRouter is an API aggregator that gives you unified access to dozens of AI models — including models from Anthropic, Meta, Google, Mistral, and many open-source providers — through a single API endpoint. Crucially, it offers a free tier with 29+ models that require no credit card and no subscription.

The key insight that makes this work: Claude Code lets you override its default API endpoint. By pointing ANTHROPIC_BASE_URL at OpenRouter instead of Anthropic, Claude Code sends its requests to OpenRouter’s servers, which route them to whichever model you choose — including the free ones.

SetupCostModels Available
Default (Anthropic API)Pay-per-token (~$3–$15 per million tokens)Claude 3.5, Claude 3, Claude 4
OpenRouter Free Tier$029+ free models (Llama, DeepSeek, Gemma, Qwen, etc.)
OpenRouter PaidPay-per-token (often cheaper than direct)200+ models including Claude

Prerequisites

Before you start, make sure you have:

  • Claude Code installed — via npm install -g @anthropic-ai/claude-code, Homebrew, or the native installer
  • A terminal (macOS Terminal, Linux shell, or Windows WSL/PowerShell)
  • An OpenRouter account — free to create at openrouter.ai

Note: If you previously logged into Claude Code with an Anthropic account, run /logout inside Claude Code first to clear stored credentials before applying the OpenRouter config.


Step-by-Step Setup: Connect Claude Code to OpenRouter

Step 1: Create Your OpenRouter Account and API Key

  1. Go to openrouter.ai and sign up for a free account
  2. Navigate to API Keys in your dashboard (or go to openrouter.ai/keys)
  3. Click “Create Key” — no credit card required for free models
  4. Copy your API key — it will look like: sk-or-v1-xxxxxxxxxxxxxxxxxx

Keep this key safe — you’ll need it in the next step.


Step 2: Configure Your Environment Variables

You have two options: a global shell profile (applies everywhere) or a project-level config (per project). Choose whichever fits your workflow.

Option A — Shell Profile (Global, Recommended for Most Users)

Add these lines to your shell profile file (~/.zshrc~/.bashrc, or ~/.config/fish/config.fish):

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=""   # Must be set to empty — prevents conflicts

After saving, restart your terminal or run:

source ~/.zshrc   # (or ~/.bashrc, depending on your shell)

Option B — Project-Level Config (Per Project)

Create a file at .claude/settings.local.json inside your project root:

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

Important: Do NOT use a .env file — Claude Code’s native installer does not read .env files. Use the shell profile or settings.local.json instead.


Step 3: (Optional) Pin a Specific Free Model

By default, OpenRouter will route your request to an available model. To lock in a specific free model, add:

export ANTHROPIC_DEFAULT_SONNET_MODEL="meta-llama/llama-3.3-70b-instruct:free"

Or set individual model overrides for each Claude Code role:

export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen/qwen3-coder-480b-a35b-instruct:free"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek/deepseek-r1:free"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="google/gemma-3-27b-it:free"

Step 4: Launch Claude Code and Verify the Connection

Navigate to your project folder and start Claude Code:

cd /path/to/your/project
claude

Once inside, run the status check command:

/status

Look for this in the output to confirm it’s working:

Anthropic base URL: https://openrouter.ai/api

If you see that line, you’re live — Claude Code is now running through OpenRouter.


Best Free Models for Coding Tasks (April 2026)

As of April 2026, OpenRouter offers 29 free models. Here are the top picks for coding work:

ModelBest ForModel ID
Qwen3-Coder 480BComplex multi-file refactors, architectureqwen/qwen3-coder-480b-a35b-instruct:free
DeepSeek R1Reasoning-heavy tasks, debugging logicdeepseek/deepseek-r1:free
Llama 3.3 70BGeneral coding, fast responsesmeta-llama/llama-3.3-70b-instruct:free
Devstral 2Lightweight tasks, quick editsmistralai/devstral-2:free
Gemma 3 27BBalanced performance and speedgoogle/gemma-3-27b-it:free

Free models won’t match Claude Opus on extremely complex architectural reasoning, but for day-to-day coding tasks — editing files, writing functions, debugging, and generating boilerplate — they perform very well.


Rate Limits on the Free Tier

Free models on OpenRouter come with usage limits. As of 2026:

  • ~20 requests per minute per model
  • ~200 requests per day per model

Tips to stay within limits:

  • Spread requests across 2–3 different free models
  • Use smaller models (Gemma 3, Devstral) for quick tasks and reserve larger models (Qwen3-Coder, DeepSeek R1) for complex work
  • Add $5–10 in OpenRouter credits if you hit limits — you’ll get access to many paid models at rates often cheaper than Anthropic’s direct pricing

Key Takeaways

  • OpenRouter acts as a free API bridge — it lets Claude Code talk to free AI models without touching Anthropic’s billing
  • Two config methods — shell profile (global) or settings.local.json (per project)
  • The magic variable is ANTHROPIC_BASE_URL=https://openrouter.ai/api — that’s what redirects all Claude Code traffic to OpenRouter
  • ANTHROPIC_API_KEY must be set to empty to prevent Claude Code from trying to authenticate with Anthropic
  • Verify with /status — always check that the base URL shows OpenRouter before you start working
  • Best free coding model right now is Qwen3-Coder 480B for heavy tasks, Llama 3.3 70B for everyday use

Frequently Asked Questions

Is this actually free, or will I get charged eventually?

OpenRouter’s free tier is genuinely free — no credit card required, and free models are clearly marked with a :free suffix. You only get charged if you explicitly add credits to your account and use paid models. Stick to :free model IDs and you’ll never see a bill.

Will Claude Code work exactly the same with OpenRouter?

Most features work identically. The main difference is that you’re using a different underlying model (e.g., Llama or Qwen instead of Claude). Complex multi-step reasoning tasks may produce slightly different quality results compared to Claude Opus, but for most coding work the difference is minimal.

What if I get a “model not found” or authentication error?

Double-check three things: (1) ANTHROPIC_API_KEY is set to an empty string "" — not unset, but explicitly empty. (2) ANTHROPIC_AUTH_TOKEN holds your sk-or-v1-... key. (3) ANTHROPIC_BASE_URL ends with /api (not /api/v1). Run /logout inside Claude Code if you’re still having issues, then restart.

Can I switch back to the real Claude (Anthropic API) when needed?

Yes. For shell profile users, just comment out the OpenRouter variables and source your profile again. For project-level config users, delete or rename .claude/settings.local.json. Claude Code will fall back to its normal Anthropic login.

What are the best free models for writing code specifically?

For 2026, Qwen3-Coder 480B is the strongest free option for complex code. DeepSeek R1 handles debugging and reasoning tasks well. Llama 3.3 70B is a solid all-rounder. Use the :free suffix in the model ID to ensure OpenRouter routes to the free version.


Conclusion

Connecting Claude Code to OpenRouter is one of the smartest moves a developer can make in 2026 — you get a fully functional AI coding assistant with zero ongoing cost, and the setup takes less than five minutes. Whether you’re a solo developer watching your API budget or just getting started and not ready to commit to a paid plan, this approach gives you access to capable models for real work without spending a cent.

Check out the Thetips4you YouTube channel for more practical tutorials on Claude, AI development tools, DevOps, and Docker.


Source: Claude Code for FREE Forever — OpenRouter Setup (2026) by Thetips4you