← All guides
🦙

Run Claude Code with free local AI (Ollama)

AI_Kwat · Episode 2 · 10 min read

Ollama (MIT licence, 180k+ GitHub stars) runs AI models on your own computer. It also exposes an Anthropic-compatible API, so Claude Code can use a local model instead of Anthropic’s servers. Normally Claude Code needs a paid Claude plan; with this setup it talks to your local model instead.

1

Install Ollama

Open a terminal and run the command for your system. You can also download the installer from ollama.com.

Windows (PowerShell)
irm https://ollama.com/install.ps1 | iex
macOS / Linux
curl -fsSL https://ollama.com/install.sh | sh
2

Download a model and test it

This downloads Google’s Gemma 4 and opens a chat in your terminal. Type a message to check it works, then /bye to exit. Smaller models run on a normal laptop; bigger ones need more memory.

ollama run gemma4
3

Install Claude Code

Skip this if you already have it. Then check it works with claude --version.

Windows (PowerShell)
irm https://claude.ai/install.ps1 | iex
macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash
4

Connect Claude Code to Ollama

One command. Ollama starts Claude Code and points it at your model through its Anthropic-compatible API.

ollama launch claude

Prefer doing it by hand? Set these, then start Claude Code with your model (example from Ollama’s docs):

5

Manual setup (optional)

macOS / Linux shell. On Windows PowerShell use $env:ANTHROPIC_AUTH_TOKEN="ollama" and so on.

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5
6

Give the model enough context

For coding tools, Ollama recommends a context window of at least 64,000 tokens so the model can keep your project in mind. In the Ollama app, use the context length slider in Settings, or start the server like this. Bigger context uses more memory; check with ollama ps.

OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Be realistic: a local model is not as capable as Claude’s top models. It’s great for quick edits, scripts and learning, for zero dollars. For large, complex projects you’ll still want the real thing.

📄 Get the PDF guide

Enter your email and download the printable version. You’ll also get new guides when they come out. Unsubscribe anytime.

We only use your email for AI_Kwat guides. No spam.

Official sources