Before You Start: The Core Concept

Claude Code is a CLI tool. By default it sends every request to Anthropic's servers and bills you per token. But it respects two environment variables that redirect all traffic to any Anthropic-compatible endpoint:

ANTHROPIC_BASE_URL   – where to send requests
ANTHROPIC_AUTH_TOKEN – the token to include (any non-empty string works for local/proxy endpoints)

Set those two variables before launching claude, and it will talk to your chosen backend instead of Anthropic. The interface, tooling, and CLAUDE.md system are identical regardless of which model is behind the curtain.

⚠️ Important caveat: You will not be talking to Claude. You'll be using Claude Code's interface powered by open-weight models. Quality varies, single-file tasks work well; complex multi-file reasoning shows more gaps. More on this in each section.

Table of Contents

  1. Installing Claude Code
  2. Option 1 — Ollama (Local)
  3. Option 2 — Ollama Cloud
  4. Option 3 — OpenRouter
  5. Option 4 — NVIDIA NIM
  6. Comparison at a Glance
  7. Choosing the Right Option
  8. Honest Performance Expectations
  9. Troubleshooting
  10. Security Notes

Installing Claude Code

Install Claude Code first, regardless of which backend you choose.

macOS / Linux (recommended — native installer, no Node.js needed):

curl -fsSL https://claude.ai/install.sh | bash

macOS (Homebrew):

brew install claude-code
# Note: does not auto-update; run `brew upgrade claude-code` manually

Linux (apt/dnf/apk):

# Debian/Ubuntu
sudo apt install claude-code

# Fedora/RHEL
sudo dnf install claude-code

# Alpine
sudo apk add claude-code

Windows (Powershell / CMD):

irm https://claude.ai/install.ps1 | iex
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Windows (WinGet — native, no WSL required):

winget install Anthropic.ClaudeCode

Verify the installation:

claude --version

Option 1 — Ollama (Local)

What It Is

Ollama is a runtime that downloads and serves open-weight LLMs on your own hardware. Since v0.14 (January 2026), Ollama natively exposes an Anthropic Messages API at http://localhost:11434, no proxy or translation layer needed.

Cost: Free forever, no rate limits, no account required.
Privacy: Complete, nothing leaves your machine.

Pros

  • Zero cost, unlimited usage
  • Fully offline after model download
  • Your code never leaves your machine
  • Works on macOS, Linux, and Windows
  • No API keys, no accounts, no quotas

Cons

  • Requires capable hardware (16 GB RAM minimum for useful models; 32 GB+ recommended)
  • Slower than cloud inference, especially on CPU-only machines
  • Without a GPU, response times can be impractical (minutes per response)
  • Open-weight models are weaker than Claude on multi-file reasoning and complex tasks
  • Model files are large (4–70 GB depending on size)
  • You are responsible for keeping models updated

Hardware Requirements

RAM Recommended Model Notes
8 GB qwen2.5-coder:3b, gemma3:4b Slow on CPU; barely usable
16 GB qwen2.5-coder:7b, glm-4.7-flash Reasonable speed with GPU
32 GB qwen3.5:27b, devstral:22b Good balance of quality and speed
64 GB+ qwen3.5:72b, llama3.3:70b Near-frontier quality; Apple M2 Ultra+

Claude Code requires at least 32K tokens of context window, but 64K or more is strongly recommended. Check each model's supported context length before committing.

Installation

macOS / Linux:

curl -fsSL https://ollama.com/install.sh | sh

Windows:

Download the installer from ollama.com and run it. Ollama will be available system-wide after installation.

Verify Ollama is running:

ollama --version

Pulling a Model

# Good balance of quality and speed for coding tasks
ollama pull qwen2.5-coder:7b

# Stronger reasoning; needs 32 GB RAM
ollama pull qwen3.5:27b

# Mixture-of-experts; runs on 16 GB, 128K context, strong tool calling
ollama pull glm-4.7-flash

Connecting Claude Code to Ollama

macOS / Linux:

export ANTHROPIC_AUTH_TOKEN="ollama"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL="http://localhost:11434"

claude --model qwen2.5-coder:7b

Windows (PowerShell):

$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"

claude --model qwen2.5-coder:7b

Persistent Alias (macOS / Linux)

Add to your ~/.zshrc or ~/.bashrc to avoid repeating the exports:

alias claude-local='ANTHROPIC_AUTH_TOKEN="ollama" ANTHROPIC_API_KEY="" ANTHROPIC_BASE_URL="http://localhost:11434" claude --model qwen2.5-coder:7b'

Then just run claude-local from any project folder.

Context Window Warning

Ollama's default context window is often small (2K–4K tokens). Claude Code sends large prompts that will overflow it. Set a larger context when launching Ollama or use ollama create with a custom Modelfile:

# Pull and run with extended context via env variable
OLLAMA_NUM_CTX=32768 ollama run qwen2.5-coder:7b

Or use ollama launch claude (Ollama's official Claude Code integration):

ollama launch claude --model qwen3.5:27b

This command handles context sizing automatically.

Best Models for Claude Code (Local)

Model Size Context Tool Calling Notes
glm-4.7-flash 30B (3B active) 128K ✅ Strong Best tool-calling local model
qwen3.5:27b 27B 128K ✅ Good Strong reasoning, needs 32 GB
qwen2.5-coder:7b 7B 32K ✅ OK Fastest; usable on 16 GB
devstral:22b 22B 128K ✅ Good Mistral's coding specialist

Option 2 — Ollama Cloud

What It Is

Ollama Cloud is Ollama's managed inference service, launched in late 2025. It serves the same open-weight model library as local Ollama but on Ollama's GPU infrastructure. You use the same Ollama client and environment variables, only the endpoint changes.

Cost: Free tier available; paid tiers at $20/month (Pro) and ~$200/month (Max).

Free Tier Limits

The free tier has session limits (reset every 5 hours) and weekly limits (reset every 7 days). Exact quota numbers are not published as fixed token or request counts, Ollama measures actual GPU utilization. Light to moderate use fits within the free tier. Check your live usage at ollama.com/settings.

Pros

  • No local hardware required
  • Frontier-class open models (Qwen 3.5, GLM-5, Kimi K2.5) at no cost
  • Same Ollama interface as local — zero code changes
  • No API key required for free tier (uses Ollama account session)
  • Works from any device that can run Ollama

Cons

  • Free tier limits are opaque — no published RPM or daily token count
  • Code leaves your machine (sent to Ollama's US-hosted servers)
  • Limits have been revised multiple times since launch; check the live page
  • Heavy use requires a paid plan

Setup

macOS / Linux:

export ANTHROPIC_AUTH_TOKEN="ollama"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL="http://localhost:11434"

# Cloud models use the :cloud suffix
claude --model qwen3.5:cloud

Windows (PowerShell):

$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"

claude --model glm-5:cloud

Ollama routes model:cloud tags to its hosted infrastructure automatically. Your local Ollama installation acts as the gateway.

Available Cloud Models (free tier)

Model Context Notes
qwen3.5:cloud 128K Strong all-round coder
glm-5:cloud 128K Excellent tool use
kimi-k2.5:cloud 256K Best context window

Or: Use ollama launch claude

Ollama's official first-class integration handles all the environment configuration:

# Pulls the model and launches Claude Code automatically
ollama launch claude --model qwen3.5:cloud

Option 3 — OpenRouter

What It Is

OpenRouter is an API gateway that provides access to 400+ models from a single endpoint. It speaks both OpenAI and Anthropic API formats, meaning Claude Code can connect to it directly with no proxy. Free models are marked with the :free suffix in their model ID.

Cost: Free tier available and no credit card required.

Free Tier Limits

Condition Daily Limit RPM
No credits purchased 50 requests/day 20 req/min
$10+ credits purchased 1,000 requests/day 20 req/min

The :free models are subsidized by OpenRouter and rotate over time. Approximately 29–32 free models are available at any given moment. Adding $10 in credits (which you only spend on paid models) unlocks the 1,000/day limit on free models as well.

Pros

  • No proxy needed — OpenRouter speaks Anthropic format natively
  • Large catalog of free models including strong coders (Qwen3 Coder, DeepSeek R1, Devstral)
  • No credit card required to start
  • Easy to upgrade incrementally (add $10 for better free limits)
  • Rotate between multiple free models to extend daily quota

Cons

  • 50 req/day without credits is very restrictive for active coding sessions
  • Free models can disappear or become paid without notice
  • 20 RPM is tight for complex agentic tasks where Claude Code calls the model frequently
  • Code is sent to OpenRouter's servers and then routed to the model provider

Getting an API Key

  1. Go to openrouter.ai and create an account (no credit card required)
  2. Navigate to API Keys and create a new key
  3. Copy it — you'll use it as ANTHROPIC_API_KEY

Setup

macOS / Linux:

export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1"
export ANTHROPIC_API_KEY="sk-or-your-key-here"

claude --model meta-llama/llama-3.3-70b-instruct:free

Windows (PowerShell):

$env:ANTHROPIC_BASE_URL = "https://openrouter.ai/api/v1"
$env:ANTHROPIC_API_KEY = "sk-or-your-key-here"

claude --model meta-llama/llama-3.3-70b-instruct:free

Persistent Alias (macOS / Linux)

alias claude-or='ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1" ANTHROPIC_API_KEY="sk-or-your-key-here" claude'

Then launch with a specific model:

claude-or --model qwen/qwen3-coder-480b:free

Best Free Models for Coding (May 2026)

Model ID Size Context Notes
qwen/qwen3-coder-480b:free 480B 262K Top coding benchmark on free tier
deepseek/deepseek-r1:free 671B 128K Best for reasoning-heavy debugging
mistralai/devstral-2-123b:free 123B 128K Coding specialist, strong agent mode
meta-llama/llama-3.3-70b-instruct:free 70B 128K Reliable general-purpose option
nvidia/nemotron-3-super-120b:free 120B 262K Hybrid MoE, fast and capable
Browse the full free catalog at: openrouter.ai/models?max_price=0

Tip: Rotate Models to Extend Daily Quota

Rate limits apply per API key, not per model. If you hit the daily cap on one model, switch to another free model. With ~30 free models available, this significantly extends your daily capacity.

# Morning session
claude --model qwen/qwen3-coder-480b:free

# If rate-limited, switch
claude --model deepseek/deepseek-r1:free

Option 4 — NVIDIA NIM

What It Is

NVIDIA NIM (Inference Microservices) is NVIDIA's hosted inference platform at build.nvidia.com. It provides free access to 50+ open-weight models running on NVIDIA DGX Cloud. Every model exposes an OpenAI-compatible endpoint — Claude Code connects via a lightweight proxy (free-claude-code) that translates formats.

Cost: Free indefinitely, rate-limited at 40 requests per minute. No per-token billing.

Free Tier Limits

  • 40 RPM (requests per minute) — hard limit, cannot be increased on the free tier
  • No daily cap — you can run all day as long as you stay under 40 RPM
  • Rate limit is per account; creating additional accounts does not help
  • Applies across all models in the catalog

Pros

  • No daily request cap — 40 RPM continuously
  • Access to 50+ models including strong coders (Kimi K2, Devstral, GLM-4.7)
  • No credit card required
  • NVIDIA's TensorRT-LLM backend — fast inference, typically 2× throughput vs vanilla deployments
  • No code of conduct restrictions beyond NVIDIA's standard ToS

Cons

  • Requires running the free-claude-code proxy (Python 3.14 + uv)
  • 40 RPM can feel tight during heavy agentic sessions where Claude Code makes rapid tool calls
  • Rate limit increases are not grantable on the free tier
  • Code is sent to NVIDIA's DGX Cloud servers

Prerequisites

Install uv (Python version manager):

macOS / Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows (PowerShell):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Getting a NIM API Key

  1. Go to build.nvidia.com and sign up (free, no credit card)
  2. Navigate to Settings → API Keys and create a key
  3. The key starts with nvapi- — copy it immediately (shown only once)

Setting Up the Proxy

macOS / Linux / Windows (same steps):

git clone https://github.com/Alishahryar1/free-claude-code.git
cd free-claude-code
cp .env.example .env

Edit .env:

# NVIDIA NIM credentials
NVIDIA_NIM_API_KEY="nvapi-your-full-key-here"

# Model mapping — Claude tiers → NIM models
MODEL_OPUS="nvidia_nim/moonshotai/kimi-k2-thinking"
MODEL_SONNET="nvidia_nim/mistralai/devstral-2-123b-instruct-2512"
MODEL_HAIKU="nvidia_nim/moonshotai/kimi-k2.5"
MODEL="nvidia_nim/moonshotai/kimi-k2.5"   # fallback

# Thinking mode — only enable for kimi-k2-thinking
ENABLE_OPUS_THINKING=true
ENABLE_SONNET_THINKING=false
ENABLE_HAIKU_THINKING=false

# Auth token (any value; Claude Code sends this back to the proxy)
ANTHROPIC_AUTH_TOKEN="freecc"
⚠️ ENABLE_OPUS_THINKING=true only works with kimi-k2-thinking. Setting it for other models causes API errors.

Start the proxy:

uv run uvicorn server:app --host 0.0.0.0 --port 8082

Connecting Claude Code

Open a second terminal and run:

macOS / Linux:

export ANTHROPIC_BASE_URL="http://localhost:8082"
export ANTHROPIC_AUTH_TOKEN="freecc"
claude

Windows (PowerShell):

$env:ANTHROPIC_BASE_URL = "http://localhost:8082"
$env:ANTHROPIC_AUTH_TOKEN = "freecc"
claude

Persistent Alias (macOS / Linux)

alias claude-nim='ANTHROPIC_BASE_URL="http://localhost:8082" ANTHROPIC_AUTH_TOKEN="freecc" claude'

Note: the proxy must be running in a separate terminal before you use the alias.

Best NIM Models for Claude Code

NIM Model ID Notes
moonshotai/kimi-k2-thinking Best reasoning; enables thinking mode
mistralai/devstral-2-123b-instruct-2512 Top coding agent, 128K context
moonshotai/kimi-k2.5 256K context, fast, good for Haiku slot
z-ai/glm4.7 Strong tool calling, efficient MoE

Browse the full catalog at: build.nvidia.com/explore/discover


Comparison at a Glance

Ollama Local Ollama Cloud OpenRouter NVIDIA NIM
Cost Free Free (limits) Free (limits) Free (rate-limited)
Rate limit None Session/weekly quota 20 RPM / 50 req/day* 40 RPM
Daily cap None Opaque quota 50 req/day* None
Privacy 🔒 Full ❌ Code sent to Ollama ❌ Code sent to OpenRouter ❌ Code sent to NVIDIA
Setup complexity Medium Low Lowest Medium
Internet required ❌ No ✅ Yes ✅ Yes ✅ Yes
Hardware requirements High None None None
Proxy needed No No No Yes
Model quality Varies by hardware Good Good–Excellent Good–Excellent

*50 req/day without credits; 1,000 req/day with $10+ credits on account


Choosing the Right Option

Choose Ollama Local if:

  • Privacy is a requirement (regulated environment, proprietary code)
  • You have a Mac with 32 GB+ unified memory, or an NVIDIA GPU with 16 GB+ VRAM
  • You want truly unlimited usage with no external dependencies
  • You work in air-gapped environments

Choose Ollama Cloud if:

  • You want zero setup and no hardware requirements
  • Light-to-moderate daily usage is sufficient
  • You already use Ollama locally and want a cloud fallback

Choose OpenRouter if:

  • You want the simplest setup (no proxy, no local server)
  • You need access to the widest variety of free models
  • You don't mind the 50 req/day limit for casual use, or are willing to spend $10 for 1,000/day
  • You want to rotate between multiple models

Choose NVIDIA NIM if:

  • You want sustained usage throughout the day without a daily cap
  • 40 RPM is sufficient for your workflow
  • You want access to strong reasoning models like Kimi K2 Thinking
  • You're comfortable running a lightweight proxy

Honest Performance Expectations

All four options use open-weight models, not Claude. Here's what to realistically expect:

What works well:

  • Single-file code generation and editing
  • Explaining and documenting code
  • Writing tests for well-isolated functions
  • Simple refactoring tasks
  • Git operations and commit message generation

Where the gap with Claude shows:

  • Multi-file reasoning (understanding how changes in one file affect others)
  • Detecting subtle bugs that require deep context
  • Complex architectural decisions across large codebases
  • Long agentic sessions requiring many consistent decisions

Edit accuracy is roughly 70–80% for local open-weight models vs ~98% for Claude Sonnet. Expect to review and occasionally correct edits manually, particularly for multi-file operations.


Troubleshooting

Claude Code shows the login screen instead of connecting: Ensure the environment variables are set in the same terminal session where you run claude. Variables exported in one terminal do not carry over to another.

ANTHROPIC_BASE_URL not picked up (Windows): On Windows, use $env: prefix in PowerShell, not export. Alternatively, set them permanently through System Properties → Environment Variables.

Ollama: slow responses or timeouts: Your model is likely too large for available RAM and is being swapped to disk. Try a smaller quantized model (e.g., qwen2.5-coder:7b instead of 27b).

OpenRouter: 429 errors: You've hit the daily request limit. Wait for the daily reset, switch to a different free model, or add $10 in credits to raise the limit to 1,000/day.

NVIDIA NIM proxy: 429 from NIM API: You've hit the 40 RPM ceiling. This is a hard limit on the free tier with no workaround. Slow down request frequency or use a different provider temporarily.

Claude Code context window errors: For Ollama local models, increase the context window: set OLLAMA_NUM_CTX=65536 before starting Ollama, or use ollama launch claude which handles this automatically.


Security Notes

  • Ollama local: Ollama binds to 127.0.0.1:11434 by default. Do not expose this port to your network unless you understand the implications.
  • All cloud options: Your code and prompts are sent to external servers. Do not use these setups with confidential source code, credentials, or proprietary IP unless you have reviewed the provider's data handling policies.
  • free-claude-code proxy: The ANTHROPIC_AUTH_TOKEN in .env is a local secret shared between the proxy and Claude Code. Set it to any non-empty value, it is not an Anthropic credential.
  • API keys: Store NIM and OpenRouter keys in environment variables or .env files. Never commit them to version control.

Last updated: May 2026. Rate limits and free tier terms change frequently, so verify current limits at each provider's official documentation before relying on them for a project.