How to run Claude Code on a local model with Ollama
Tested by BranoLabs: Tested by BranoLabs on 2026-10-22: Ollama 0.40.8 on a CPU-only Linux box (8 cores, no GPU) serving Qwen3 1.7B (Q4_K_M, 24k context), Claude Code 2.1.308 started headless with ANTHROPIC_BASE_URL=http://localhost:11434. Asked to create hello.py that sums 1 to 10 and run it, it wrote a correct file and reported the output 55 in about 7 minutes. The setup also matches Ollama's official Claude Code integration docs (docs.ollama.com/integrations/claude-code), checked live the same day. (checked 2026-10-22)
The problem
You want an agent that reads your project, writes files and runs commands, but you don't want your code sent to a cloud API, you want to work offline, or you don't want to pay per request. Claude Code normally talks to Anthropic's servers; Ollama can stand in for them with a model running on your own machine.
Tools needed
- Claude Code
- Ollama (local model server with an Anthropic-compatible API)
- A local coding model that supports tool calling (the source uses qwen3.5:9b)
- Optional: IntelliJ IDEA or any IDE with a built-in terminal
Step-by-step recipe
- Install Claude Code (for example with npm install -g @anthropic-ai/claude-code) and check that the claude command starts. You can run it from your IDE's built-in terminal so it works next to your code.
- Install Ollama and pull a coding model that supports tool calling, for example ollama pull qwen3.5:9b. Ollama's docs recommend a 64k-token or larger context window for real repositories; set it on the server (for example with the OLLAMA_CONTEXT_LENGTH environment variable) before you start.
- Point Claude Code at Ollama instead of Anthropic: set ANTHROPIC_BASE_URL to http://localhost:11434, set ANTHROPIC_AUTH_TOKEN to any placeholder such as ollama, leave ANTHROPIC_API_KEY empty, and start claude --model with your model name. As a shortcut, ollama launch claude --model <model> does the wiring for you.
- Start with a small, well-defined task in an empty or throwaway project (the source asks for a 2-3 class console task manager) and approve the file writes and commands Claude Code asks for.
- For scripts or CI, run it non-interactively with claude -p "<task>" and an explicit --allowedTools list, or with ollama launch claude --model <model> --yes -- -p "<task>".
- Check the result yourself: run the code, read the diff, and only then move on to your real project.
Copyable prompt
You are working in [PROJECT DIRECTORY] with a local model, so keep the plan short and do one step at a time. Task: [SMALL, CONCRETE TASK, e.g. 'add a --verbose flag to cli.py']. Rules: - Only touch these files: [FILES OR FOLDER]. - After each change, run [TEST OR RUN COMMAND] and show me the output. - If a command fails, read the error, fix it, and run it again at most [N] times before stopping to ask me. - Finish with a two-line summary of what changed.
Original template written by our AI agent for AgentRecipes, not copied from the source. Replace the [BRACKETS] and {{variables}} with your own values and test before relying on it.
What the builder reported
The author shows Claude Code with qwen3.5:9b via Ollama planning, creating and running a small Java console task manager, fixing its own errors along the way and asking permission before changes. They describe local quality as good for small tasks, with speed depending on hardware. No other figures are given.
These are the source author's own claims. BranoLabs also ran this recipe end to end.
Watch out for
- Speed depends entirely on your hardware. In our CPU-only test, a two-step task (write a file, run it) took about 7 minutes, mostly spent reading Claude Code's roughly 11,000-token system prompt and tool definitions.
- Context window: Claude Code's built-in instructions alone filled about 11,000 tokens in our test, so a default small context can cut them off. Ollama's docs ask for 64k+ for real repositories.
- The model must support tool calling, or Claude Code cannot edit files or run commands. Check with ollama show <model> that 'tools' is listed.
- Claude Code warns that it doesn't recognise local model names and assumes a 200k context window; its model-config docs explain how to set the real window.
- Small local models are fine for small tasks but well below Anthropic's cloud models on larger refactors, which the source's own comparison table also says.
Source
Original write-up: DEV Community (2026-10-21) ↗
Found via Agent Use Cases: “Run Claude Code on local models via Ollama”. This recipe summarises the source in words written by our AI agent; read the original for the full details. Link last checked 2026-10-22.
More engineering & security recipes
New agent recipes in your inbox
A short email with the newest automation recipes, each linked to its real-world source. No spam. Every email has a one-click unsubscribe link.