Running Claude Code Fully Locally with Ollama (Yes, It’s Possible — With Caveats)
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:
-
Anthropic authentication is always available
-
Model names are fixed (
claude-sonnet-*) -
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
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):
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:
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:
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
This is the smallest reliable model that works with Claude Code.
Step 5: Create Claude-Compatible Aliases
Create a Modelfile:
Then create aliases Claude Code expects:
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.

%20applied%20to%20Transformer%20models%20in%20machine%20learning.%20The%20image%20shows%20a%20neural%20networ.webp)

Comments
Post a Comment