Skip to content

How to Run Claude Code on a Local Model with Ollama

By Bikram Bhujel

Claude Code is Anthropic's coding agent for the terminal. It reads your project, edits files and runs commands. Normally it talks to Anthropic's models over the internet. Ollama, the tool many of us already use to run models at home, now has a one-line way to point Claude Code at a model running on your own machine instead: ollama launch claude.

I like this for two reasons. You can try an agent on private code without it leaving the box, and on a bad internet day the agent still works. But it's easy to set up wrongly and then decide "local models are useless", when the real problem was one setting. This post covers the setup, the model choice and that setting.

Terminal running ollama launch claude to start Claude Code with a local Qwen model through Ollama

Quick answer

Install Ollama and Claude Code, then run ollama launch claude --model qwen3.6. Ollama exposes an Anthropic-compatible API on localhost:11434, and the launch command points Claude Code at it. The catch is context length: Ollama defaults to only 4k tokens on GPUs with under 24 GiB of VRAM, and Ollama's own docs say coding agents need 64k or more. Set it with the slider in the Ollama app or OLLAMA_CONTEXT_LENGTH=64000 ollama serve, then check with ollama ps.

How the pieces fit together

Ollama runs the model and serves an API on port 11434. Since it speaks the same API format as Anthropic, Claude Code doesn't know (or care) that the model is local. According to Ollama's Claude Code page, chat, file edits, running commands, tool calling, subagents and vision all work with compatible models. The model has to support tools, otherwise Claude Code can talk but can't do anything.

Step 1: Install Ollama and Claude Code

Get Ollama from ollama.com/download for Windows, macOS or Linux. If you already have it, update it, because launch is a newer command. This should print help, not an error:

ollama launch --help

Then install Claude Code. On macOS and Linux:

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

On Windows, use the installer command shown in Ollama's Claude Code docs or Anthropic's install page. Check it worked with claude --version.

Step 2: Pick a model your machine can actually run

Ollama's docs and the model page both suggest Qwen 3.6 for this, and it's built for agent-style coding. These are the sizes listed on ollama.com/library/qwen3.6:

TagDownload sizeContextInput
qwen3.6 (latest)23 GB256KText and image
qwen3.6:27b18 to 19 GB256KText and image

The model has to fit in your GPU memory (or unified memory on Apple Silicon) plus room for the context, and a long context takes a lot of memory. If it doesn't fit, Ollama spills to the CPU and everything slows to a crawl. On a smaller machine, pick a smaller model with the tools tag from the Ollama library. It won't be as clever, but it'll be usable.

Step 3: Raise the context length before you start

This is the step that decides whether the whole thing works. Ollama picks a default context based on your VRAM, and the defaults are small for this job:

GPU memoryDefault context
Under 24 GiB4k tokens
24 to 48 GiB32k tokens
48 GiB or more256k tokens

Claude Code sends your instructions, file contents and tool output on every turn. At 4k tokens it runs out of room almost straight away, forgets what it was doing, and looks broken. Ollama's context length page says agents and coding tools should be set to at least 64000 tokens. You have two ways to do that:

  • Ollama app: open its settings and move the context length slider to 64k or more.
  • Command line: start the server with the variable set.
OLLAMA_CONTEXT_LENGTH=64000 ollama serve

On Windows PowerShell, set it for the session first: $env:OLLAMA_CONTEXT_LENGTH="64000"; ollama serve. If Ollama is already running in the tray, quit it first, or the new value won't apply.

Step 4: Launch Claude Code

From your project folder:

cd ~/projects/my-app
ollama launch claude --model qwen3.6

Without --model, it asks you to pick one. It pulls the model if you don't have it yet, which takes a while for a 23 GB download, so start it before lunch, not before a meeting.

While it's running, check from another terminal that the model really is on the GPU and that your context setting took effect:

ollama ps
# look at PROCESSOR (you want 100% GPU) and CONTEXT (64000 or more)

For scripts: run it without questions

The --yes flag skips the menus and pulls the model if needed. Anything after -- goes straight to Claude Code:

ollama launch claude --model qwen3.6 --yes -- -p "explain how this repository is organised"

The manual way, if you prefer

ollama launch just sets three environment variables for you. You can set them yourself, which is useful in a Docker container or a CI job:

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

If Claude Code still seems to talk to the wrong place, run /status inside it. Ollama's docs warn that Claude Code's own settings file can override shell variables, so a base URL you set months ago in settings will win.

The catch: when it "works" but is useless

Three things make a local setup feel broken when it isn't:

  1. Context too small. The agent loses track after a couple of steps. Fix it with Step 3 and confirm in ollama ps.
  2. Model on the CPU. ollama ps shows a CPU/GPU split. Answers take minutes. Use a smaller model or a shorter context.
  3. A model without tool support. It chats but never edits files or runs commands. Pick a model tagged tools.

Be realistic too. A 27B model on a home GPU is not the same as Anthropic's hosted models. I'd use the local setup for private code, small focused tasks and explaining a codebase, and switch back to the hosted models for big multi-file changes.

How to undo it

ollama launch doesn't change your normal Claude Code setup. Run plain claude in a new terminal and it uses your usual account. If you exported the variables yourself, clear them:

unset ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY ANTHROPIC_BASE_URL

To free the disk space, remove the model with ollama rm qwen3.6.

A few things I learned

  • Context length is the whole game. 4k is fine for chat and useless for an agent.
  • Check ollama ps, not your feelings. It tells you the real context size and whether the GPU is doing the work.
  • Tools support is required. No tools, no agent.
  • Settings beat environment variables. Use /status when the connection looks wrong.

If you're new to running models at home, start with my guide to running local LLMs with Ollama and running AI models on your own hardware. For the agent side, see how to set up your first AI agent and MCP vs skills. If you'd like a private AI setup built for your team, that's part of my AI and automation services.

Frequently asked questions

Can Claude Code run with a local model?

Yes. Ollama provides an Anthropic-compatible API, so Claude Code can use a model running on your own computer. Run ollama launch claude and pick a model that supports tools, such as Qwen 3.6. Chat, file edits, running commands and tool calling work with compatible models.

What context length does Claude Code need with Ollama?

Ollama recommends at least 64000 tokens for coding agents like Claude Code. By default Ollama uses only 4k on GPUs with under 24 GiB of VRAM and 32k on 24 to 48 GiB. Raise it with the app's slider or OLLAMA_CONTEXT_LENGTH, then confirm with ollama ps.

Which Ollama model is best for Claude Code?

Ollama's own docs suggest Qwen 3.6, which supports tools, thinking and images with a 256K context window. The 27b tag is about 18 to 19 GB. The model must support tools, and it should fit fully in GPU memory with your chosen context, or it will be very slow.

How do I point Claude Code at Ollama without ollama launch?

Set ANTHROPIC_BASE_URL to http://localhost:11434, ANTHROPIC_AUTH_TOKEN to ollama and ANTHROPIC_API_KEY to an empty value, then run claude with the model name. Claude Code's settings file can override these, so run /status inside Claude Code if it connects to the wrong place.

Why is Claude Code so slow with my local model?

Usually the model doesn't fit in GPU memory, so Ollama runs part of it on the CPU. Run ollama ps and check the PROCESSOR column. If it shows a CPU and GPU split, use a smaller model or lower the context length until it runs fully on the GPU.

Comments

Questions and corrections are welcome. I read every comment before it appears, and remove spam and promotional links.