Running Claude Code Fully Locally with Ollama (Yes, It’s Possible — With Caveats)

Claude Code is designed as a cloud-first, tool-centric coding agent tightly coupled to Anthropic’s infrastructure. Out of the box, it does not support local models.

However, with a combination of:

  • endpoint redirection,

  • model aliasing inside Ollama,

  • and a tool-capable local model,

you can run Claude Code entirely locally against Ollama — including file edits, refactors, and shell tools.

This article documents the exact path that works, the failure modes you will hit, and the engineering trade-offs.

Why Claude Code Is Hard to Run Locally

Claude Code makes three strong assumptions:

  1. Anthropic authentication is always available

  2. Model names are fixed (claude-sonnet-*)

  3. Tool calling is mandatory

Most “local Claude” guides fail because they only solve one of these.

To succeed, you must solve all three.


Architecture That Actually Works

VS Code └─ Claude Code extension ├─ hardcoded model name (claude-sonnet-*) ├─ mandatory tools └─ Anthropic-style requests ↓ Ollama (localhost) ↓ Tool-capable local model (Qwen)

Key insight:

You don’t change Claude Code — you adapt Ollama to look like Anthropic.

Step 1: Redirect Claude Code to Ollama

In VS Code Command palette -> Preferences: Open User Settings (JSON):

{ "claudeCode.environmentVariables": [ { "name": "ANTHROPIC_BASE_URL", "value": "http://127.0.0.1:11434" }, { "name": "ANTHROPIC_AUTH_TOKEN", "value": "ollama" } ], "claudeCode.disableLoginPrompt": true }

This bypasses cloud calls and sends all traffic to Ollama.

At this point:

  • UI works

  • Requests flow

  • But you will get 404 model not found

That is expected.

Step 2: Understand the Model Name Problem

Claude Code always sends model names like:

claude-sonnet-4-5-20250929

Ollama does not have such models.

You cannot configure Claude Code to use gemma, llama, or qwen directly.

Solution: Model aliasing

Ollama lets you create lightweight aliases that map one model name to another.


Step 3: Why Gemma Fails (Important)

Gemma models (including gemma3n) do not support tool calling.

Claude Code always sends a tools schema.

Resulting error:

does not support tools

This is a hard failure, not a timeout or config issue.

Conclusion

Gemma works for chat, not for Claude Code.


Step 4: Use a Tool-Capable Model

You need a model that supports:

  • structured tool calls

  • JSON responses

  • streaming + edits

Recommended

ollama pull qwen2.5-coder:7b

This is the smallest reliable model that works with Claude Code.


Step 5: Create Claude-Compatible Aliases

Create a Modelfile:

FROM qwen2.5-coder:7b

Then create aliases Claude Code expects:

ollama create claude-sonnet -f Modelfile ollama create claude-opus -f Modelfile ollama create claude-haiku -f Modelfile

No weights are duplicated.
Only metadata is created.

Now Ollama can answer requests for claude-sonnet-*.

Result: Fully Local Claude Code

At this point, Claude Code can:

  • create files

  • edit files

  • run shell commands

  • refactor code

  • reason about repos

All without cloud access.




Comments

Popular Posts