How to Use Claude Code with Free Models
Steps checked against Anthropic, Ollama and OpenRouter documentation on 2 November 2026; not run for this guide.
In short: Claude Code can send its requests to another model through a setting called the base URL. With Ollama the model runs on your own computer for free; with OpenRouter you can pick a free hosted model. Neither route uses Claude, and Anthropic does not support either one: its gateway documentation says it does not support routing Claude Code to non-Claude models. The steps below come from the vendors' documentation and were not run for this guide, so features may fail.
What is free and what is not
| Cost | What it runs | Account needed | |
|---|---|---|---|
| Claude Code app | Free to install | The program itself, not a model | None for the routes below |
| Claude's free plan | Does not include Claude Code | Nothing here | Anthropic's setup page lists Pro, Max, Ultra, Team, Enterprise or Console |
| Ollama, local model | Free; your own hardware and electricity | An open model on your computer | None for local models |
| Ollama, cloud model | Depends on your Ollama plan | A larger model on Ollama's servers | Ollama account and key |
OpenRouter, :free model | Free, 50 requests a day on a free account | A free model on OpenRouter | OpenRouter account and key |
Step 1: Open a terminal
The terminal is the window where you type commands. Type or paste one line, then press Enter.
- Windows: press the Start key, type PowerShell, and press Enter. Paste with a right-click.
- Mac: press Command + Space, type Terminal, and press Return.
- Linux: press Ctrl + Alt + T on Ubuntu, or open Terminal from your apps menu.
Step 2: Install Claude Code
Windows (PowerShell):
irm https://claude.ai/install.ps1 | iex
Mac and Linux:
curl -fsSL https://claude.ai/install.sh | bash
The command shows no progress while it downloads. When it finishes, open a new terminal window and run:
claude --version
A version number means it worked. It needs macOS 13, Windows 10 1809, or Ubuntu 20.04 or newer, and 4 GB of RAM. If you see "claude is not recognized", follow Anthropic's PATH fix.
Option A: Free local models with Ollama
Step 1: Install Ollama. Follow how to install Ollama for your system, then come back here.
Step 2: Set the context length. Ollama's Claude Code page says local models should have a context window of 64k or higher. Ollama's default is 4k on a graphics card with under 24 GB of memory. Open the Ollama app's settings and move the context length slider to 64k. If your version has no slider, on Mac or Linux close the Ollama app and run:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Leave that window open and open a new one for the next steps. A larger context uses more memory.
Step 3: Download a model. Claude Code needs a model that supports tools. This one appears in Ollama's Claude Code examples, and this size is a 6.6 to 7.6 GB download:
ollama pull qwen3.5:9b
Which models fit your memory is listed in how to run an LLM locally.
Step 4: Open your project folder. Claude Code works on the folder you start it in. Replace the path with your own:
cd Documents/my-project
Step 5: Start Claude Code through Ollama.
ollama launch claude --model qwen3.5:9b
Step 6: Check the context. In a second terminal window, run:
ollama ps
The CONTEXT column shows the length in use, and the PROCESSOR column shows whether the model runs on your graphics card or partly on the processor.
Option B: Set up Ollama by hand
ollama launch sets the values below for you. To set them yourself, run them in the same window you
start Claude Code from. They last until you close that window.
Windows (PowerShell):
$env:ANTHROPIC_AUTH_TOKEN="ollama"
$env:ANTHROPIC_API_KEY=""
$env:ANTHROPIC_BASE_URL="http://localhost:11434"
claude --model qwen3.5:9b
Mac and Linux:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5:9b
Option C: Free hosted models with OpenRouter
OpenRouter's Claude Code page covers the connection but not free models, and says Claude Code is guaranteed to work only with Anthropic as the provider. A free model may therefore return errors or lack features.
Step 1: Get a free key. Follow how to get an OpenRouter API key for free.
Step 2: Set the connection. Replace your-key-here with your key.
Windows (PowerShell):
$env:OPENROUTER_API_KEY="your-key-here"
$env:ANTHROPIC_BASE_URL="https://openrouter.ai/api"
$env:ANTHROPIC_AUTH_TOKEN=$env:OPENROUTER_API_KEY
$env:ANTHROPIC_API_KEY=""
Mac and Linux:
export OPENROUTER_API_KEY="your-key-here"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
Step 3: Start Claude Code with a free model. openrouter/free lets OpenRouter choose among its free
models. To name one, use its ID ending in :free.
claude --model openrouter/free
Step 4: Log out of any Anthropic account. If you signed in to Claude before, type /logout inside
Claude Code, then start it again as in Step 3.
Step 5: Check the connection. Type /status inside Claude Code. It should list ANTHROPIC_AUTH_TOKEN
as the auth token and https://openrouter.ai/api as the base URL. The
OpenRouter activity page also lists each request.
What stops working
- Claude itself. These routes run other models, so answers differ from Claude's.
- Hosted web search. Ollama's page says hosted WebSearch and some advanced tool controls are not fully supported on its cloud connection.
- Anthropic's support. Anthropic does not maintain or audit third-party gateways.
- Your Claude subscription. While a gateway credential is active, requests do not use your subscription or its limits. Clear the variables or close the window to go back.
Related
- How to get free AI API access for coding: models made for coding that are free to call.
- How to add free API keys to OpenCode: the same job in an open-source coding app.
- How to use Kilo Code's free models.
- How to run an LLM locally: models, memory and measured speeds.
Frequently asked questions
Can I use Claude Code for free?+
The app is free to install, but Claude's free plan does not include Claude Code. Anthropic lists Pro, Max, Ultra, Team, Enterprise or Console accounts. Ollama and OpenRouter document connecting Claude Code to other models, which runs those models instead of Claude.
Does Anthropic support Claude Code with other models?+
No. Anthropic's gateway documentation says it does not support routing Claude Code to non-Claude models through any gateway, and that it does not endorse, maintain or audit third-party gateways.
How do I use Claude Code with Ollama?+
Install Claude Code and Ollama, set a context length of 64k or higher, download a model, then run ollama launch claude. Ollama's default context on a graphics card under 24 GB is 4k.
Do OpenRouter free models work with Claude Code?+
OpenRouter documents the connection but not free models, and says Claude Code is guaranteed to work only with Anthropic as the provider. A free OpenRouter account has 50 requests a day.