Anthropic’s command-line tool earns its keep. The $100 or $200 monthly bill for the “Max” plan is a separate conversation, especially if you are billing your own hours against it. After fourteen years of development work I have read enough “API usage” line items to know when the math has stopped working. So a lot of us went looking for a way to run Claude Code for free on hardware we already own.
Ollama’s v0.14.0 release added compatibility with the Anthropic Messages API. That is the whole trick. Claude Code believes it is talking to Anthropic’s servers, and the tokens are actually coming out of a Llama 3 or Qwen model sitting on your own machine.
Why run Claude Code for free locally
Privacy and cost are the obvious reasons. The one I care about more is context control. Running the model locally through Ollama removes the proprietary rate limit sitting between you and your own work. It also keeps you clear of one flavor of technical debt in AI development, the kind you accumulate by building against cloud model behavior that shifts under you without notice.
Getting the environment ready
Start with the latest Ollama build. On Windows I do this from PowerShell. Then pull a model that can actually write code: qwen3-coder and codellama are the two I reach for, and the Qwen3 series has been ahead of the pack lately on logic-heavy work.
# Pull the model
ollama pull qwen3-coder:7b
# Verify version (needs to be 0.14.0 or higher)
ollama --version
Pointing Claude Code at Ollama
The redirect happens through environment variables. Set these three in your terminal session and the Claude Code CLI stops calling Anthropic’s API and starts calling your local Ollama endpoint instead.
# Windows PowerShell
$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = "ollama"
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"
# MacOS/Linux
export ANTHROPIC_AUTH_TOKEN="ollama"
export ANTHROPIC_API_KEY="ollama"
export ANTHROPIC_BASE_URL="http://localhost:11434"
Run claude now and it hits your local Ollama instance. Pass --model to name the model you pulled a minute ago. Local models drift and hallucinate as readily as hosted ones, so my guide on AI coding agent context applies here too.
claude --model qwen3-coder:7b --allow-dangerously-skip-permissions
The Git repository wall I hit first
My first attempt was in a fresh, empty project folder, and it stopped cold. Claude Code is agentic, which in practice means it wants to track its own changes. Outside a Git repository it tends to error out with a complaint about having “no version control context.” That is a safeguard, and a reasonable one, since the alternative is an agent rewriting your disk with no undo. Run git init first, even for a throwaway “Hello World” script.
If wiring this up is eating hours you would rather bill elsewhere, I can take it on. I have been building WordPress and AI integrations since the early days of both, and I can put together a workflow that survives the next API change.
Where a local setup is good enough
Running Claude Code for free against Ollama does not have to be all or nothing. Local models still trail Claude 3.5 Opus on hard reasoning, and the gap is real. But most of a working day goes to refactoring, CSS tweaks and boilerplate, call it 80% of it, and a 7B coder model on your own machine covers that comfortably. Save the paid tokens for the problems that need them.