GenAI Unplugged

Run Claude Code free with OpenRouter

Run Claude Code for free with OpenRouter models: three setup methods, the settings JSON, and the stuck onboarding screen fix.

Table of contents

Claude Code can run on a free OpenRouter model instead of a paid Anthropic subscription or API credits. This lesson covers creating an OpenRouter key, writing one project settings file with six model lines, and clearing a cached login and a first-run wizard that otherwise block the setup.

What you will be able to do

  • Create an OpenRouter key that starts with sk-or-v1- and store it safely
  • Install Claude Code and confirm it with claude --version
  • Write .claude/settings.local.json so one project runs on openrouter/free
  • Get past the first-run login wizard on a fresh machine
  • Check that the redirect to OpenRouter took effect with /status

Before you start

  • A free OpenRouter account at openrouter.ai, no card needed for key creation
  • A terminal: Terminal on macOS, PowerShell or WSL on Windows, or a Linux shell
  • Windows 10 or newer, macOS 13 or newer, or Linux such as Ubuntu 20.04+, with 4 GB of RAM and no GPU
  • A project folder where you want free models to run

Reference

Setting or file Value or purpose
ANTHROPIC_BASE_URL https://openrouter.ai/api with no /v1 on the end, because Claude Code adds /v1/messages itself
ANTHROPIC_AUTH_TOKEN Your OpenRouter key, which begins sk-or-v1-
ANTHROPIC_API_KEY Empty string "", so no x-api-key header is sent and Anthropic is not billed
ANTHROPIC_MODEL openrouter/free, the default model
ANTHROPIC_DEFAULT_OPUS_MODEL, SONNET, FABLE, HAIKU openrouter/free for each of the four roles. Any role left unset keeps its paid Anthropic default
CLAUDE_CODE_SUBAGENT_MODEL openrouter/free, covers background subagent work
CLAUDE_CODE_MAX_CONTEXT_TOKENS 200000, so Claude Code does not compact earlier than needed. Optional
.claude/settings.local.json Per-project env block. Plain JSON, no comments. Add it to .gitignore because it holds your key
~/.claude.json Add "hasCompletedOnboarding": true to skip the first-run wizard. Edit it, do not overwrite it
~/.claude/settings.json Machine-wide env block

Common errors and fixes

What goes wrong The fix
"Not logged in, please run login", or a model-not-found error on a model that exists A cached Anthropic login is checked before your settings file. Run /logout inside a session, close it, and relaunch
/logout does not help and requests still go to Anthropic A real ANTHROPIC_API_KEY is set in your shell profile. Remove it from .zshrc or .bashrc, or override it with an empty string in the settings file
The request fails with a 404 HTML page The base URL ends in /api/v1, which resolves to /api/v1/v1/messages. Use https://openrouter.ai/api
Claude Code refuses to read the settings file with an unhelpful error The file contains a # comment. JSON has no comments, so remove it
A fresh install stops on Select login method even with the right settings file The wizard reads only real environment variables. Set hasCompletedOnboarding to true in ~/.claude.json, or export ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN before the first launch
Usage gets billed although the setup looked free The model is openrouter/auto, the Auto Router, which can pick a paid model. Use openrouter/free
The settings file seems to be ignored The trust prompt was declined. Most env values apply only after you trust the folder, so run claude again and say yes

Watch it inside the full course

The whole course is also one long video on YouTube, all 8 lessons in order. Lesson 8 starts at 4:41:30.

Read the written version

The Substack article covers the same build step by step, with the prompts and files to copy. Read Lesson 8 on Substack.

More in this section

Continue the course

See all 8 lessons in the Claude Code Full Course: Build AI Systems Without Writing Code.

Dheeraj Sharma

AI Systems Builder
I teach founders, creators and tech teams to build production-grade AI systems, without an enterprise budget. 20 years of enterprise engineering, now in plain English.

Build your own system with me, live

The Claude Code Builder cohort on Maven is 6 weeks of building with me live. You leave with a working system of your own.

See the Claude Code Builder cohort