Yes, you can run Claude Code for free in 2026 — no Anthropic API key, no subscription, no per-token bill. You keep the full Claude Code harness (file editing, tool calling, subagents, slash commands) and swap the model behind it for either a local open-weight model like Google's Gemma 4 running through Ollama, or a free cloud model routed through OpenRouter. The local path costs nothing and keeps your code on your machine; the cloud path works on any hardware, including laptops without a GPU. Since Ollama v0.14.0 added native Anthropic Messages API support in January 2026, the setup is two environment variables or a single ollama launch command — no proxy required.
Last verified: 2026-07-21 · Local path: Ollama + Gemma 4 (free, private) · Cloud path: OpenRouter free tier (free, any hardware) · Speed: ~90% faster with MTP on Apple Silicon · Volatile: model versions and free-tier availability change often.
What Is Claude Code and Why Does It Normally Cost Money?
Claude Code is Anthropic's terminal-based AI coding agent. It reads your codebase, edits files, runs shell commands, manages multi-step tasks, and supports subagents — all from the command line or VS Code extension. The harness (tool-calling, file management, slash commands, agent orchestration) is what makes it powerful; the model behind it is swappable.
Officially, Claude Code access requires either a Claude Pro subscription ($20/month), Claude Max ($100–$200/month), or pay-per-token API billing through Anthropic's Console. Heavy agentic usage can rack up significant API costs — a full day of coding with Claude Sonnet can consume tens of dollars in tokens. That cost pressure makes developers hesitant to use Claude Code for exploratory or experimental work, which is exactly where an AI coding agent is most valuable.
How Does Running Claude Code for Free Actually Work?
Claude Code communicates with its model backend using the Anthropic Messages API protocol. It reads the ANTHROPIC_BASE_URL environment variable to know where to send requests. By default, that points to https://api.anthropic.com. But any server that speaks the same protocol can serve as the backend.
Two free backends support this in 2026:
Ollama (local): Since v0.14.0 (January 2026), Ollama exposes a native Anthropic-compatible
/api/messagesendpoint. You run an open-weight model on your own hardware, and Claude Code talks to it as if it were Anthropic's API. Your code never leaves your machine. (Ollama Docs — Claude Code)OpenRouter (cloud): OpenRouter hosts free-tier models (tagged
:free) that are accessible through their API. Using a community router likeclaude-code-router(CCR), you redirect Claude Code's requests to OpenRouter's free models. This works on any machine — no GPU required. (OpenRouter Free Models)
In both cases, you keep the exact same Claude Code binary, terminal workflow, tool-calling interface, and slash commands. Only the model providing the intelligence changes.
What Is Gemma 4 and Why Is It the Best Free Model for Claude Code?
Gemma 4 is Google DeepMind's latest family of open-weight models, released starting March 31, 2026, with the 12B Unified variant arriving June 3, 2026. The models are Apache 2.0 licensed, support text and image input (audio on E2B, E4B, and 12B variants), and offer a context window of up to 256K tokens across five sizes: E2B, E4B, 12B, 26B A4B (Mixture-of-Experts), and 31B. (Google AI — Gemma Releases, Gemma 4 Model Card)
For Claude Code specifically, Gemma 4 is compelling for three reasons:
- Free and open-weight: Download it once, run it locally forever. No API calls, no rate limits, no metering.
- 256K context window: Claude Code needs at least 64K tokens of context to work effectively with real codebases. Gemma 4's 256K window is more than sufficient for most repositories.
- Multi-token prediction (MTP): Gemma 4 ships with a small draft model that proposes multiple tokens at once, which the main model verifies in a single pass. On Apple Silicon, this makes Gemma 4 generate tokens nearly 90% faster on the Aider polyglot coding benchmark — and the speedup is on by default in Ollama 0.31+. (Ollama Blog — Faster Gemma 4 on MLX with MTP, Google Blog — MTP for Gemma 4)
The 90% speedup matters most for coding agents because they call the model continuously — reading files, running tools, iterating through tasks. Code is especially predictable (closing brackets, repeated identifiers, boilerplate), so the draft model's proposals are accepted often, making MTP particularly effective for this workload.
How to Set Up Claude Code with Ollama (Local, Free, Private)
This is the recommended path if you have a machine with at least 8 GB RAM (16 GB recommended) and ideally a GPU (Apple Silicon, NVIDIA, or AMD). Your code stays entirely on your machine.
Step 1: Install Ollama
macOS / Windows: Download from ollama.com/download. It starts automatically as a background service.
Linux:
curl -fsSL https://ollama.com/install.sh | sh
Verify the installation:
ollama --version # Must be 0.14.0 or later
Ollama v0.14.0+ is required — older versions do not expose the Anthropic Messages API endpoint that Claude Code needs. (Ollama Docs)
Step 2: Pull a Model
# Gemma 4 — the recommended free model for coding
ollama pull gemma4
# Or for low-VRAM machines (8 GB or less)
ollama pull qwen2.5-coder:7b
Test that the model runs:
ollama run gemma4 "Hello, what model are you?"
Step 3: Connect Claude Code to Ollama
Method 1 — ollama launch (easiest, Ollama v0.14.5+):
ollama launch claude --model gemma4
This single command sets all environment variables, configures the context window, and opens Claude Code in your current directory. (Ollama Blog — ollama launch)
Method 2 — Manual environment variables:
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude
For permanent configuration, add these to ~/.claude/config.json:
{
"env": {
"ANTHROPIC_BASE_URL": "http://localhost:11434",
"ANTHROPIC_AUTH_TOKEN": "ollama",
"ANTHROPIC_API_KEY": ""
},
"model": "gemma4"
}
Step 4: Fix the Context Window (Critical)
This is the step most guides skip, and it is the most common reason Claude Code fails mid-task. Ollama defaults to a 2K–4K token context window. Claude Code needs at least 64K to work with real codebases.
If you used ollama launch, this is handled automatically. If you set environment variables manually, create a Modelfile:
FROM gemma4
PARAMETER num_ctx 65536
Then build and run:
ollama create gemma4-64k -f Modelfile
ollama launch claude --model gemma4-64k
Step 5: Verify It Works
Navigate to any project directory and start Claude Code:
cd your-project
ollama launch claude --model gemma4
Type a simple prompt like "explain this codebase." If everything is configured correctly, the model will respond, read your files, and answer questions about your project — all locally, all free.
How to Run Claude Code for Free Without a GPU (OpenRouter Cloud Path)
If you don't have a Mac with Apple Silicon or a machine with a dedicated GPU, local inference may be too slow to be practical. OpenRouter provides free cloud access to the same open-weight models, including Gemma 4.
Step 1: Install Claude Code and the Router
# Install Claude Code
npm install -g @anthropic-ai/claude-code
# Install Claude Code Router (CCR)
npm install -g @musistudio/claude-code-router
Step 2: Get a Free OpenRouter API Key
- Go to openrouter.ai and create a free account.
- Navigate to Keys and generate an API key.
- Set it as an environment variable:
export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
Step 3: Configure the Router
Create ~/.claude-code-router/config.json:
{
"Providers": [{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "$OPENROUTER_API_KEY",
"models": [
"google/gemma-4-26b-a4b-it:free",
"google/gemma-4-31b-it:free"
],
"transformer": { "use": ["openrouter"] }
}],
"Router": {
"default": "openrouter,google/gemma-4-26b-a4b-it:free"
},
"LOG_LEVEL": "info"
}
As of July 2026, OpenRouter's free catalog includes google/gemma-4-26b-a4b-it:free (262K context) and google/gemma-4-31b-it:free (262K context), among others. The catalog changes frequently — always check the live free-model collection before relying on a specific endpoint. (OpenRouter Free Models)
Step 4: Start Coding
ccr start
ccr code
Inside Claude Code, you can switch models with:
/model openrouter,google/gemma-4-26b-a4b-it:free
Local vs Cloud: Which Free Path Should You Choose?
| Feature | Ollama (Local) | OpenRouter (Cloud) |
|---|---|---|
| Cost | Free | Free |
| Privacy | Code never leaves your machine | Code sent to cloud provider |
| Hardware | 8 GB+ RAM, GPU recommended | Any machine, no GPU needed |
| Setup | 3 commands via ollama launch |
CCR + API key + config file |
| Speed | Fast with GPU + MTP (~90% faster) | Depends on provider load |
| Offline | Yes, fully offline | No, requires internet |
| Model variety | Any Ollama-compatible model | 20+ free models available |
| Rate limits | None (your hardware) | Provider-imposed limits |
Choose local (Ollama) if you have a capable machine and care about privacy. Choose cloud (OpenRouter) if you're on a lightweight laptop, a Chromebook, or any device without a GPU. Both paths give you the full Claude Code experience at zero cost.
What Can You Actually Build with Free Claude Code?
Free local models like Gemma 4 are best suited for everyday coding tasks — the majority of what most developers and small business builders actually do:
- Landing pages and marketing sites: Generate HTML/CSS, iterate on design, deploy.
- Simple web apps: To-do lists, dashboards, CRUD applications in any framework.
- Games and prototypes: Browser-based games, interactive demos, proof-of-concept builds.
- Scripts and automation: Data processing scripts, build tools, CI/CD helpers.
- Code review and refactoring: Read a codebase, suggest improvements, explain unfamiliar code.
- Blog posts and content: Generate markdown, structure documents, draft copy.
For complex, multi-file refactoring or deep architectural decisions, a stronger model (Claude Sonnet/Opus, Qwen3-Coder 32B) will perform better. But for the daily grind — building, prototyping, iterating — a free local model handles the majority of tasks well. The key insight is that you can switch back and forth: use the free local model for 80% of your work, and escalate to a paid model only when you hit a wall.
What This Means for You
If you've been holding back from using Claude Code because of API costs, that barrier is gone. You can install Ollama, pull Gemma 4, and be coding with a free AI agent in under 10 minutes — with your code staying private on your own machine. If you don't have the hardware for local inference, OpenRouter's free tier gives you the same workflow on any laptop. The harness is free, the models are free, and the setup is three commands. The main trade-off is that free models are less capable than Claude Sonnet or Opus on complex tasks — but for most everyday coding work, they're more than sufficient. Start with the local path if you can; fall back to the cloud path if your hardware can't handle it. Either way, you get an autonomous coding agent running for free, day and night, without a meter running.
If you're exploring other autonomous AI coding setups, check out our guide to building a sovereign AI agent operating system or our deep dive on OpenAI Codex's remote agent update. For a broader look at how autonomous AI workflows are running entire businesses, see our 5 autonomous AI workflows guide. And if you're weighing different AI coding approaches, our fleet engineering guide covers how to orchestrate multiple coding agents effectively.
FAQ
Q: Is this really the same Claude Code, or a watered-down version?
A: It is the exact same Claude Code binary with the same harness — file editing, tool calling, subagents, slash commands, and everything else. You are simply pointing it at a different model backend via the ANTHROPIC_BASE_URL environment variable. The tool itself is unchanged; only the intelligence behind it differs.
Q: Can a free local model actually write real, working code?
A: Yes. Gemma 4 and similar open-weight models can generate working code for landing pages, web apps, scripts, and games. They are best for everyday coding tasks. For complex multi-file refactoring or deep architectural decisions, a larger model will perform better — but for the majority of daily work, free models are sufficient.
Q: Do I need a Mac or a GPU to run Claude Code locally?
A: No. If you have a Mac with Apple Silicon, local inference is fast and straightforward. If you don't, you can use OpenRouter's free cloud tier instead, which runs the same models on cloud hardware and works on any machine — including Chromebooks and lightweight laptops. Both paths are free.
Q: How much faster is Gemma 4 with multi-token prediction?
A: On Apple Silicon, Ollama 0.31+ with MTP enabled makes Gemma 4 generate tokens nearly 90% faster on the Aider polyglot coding benchmark. The speedup comes from a small draft model that proposes multiple tokens, which the main model verifies in a single pass. MTP is on by default and does not change the model's output quality. (Ollama Blog)
Q: Is my code safe when using a local model?
A: When using Ollama locally, your code never leaves your machine. All inference happens on your hardware. This is a significant privacy advantage over cloud-based AI coding tools. When using OpenRouter's cloud path, your code is sent to the cloud provider's servers — so if privacy is a hard requirement, use the local path.
Q: Can I switch between free and paid models?
A: Yes. You can set up Ollama for free daily work and switch to Anthropic's API for complex tasks by changing the ANTHROPIC_BASE_URL environment variable. This hybrid approach lets you keep costs down for routine work while having a frontier model available when needed.

Discussion
0 comments