AgentRecipes
Recipes › Engineering & security

How to run Claude Code on a local model with Ollama

Engineering & securityClaude Code✓ Tested by BranoLabs

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

Step-by-step recipe

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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>".
  6. Check the result yourself: run the code, read the diff, and only then move on to your real project.

Copyable prompt

Prompt template
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

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

Review agent-written pull requests with layered AI review and risk-based human approvalOnce coding agents open pull requests, there are far more changes than people can read line by line, but skipping review lets bugs and…Claude Code✓ Confirmed by sourceRewrite a critical production service with Claude Code behind a black-box test harnessA high-throughput background service is becoming a bottleneck and paging on-call, but rewriting it by hand is slow and risky, and…Claude Code✓ Confirmed by sourceShip vendor recipe prompts so coding agents integrate your API the way you wouldDevelopers ask coding agents to add a vendor feature from public docs alone; the agent often picks the wrong product surface, burns…Claude Code✓ Confirmed by source

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.