How to run Claude Code with a local model

You can point Claude Code at a local model served by Ollama instead of signing in to a vendor account. In our 2026-10-25 test on Claude Code 2.1.310, a headless run with a small local model edited a file when given the exact path and strings, and made no edit on a vaguer prompt. This says nothing about Claude models.

Checked by Agentic Weekly's editorial process: vendor docs re-read (the test was run on 2026-10-25, not re-run on this date).

Last verified: 2026-10-26 (America/Chicago) · Versions covered: Claude Code 2.1.310 (native installer); Ollama 0.40.11; Qwen2.5-3B-Instruct (Q4_K_M) · Evidence: Tested (see “What we tested”)

What to expect

Claude Code is Anthropic's coding agent for the terminal. Ollama documents a way to connect it to local and cloud models through Ollama's Anthropic-compatible API (Ollama docs, read 2026-10-26). That lets you try Claude Code without a Claude subscription, or keep code on your machine. See what an AI coding agent is if the term is new.

Expect it to depend heavily on the model. Our test used a small local model on a machine with no GPU, and it needed an exact prompt. We did not test any Claude model, so none of this says how Claude Code behaves with the models it is built around.

Prerequisites

  • Operating system and hardware we ran on: Linux x86_64 machine, 8 CPUs, no GPU. Not run by us: macOS and Windows.
  • Claude Code 2.1.310 installed with Anthropic's native installer. The tool page lists 2.1.310 (released 2026-10-23); we did not check for a newer version on 2026-10-26.
  • Ollama 0.40.11 with Qwen2.5-3B-Instruct (4-bit, Q4_K_M) pulled. Other models: not tested.
  • Accounts and keys: no vendor account, login or API key was used in our test.

Step 1: Install Claude Code with the native installer

Our test used Anthropic's installer script, which we read first (a copy is kept with our test files). The installer is the method Ollama's page and the Claude Code README list for macOS and Linux.

Command (as logged)
curl -fsSL https://claude.ai/install.sh | bash
Expected result
The headless run reported claude_code_version 2.1.310. We did not time the install.

The npm package installed an older version, 2.1.197, in an earlier shared npm install of ours, so the npm package was not the version we tested. If you install with npm, check claude --version first.

Step evidence: Tested (native install, 2026-10-25; log: /tests/claude-code).

Step 2: Serve a model with Ollama

We ran Qwen2.5-3B-Instruct (Q4_K_M) on Ollama 0.40.11. The model id Claude Code printed in our log was qwen2.5-3b-32k. Our log does not record how that tag was created, so we do not give a pull command. Ollama's page says to choose a model with enough context for your repository and, for larger repositories, to set the context length to 64k or higher. Details of our Ollama runs are in the Ollama test log.

Step evidence: Tested (a model served by Ollama 0.40.11; log: /tests/ollama).

Step 3: Point Claude Code at Ollama

Ollama's page (read 2026-10-26) gives two routes. The shortcut is ollama launch claude. The manual route sets three environment variables, then starts claude with a model name.

Manual setup (from Ollama's docs; values as written there)
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model <your-ollama-model>

Our log says the configuration pointed Claude Code at a local Ollama server through an Anthropic-compatible API, but it did not record the exact settings we used, so these variables come from Ollama's documentation and were not copied from our run. Ollama also notes that Claude Code settings can override shell variables, and suggests /status to check the connection. Claude Code printed that it did not recognize our model id and assumed a 200k-token context window.

Step evidence: Reported (not run by us). Source: https://docs.ollama.com/integrations/claude-code, read 2026-10-26.

Step 4: Run a headless edit

We made a folder with calc.py containing def add(a,b): return a-b and asked Claude Code to fix it in headless mode (claude -p). We ran it with permission mode acceptEdits and JSON streaming output; the exact flag spellings were not recorded.

Prompt that worked (attempt 2, as logged)
claude -p "Edit /full/path/calc.py: replace '    return a-b' with '    return a+b'"
Expected result (log excerpt, trimmed)
tool_use: Edit  file_path=.../calc.py  old_string="    return a-b"  new_string="    return a+b"
tool_result: The file .../calc.py has been updated successfully.
stop_reason: end_turn  is_error: false  num_turns: 2  duration: 85.9 s  time to first token: 74.9 s

Most of the 85.9 seconds was waiting for the first token, which our log attributes to the small model on a CPU-only machine rather than to Claude Code.

Step evidence: Tested (the headless edit, 2026-10-25; log: /tests/claude-code).

What failed

Our first prompt was vaguer and did not give the exact path. Claude Code answered that calc.py did not exist in the working directory and made no edit. We then tried the exact-path prompt above, which worked. That is one prompt that failed followed by one that worked, so it shows the setup can work, not how often.

Attempt 1 output (log excerpt)
Claude Code doesn't recognize the model "qwen2.5-3b-32k", so it assumes a context window of 200k tokens.
The file `calc.py` does not exist in the current working directory.

What we tested

Evidence: Tested (partial, 2026-10-25): native install, one headless edit task with a small local model, two attempts. Reported (not run by us): the Ollama environment variables and ollama launch claude.

  • What we ran: the native installer, then two headless prompts against a local Qwen2.5-3B-Instruct served by Ollama 0.40.11, on 2026-10-25 from 17:48 to 17:50 CDT (America/Chicago). One prompt failed, one worked.
  • Environment: Linux x86_64 machine, 8 CPUs, no GPU; no vendor account, login or API key.
  • Model: Qwen2.5-3B-Instruct (Q4_K_M) through Ollama 0.40.11. The result reflects Claude Code plus that small model, not any vendor's hosted model.
  • Full test log: Claude Code test log. Our log's cost field showed 0.0437 dollars with no API key in use, which we do not treat as a charge.
  • Reported, not run by us: the three environment variables, ollama launch claude, and every cloud-model route on Ollama's page.
  • Not tested: Claude models, subscription login, the sandbox and permission fixes in 2.1.309 and 2.1.310, claude ultrareview, --trust-workspace, Bedrock, Vertex or Foundry, any other local model, tool-heavy tasks and reliability over many runs.
Evidence by step
StepEvidenceCovered by
1 InstallTested/tests/claude-code
2 Serve a modelTested for our Qwen2.5-3B model; other models not tested/tests/claude-code and /tests/ollama
3 Point Claude Code at OllamaReported (settings not recorded in our log)Ollama's Claude Code page, read 2026-10-26
4 Headless editTested, two attempts/tests/claude-code

This is a small test, not a benchmark: one task, one small model, one machine.

Troubleshooting

Problems we hit or Ollama's docs describe
SymptomLikely causeFixSource
Claude Code says a file does not exist and makes no editA vague prompt with a small model; the model did not use the pathGive the exact full path and the exact strings to replace.Seen by us 2026-10-25, /tests/claude-code
A message that the model is not recognized and a 200k context window is assumedClaude Code does not know a local model's idThis appeared in our successful run too; set the model's real context in Ollama.Seen by us 2026-10-25, /tests/claude-code; context advice per Ollama's Claude Code page, read 2026-10-26
Settings seem ignoredClaude settings can override shell variablesUpdate any base URL or credentials in your Claude settings and run /status.Ollama's Claude Code page, read 2026-10-26
A very slow first responseA small model on a CPU-only machineExpect a long wait for the first token; ours was 74.9 s.Seen by us 2026-10-25, /tests/claude-code
  • Claude Code: Update now if you use the sandbox or run Claude Code on a cloud provider; skip if you wanted flashy new features, this is a hardening release. Tested (smoke test, 2026-10-25, local Qwen2.5-3B-Instruct, not vendor models).
  • Ollama: The common way to run open models locally on macOS, Windows and Linux, with a cloud option and an MIT-licensed open-source core. Tested (smoke test, 2026-10-25, local 3B model (Qwen2.5-3B)).

FAQ

Can Claude Code run without an Anthropic account?

In our 2026-10-25 test, yes for one task: with no vendor account, login or API key, Claude Code 2.1.310 edited a file through a local Ollama model. It is one test with a small model, so we do not generalize it.

Which local models work with Claude Code?

We ran only Qwen2.5-3B-Instruct (4-bit) through Ollama 0.40.11. It worked on an exact prompt and failed on a vaguer one. We have not tested other local models, so we cannot say which others work.

Is it as good as using Claude models?

We did not compare. We did not test any Claude model, and our small local model failed on a vague prompt before succeeding on an exact one. Treat this guide as showing the setup can work, not how well it works.

Is running Claude Code against a local model supported by Anthropic?

We have not verified this against Anthropic's documentation. Ollama documents the connection on its own docs site (read 2026-10-26), which is Ollama's statement, not Anthropic's. Check the official Claude Code docs before relying on it.

Have you tested running Claude Code with a local model?

Partly. On 2026-10-25 we ran the native installer and two headless prompts against Qwen2.5-3B-Instruct on Ollama 0.40.11; one failed and one edited the file. The environment variables here come from Ollama's docs.

Sources

Page history

  • : First published. Ollama's page re-read on this date; the test result is from 2026-10-25 and was not re-run.

Markdown version for agents: /guides/run-claude-code-with-a-local-model.md