Skip to content
Aventail™ investigation into UK government AI dependence featured in Computer Weekly.Read the story
Aventail™
All guides

Claude Code + Ollama: run Claude Code on your own models

12 min read

Run Claude Code on a local model with Ollama: one command, the manual environment variables, the models that work, the limits, and the same setup for a whole team.

Claude Code can run against a model served by Ollama on your own machine. Since January 2026 Ollama speaks Anthropic's Messages API, so Claude Code treats a local model as if it were Anthropic's endpoint. One command starts it. Nothing you type leaves the computer, and there is no per-token bill.

You need Ollama 0.15 or later, a coding model with a 64K context window, and 16 to 32 GB of memory depending on the model. This guide gives the one-command path, the manual path with environment variables, how to check the model is really local, what does not work on a non-Anthropic model, and how to roll the same setup out to a team with Aventail™ Connect.

What you need

Minimum

Comfortable

Ollama

0.14.0 for the Anthropic-compatible API; 0.15 for ollama launch

Latest release

Memory (unified or VRAM)

16 GB for a 20B model such as gpt-oss:20b

32 GB for 24B to 30B models at 64K context

Context length

64K tokens

128K tokens for larger repositories

Disk

14 to 20 GB per model

Space for two or three models

Claude Code

Any current version

Latest release

Ollama sets a default context length from your GPU memory: 4K below 24 GiB, 32K from 24 to 48 GiB, 256K at 48 GiB and above. Claude Code needs at least 64K, so on most laptops you raise it by hand in step 1.

Step 1: install Ollama and set the context length

macOS and Linux:

curl -fsSL https://ollama.com/install.sh | sh

Windows, in PowerShell:

irm https://ollama.com/install.ps1 | iex

Set the context length before you serve a model. The quickest way is the slider in the Ollama app settings. From a terminal:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

Check what is loaded and whether it sits on the GPU or the CPU:

ollama ps

The PROCESSOR column shows the GPU and CPU split. If part of the model has spilled to the CPU, pick a smaller model or a shorter context.

Step 2: pull a coding model

Pick one model that fits your memory and supports tool calling. Claude Code edits files and runs commands through tools, so a model without tool support will chat but not work.

Model

Size on disk

Context

Memory guidance

Notes

gpt-oss:20b

14 GB

128K

16 GB

Smallest workable choice; tools and thinking

qwen3-coder:30b

19 GB

256K

Not published; plan for 32 GB

Coding-tuned, tools

glm-4.7-flash

19 GB

198K

About 23 GB VRAM at 64K context

Tools and thinking

devstral-small-2

15 GB

384K

A single RTX 4090 or a Mac with 32 GB

Tools and vision

qwen3.5:27b

17 to 20 GB

256K

Not published; plan for 32 GB

Ollama's own example model for Claude Code

gemma4:26b

16 to 19 GB

256K

Not published; plan for 32 GB

Tools, thinking and vision

Pull the one you chose:

ollama pull qwen3-coder:30b

These are the models Ollama names for Claude Code. For a wider comparison with licence, benchmark and memory tier for each model, see Best local LLMs for coding.

Two models that older guides recommend, glm-4.6 and kimi-k2, were retired from the Ollama library in June 2026. If a guide tells you to pull them, pick from the table instead.

Step 3: install Claude Code

macOS, Linux and WSL:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

You do not need an Anthropic account or API key for the local path. Claude Code will still ask you to trust the folder you open it in.

Step 4: launch Claude Code on Ollama with one command

ollama launch claude

Ollama asks which model to use, pulls it if it is missing, and starts Claude Code pointed at the local server. No environment variables, no config file. To skip the picker:

ollama launch claude --model qwen3-coder:30b

For scripts, --yes skips every prompt and anything after -- goes to Claude Code:

ollama launch claude --model qwen3-coder:30b --yes -- -p "how does this repository work?"

ollama launch also starts OpenCode, Codex, VS Code and Droid the same way. The OpenCode version is in our guide to OpenCode with Ollama.

Step 5: or point Claude Code at Ollama by hand

Use this when you want Claude Code to start from its own command, in an editor, or on a machine where ollama launch is not available.

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3-coder:30b

Three things to know about these lines:

  • ANTHROPIC_AUTH_TOKEN is required but ignored. The local server does not check keys. Any non-empty value works.

  • ANTHROPIC_API_KEY="" stops Claude Code from sending a stale Anthropic key alongside the token.

  • --model takes the Ollama model name. Claude Code's opus, sonnet and haiku aliases still exist; point them at local models with ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL. The Haiku alias also runs Claude Code's background tasks, so give it a model you have pulled.

To make it permanent, put the variables in ~/.claude/settings.json:

{
"env": {
"ANTHROPIC_AUTH_TOKEN": "ollama",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_BASE_URL": "http://localhost:11434",
"ANTHROPIC_MODEL": "qwen3-coder:30b",
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "64000",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}

The last two lines matter on a local model:

  • CLAUDE_CODE_MAX_CONTEXT_TOKENS tells Claude Code the real window. For a model name it does not recognise, Claude Code assumes a 1M-token window, so it never compacts the conversation and the local model runs out of context mid-task. Set it to the context length you gave Ollama.

  • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns off auto-update, telemetry, feedback and release-note checks, so the only network traffic left is to localhost.

Some tools expect Anthropic model names. Ollama can alias a local model to one:

ollama cp qwen3-coder:30b claude-3-5-sonnet

Step 6: check it is running locally

Confirm the endpoint answers before you open a repository:

curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "qwen3-coder:30b", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'

A 200 means Ollama is serving the model through the Anthropic-compatible API. Inside Claude Code, run /status and check the Anthropic base URL line shows http://localhost:11434. Then unplug the network and ask it to explain a file. If it answers, the model is local.

What works and what does not on a local model

Works: chat, reading and editing files, running commands, the agent loop, MCP servers you configure yourself, /init, /compact, CLAUDE.md.

Does not work, or works differently:

  • Anthropic does not support it. Anthropic's own documentation says it does not support routing Claude Code to non-Claude models through any gateway. It runs, but a Claude Code update can break it and support will not help.

  • No prompt caching. Ollama's Anthropic-compatible API ignores cache_control, so every turn resends the whole conversation. On a local model that costs time, not money.

  • Approximate context counts. The token-count endpoint is missing, so /context estimates.

  • Hosted web search and some advanced tool controls are not fully supported. tool_choice, batches, citations, PDF blocks and image URLs are not supported either; images work as base64 only.

  • Claude.ai features are off. Connectors, Remote Control, voice dictation and server-managed settings need a claude.ai login and Anthropic's endpoint.

  • Tool reliability depends on the model. The 20B and 30B models follow the tool protocol most of the time. Expect more retries and the odd malformed edit compared with Claude. A model under 20B is not worth the time.

  • Speed. A 30B model at 64K context on a 32 GB Mac feels like a slow connection, not a fast one. The first response after a long idle takes longest because the model reloads.

Ollama cloud models are not your own models

Ollama also offers :cloud models such as gemma4:cloud and qwen3-coder:480b-cloud, and a hosted endpoint at ollama.com. They are convenient and Ollama states it does not log or train on prompts. They are still a third party's servers, hosted primarily in the United States with overflow to Europe. If the reason you are reading this is that your code must stay on your machines, do not pass a :cloud name to --model, and set ANTHROPIC_BASE_URL to localhost, not ollama.com.

The same setup for a team with Aventail™ Connect

The steps above work for one developer who manages their own machine. They do not give an IT or security lead what they need: a way to know which machine sent which request where, a rule that keeps certain work on local models, and no shell profile that a developer can edit back.

Aventail™ Connect configures supported apps to send their model requests through Aventail™ Link, the inference engine and gateway that runs on each machine. Routing rules are set once in Aventail™ Control and evaluated on the device. Claude Code, Claude Desktop, OpenCode and Codex are supported.

  1. Sign in to Control at control.aventail.co.uk and choose Connect a device.

  2. Install Link on each developer machine. Desktop installers exist for macOS (Apple silicon), Windows and Linux. For a fleet, the unattended line is:

    curl -fsSL https://get.aventail.co.uk/install.sh | AVENTAIL_REGISTRATION_KEY='YOUR_REG_KEY' sh

    Check with aventail status.

  3. Serve a model. In Models, download a coding model and choose Start serving. Claude Code needs at least 64K context; Link warns below 128K. The context slider shows the estimated memory as you move it.

  4. Connect Claude Code. In Connected apps, choose Connect next to Claude. Claude Code uses the same connection as Claude Desktop. There is no configuration file, endpoint or key to enter. Open a fresh Claude Code session and leave the model selection to Link, not to Claude Code.

  5. Check where it ran. Send a harmless prompt, then open Requests in Control. The model label alone does not show the destination; the Requests view does.

  6. Write the routing rule. In Control, a rule has conditions, a destination and up to three fallback hops, and the first matching enabled rule wins. For a local-only team, permit only On device. If local serving is unavailable, the request fails with an error. It is not sent to a disallowed destination. For a team that may use cloud, set On device as primary with one fallback hop to an approved provider connection, which runs through your own account with that provider.

Disconnect restores the settings Link changed. Developers keep the Claude Code they already use; what changes is where the requests go, and that an admin can see it.

Aventail™'s Free plan covers three connected devices, including business use, with no trial clock. Starter is £50 a month excluding VAT with ten devices included, then £5 a month for each extra device. Routing policies need Control for Enterprise.

Which path to take

Claude Code + Ollama by hand

Claude Code with Aventail™ Connect

Who it suits

One developer on their own machine

A team whose code must stay on approved models

Setup

Environment variables or ollama launch

Connect button in Link, rules in Control

Who picks the model

The developer

The developer within the rule, or the rule

Where requests go

Wherever the shell profile says

Where the routing rule says, evaluated on the device

Record of requests

None

Requests view in Control

If the local model is down

Developer changes the base URL

Fails closed, or falls back to an approved provider

Cost

Free

Free for three devices; Starter is £50 a month excluding VAT with ten devices

Frequently asked questions

Can Claude Code work with a local LLM?
Yes. Ollama 0.14 and later expose an Anthropic-compatible API, and Claude Code accepts any base URL that speaks it. ollama launch claude does the setup in one command.

Is Claude Code free if I run it locally?
Claude Code itself is free to install. Running it on a local model costs nothing per token. You pay for the hardware and the electricity, and you give up Anthropic's models and support.

Can I run Claude Code without internet?
Yes, once the model is pulled and Claude Code is installed. Set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 so it stops checking for updates, then work offline.

Which Ollama model is best for Claude Code?
On 16 GB, gpt-oss:20b. On 32 GB, qwen3-coder:30b or glm-4.7-flash. Above that, the 120B class if it fits. The deciding factor is tool-calling reliability, so test the model on a real edit before you settle.

Does this work on Windows?
Yes. Install Ollama from the Windows installer, install Claude Code with the PowerShell line in step 3, and set the same variables with $env:ANTHROPIC_BASE_URL = "http://localhost:11434" and so on, or use ollama launch claude.

Does it work in VS Code?
Yes. The Claude Code extension reads the same environment and settings. Set the variables in ~/.claude/settings.json so the extension picks them up, then start a session.

Is my code sent to Anthropic?
Not for model requests when the base URL is localhost. Two checks still call Anthropic directly: the fast-mode check and the WebFetch domain safety check. Disable non-essential traffic and avoid WebFetch if that matters.

Sources

  1. Ollama, Claude Code integration: https://docs.ollama.com/integrations/claude-code

  2. Ollama, Anthropic compatibility: https://docs.ollama.com/api/anthropic-compatibility

  3. Ollama, Context length: https://docs.ollama.com/context-length

  4. Ollama, CLI reference: https://docs.ollama.com/cli

  5. Ollama blog, Claude Code with Ollama (16 January 2026): https://ollama.com/blog/claude

  6. Ollama blog, ollama launch (23 January 2026): https://ollama.com/blog/launch

  7. Ollama cloud: https://ollama.com/cloud

  8. Ollama library: gpt-oss, qwen3-coder, glm-4.7-flash, devstral-small-2, qwen3.5, gemma4, glm-4.6, kimi-k2

  9. Anthropic, Claude Code environment variables: https://code.claude.com/docs/en/env-vars

  10. Anthropic, Model configuration: https://code.claude.com/docs/en/model-config

  11. Anthropic, LLM gateway: https://code.claude.com/docs/en/llm-gateway and https://code.claude.com/docs/en/llm-gateway-connect and https://code.claude.com/docs/en/llm-gateway-protocol

  12. Anthropic, Feature availability: https://code.claude.com/docs/en/feature-availability

  13. Aventail™, Connect overview: https://docs.aventail.co.uk/docs/connect/overview

  14. Aventail™, Initial setup: https://docs.aventail.co.uk/docs/getting-started/initial-setup

  15. Aventail™, Routing: https://docs.aventail.co.uk/docs/fleet/routing

  16. Aventail™, Pricing: https://aventail.co.uk/#pricing

All sources were read on 15 November 2026.

We use optional cookies and tracking to identify visiting companies, load our contact form, measure Google Ads download clicks and understand page use with PostHog on our homepage, Connect and How it works pages, Ollama and LM Studio comparison guides and campaign pages. Cookie policy