Run Claude Code on a local model with Ollama
Run Claude Code on a free local model with Ollama in under 25 minutes, so your code and prompts stay on your own computer with no API bills.

What you need
Ollama needs macOS 14 Sonoma or newer, and Intel Macs run models on the CPU only. On Windows, it needs Windows 10 22H2 or newer.
Step 1: Install Ollama
3 minOllama downloads and serves the model, and it speaks the same API that Claude Code expects.
- Go to ollama.com/download and install the app for your system.
- Linux: run the install command below instead.
- Open a new terminal window and run
ollama --version.
Linux: run thiscurl -fsSL https://ollama.com/install.sh | sh
You should see a version number of 0.15 or higher.
The version is older than 0.15?
Click the Ollama icon in the menu bar or taskbar and choose Restart to update. Or download the latest version again.
Step 2: Download a coding model
8 minClaude Code needs a model that can call tools, and Ollama's own Claude Code guide uses Qwen3.5.
- Run the command below. It pulls the 9B model, about 6.6 GB.
- With 32 GB of memory or more, you can pull the larger
qwen3.5:27binstead. It's about 17 GB. - Wait for the download to finish.
Run thisollama pull qwen3.5
You should see a progress bar that fills up and ends with
success.Your main drive is running out of space?
Set the
OLLAMA_MODELSvariable to a folder on another drive, restart Ollama, then pull the model again.Step 3: Raise the context window to 64K
2 minOllama gives models a 4K window on GPUs with under 24 GB of memory. Coding agents need at least 64K.
- Mac or Windows: open the Ollama app's settings and move the context length slider to 64K.
- Linux, or from a terminal: quit the Ollama app, then start the server with the command below.
Or run thisOLLAMA_CONTEXT_LENGTH=64000 ollama serve
You should see the slider at 64K, or the server running in that terminal with no error.
ollama servesays the address is already in use?The Ollama app is still running. Quit it from the menu bar or taskbar, then run the command again.
A bigger window uses more memory. If the model slows down a lot, stay at 64K rather than going higher.
Step 4: Install Claude Code
3 minClaude Code is the agent that reads and edits your files. Ollama only supplies the model behind it.
- Mac or Linux: run the command below.
- Windows: run
irm https://claude.ai/install.ps1 | iexin PowerShell. - Open a new terminal window and run
claude --version.
Mac or Linux: run thiscurl -fsSL https://claude.ai/install.sh | bash
You should see a version number followed by
(Claude Code).The terminal says it can't find
claude?Open a new terminal window so it picks up the new install folder, then run the check again.
Step 5: Launch Claude Code on the local model
3 minollama launchconnects Claude Code to Ollama for you, so there are no variables to type.- In the terminal, go to a project folder with
cd. - Run the command below.
- Type
/statusto check which model is in use.
Run thisollama launch claude --model qwen3.5
You should see Claude Code open in your project, with
qwen3.5as the model in/status.Claude Code warns that it doesn't recognize the model and assumes 200K tokens?
Give it the real window so it compacts in time. Quit, run
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000, then launch again.To connect by hand, set
ANTHROPIC_BASE_URL=http://localhost:11434,ANTHROPIC_AUTH_TOKEN=ollamaand an emptyANTHROPIC_API_KEY. Then runclaude --model qwen3.5.- In the terminal, go to a project folder with
Step 6: Give it a first task
5 minA small task shows that the model can read files, edit them and run commands on your machine.
- Paste the prompt below and press Enter.
- Approve each file edit or command when Claude Code asks.
- In a second terminal window, run
ollama psto see how the model is loaded.
Your promptRead this project and sum it up in 5 bullets. Then add a file called hello.html with a simple Hello world page.
You should see a short summary, a new
hello.htmlfile, andollama psshowing100% GPUwith a context of 64K or more.Replies come out very slowly?
Check the
PROCESSORcolumn inollama ps. A CPU share means the model didn't fit in GPU memory. Close other apps, or try the smallerqwen3.5:4b.Local models are smaller than cloud ones. Give them one clear change at a time rather than a whole feature.
You get
Claude Code running on a local Qwen3.5 model through Ollama, with your code and prompts kept on your own computer
Try next
Did this guide work for you?
Thanks. It helps us fix the steps.
Sources
0 of 6Next: Install Ollama


