GuidesHosting choices

Claude Code with Ollama: run it on local and cloud models

Run Claude Code on Ollama models: ollama launch claude, the variables by hand, the 64K context it needs, which models to pick, cloud prices and what breaks.

November 23, 2026The Everpod team
The short answer

Yes. Ollama has served an Anthropic-compatible API since version 0.14.0 (January 2026), so Claude Code can run on Ollama models that support tool calling, on your own machine or in Ollama’s cloud. The quick way is ollama launch claude (Ollama 0.15 or later; 0.40.17 is current as of November 2026), which picks or downloads a model and starts Claude Code pointed at it; ollama launch claude --model qwen3.8:27b skips the picker. By hand, set ANTHROPIC_BASE_URL=http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama and an empty ANTHROPIC_API_KEY, then run claude --model qwen3.8:27b.

Two settings decide whether a local model holds up. Give it at least 64K tokens of context in Ollama, which starts at 4K on a GPU with less than 24 GiB, and tell Claude Code the same number with CLAUDE_CODE_MAX_CONTEXT_TOKENS, because it assumes 1M tokens for a model it does not know. Anthropic does not support Claude Code on non-Claude models, and your Claude plan is not used.

The one-command way: ollama launch claude

Ollama 0.15.0 (January 21, 2026) added ollama launch, which starts a coding agent already wired to Ollama’s models, with, in Ollama’s words, “no environment variables or config files needed.” With Ollama installed and running:

ollama launch claude                              # choose a model from a list
ollama launch claude --model qwen3.8:27b          # a local model
ollama launch claude --model glm-5.3-flash:cloud  # one of Ollama's cloud models
Copied

Without --model you get a picker with a Recommended section at the top. A local model you have not downloaded is pulled after a prompt, a :cloud model needs you signed in to Ollama, and if Claude Code itself is missing, the launcher asks “Claude Code is not installed. Install now?” and runs Anthropic’s install script. Anything after -- goes to Claude Code. --yes answers the prompts, skips the pickers, pulls a missing model and requires --model, which makes it the form for scripts and CI; without it, a run with no terminal stops at a missing model with model "<name>" not found; run 'ollama pull <name>' first, or use --yes to auto-pull. The example on Ollama’s Claude Code page:

ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"
Copied

The launcher changes no Claude Code file. It starts claude with these variables set for that one process, so a plain claude afterwards talks to Anthropic as before. From its source at v0.40.17:

VariableSet toWhat it does
ANTHROPIC_BASE_URL
Your OLLAMA_HOST, by default http://127.0.0.1:11434Sends Claude Code’s requests to Ollama
ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY
ollama, and emptyA placeholder credential in place of your Claude sign-in
ANTHROPIC_DEFAULT_OPUS_MODEL, _SONNET_, _HAIKU_, CLAUDE_CODE_SUBAGENT_MODEL
The model you choseThe opus, sonnet and haiku aliases, and subagents with no model of their own, all land on that model
CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST
1Claude Code ignores a base URL or key in your settings files, so nothing there can redirect the session; the launcher also blanks CLAUDE_CODE_USE_BEDROCK and the other provider switches
CLAUDE_CODE_MAX_CONTEXT_TOKENS, CLAUDE_CODE_AUTO_COMPACT_WINDOW, CLAUDE_CODE_MAX_OUTPUT_TOKENS
The model’s own limits, output capped at 128,000Cloud models only
CLAUDE_CODE_AUTO_MODE_SERVER
0, unless you set itAuto mode uses Claude Code’s own classifier requests; the source’s reason: “Ollama does not provide Anthropic’s server-side auto-mode checks.”
ENABLE_CLAUDEAI_MCP_SERVERS, CLAUDE_CODE_ATTRIBUTION_HEADER, DISABLE_ERROR_REPORTING, DISABLE_FEEDBACK_COMMAND, CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY
false, 0, then 1 for the restNo MCP servers from your claude.ai account, no attribution block at the top of the system prompt, no error reports, /feedback or surveys

The row to notice is the cloud-only one. For a local model the launcher tells Claude Code nothing about the context window, and that is the setting that most often spoils a local session (below).

Setting it up by hand

Ollama’s manual setup, for when you start Claude Code yourself, with its example model swapped for qwen3.8:27b:

export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model qwen3.8:27b
Copied

Ollama’s recipe stops at --model, but Claude Code still asks for Claude models by alias in a few places: its built-in claude-code-guide helper runs on Haiku, the web-fetch helper prefers Haiku, and Claude can name sonnet or haiku when it starts a subagent. Against Ollama those resolve to Claude model IDs it does not serve. The launcher closes that gap by pointing the aliases at your model; by hand, add the same lines, plus the context window from the next section:

export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3.8:27b
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3.8:27b
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3.8:27b
export CLAUDE_CODE_SUBAGENT_MODEL=qwen3.8:27b
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000   # the CONTEXT value from ollama ps
Copied

What each alias variable does with Claude’s own models is in Claude Code models. To keep the setup, put the same names in the env block of a settings file: a project’s .claude/settings.local.json to use Ollama in one repository, or ~/.claude/settings.json to send every session there. A settings-file value beats a shell export, and in the session /status shows an Anthropic base URL line with Ollama’s address when it worked.

To test Ollama’s side alone, send it one request in Anthropic’s format; a JSON reply with a content array means the endpoint and the model work:

curl -sS http://localhost:11434/v1/messages \
  -H "content-type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{"model": "qwen3.8:27b", "max_tokens": 1024, "messages": [{"role": "user", "content": "Say hello."}]}'
Copied

Context length: the setting that breaks it

A coding agent resends everything on each step. Ollama’s November 2026 post on long agent sessions puts it plainly: “the harness sends the model the entire conversation so far: the system prompt, every tool definition, your request, every file the agent has read, and every command it has run.” Ollama’s context length page sets the default window by GPU memory:

VRAMDefault context
Under 24 GiB
4K tokens
24 to 48 GiB
32K tokens
48 GiB or more
256K tokens

For coding tools the same page asks for “at least 64000 tokens”, up from the 32K Ollama suggested when it launched Claude Code support in January. Raise it with the slider in the Ollama app’s settings, or start the server with the variable:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Copied

On Linux, where Ollama runs as the ollama systemd service, run systemctl edit ollama.service, add the two lines below, then systemctl daemon-reload and systemctl restart ollama. On a Mac with the Ollama app, run launchctl setenv OLLAMA_CONTEXT_LENGTH 64000 and restart the app.

[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"
Copied

Then check what the model is really running with. In Ollama’s example:

ollama ps
NAME             ID              SIZE      PROCESSOR    CONTEXT    UNTIL
gemma4:latest    c6eb396dbd59    9.6 GB    100% GPU     131072     2 minutes from now
Copied

CONTEXT is the window in use. A larger one needs more memory, and Ollama’s advice is to keep PROCESSOR at 100% GPU rather than let the model spill onto the CPU.

Tell Claude Code the same number

Claude Code does not know qwen3.8:27b, so it guesses the window: since version 2.1.323 it assumes 1M tokens for any model ID it does not recognise (200K before), and starts with a warning beginning ⚠ Model "<your model>" isn't recognized · context assumed to be 1m tokens. It compacts the conversation only as it nears that guess. Ollama, for its part, does not refuse a chat that outgrows its window: by default its server drops the oldest messages until the rest fits, always keeping the system messages and the latest message (server/prompt.go in 0.40.17; models on Ollama’s MLX engine are left out of this trimming). The model loses the start of the session while Claude Code believes it is all still there.

The fix is CLAUDE_CODE_MAX_CONTEXT_TOKENS, set to the CONTEXT value from ollama ps in the environment that starts Claude Code. Per Anthropic’s model configuration page, for an ID that does not start with claude- it takes effect on its own, and compaction then runs against the window you declared. CLAUDE_CODE_AUTO_COMPACT_WINDOW cannot do the job here, since it takes no value below 100,000 tokens. With the launcher and a local model, put it in front of the command:

CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000 ollama launch claude --model qwen3.8:27b
Copied

/context shows how full the window is, but through Ollama its numbers are estimates: Ollama has no count_tokens endpoint, so Claude Code counts characters instead.

Which models to use

Claude Code reads, edits and runs commands through tool calls, so the model must support them; Ollama’s library marks those with a tools tag. The Recommended list in ollama launch comes from Ollama’s servers and changes over time. On November 23, 2026 it held these, with prices per million input and output tokens from Ollama’s pricing page:

ModelRunsSize or priceWindowOllama’s description
qwen3.8:27b
Your GPU18 GB download; the launcher lists about 28 GB of VRAM256K“Coding, research, and long-horizon agentic tasks”
gemma4:12b
Your GPU7.7 to 8.0 GB; about 11 GB of VRAM256K“Agentic workflows and multimodal reasoning”
qwen3.5:4b
Your GPU3.3 to 4.0 GB; about 6 GB of VRAM256K“Compact multimodal reasoning and tool use”
glm-5.3-flash:cloud
Ollama’s cloud$0.15 / $0.501M“Fast reasoning for coding and agentic workloads with 1M context and native image understanding”
deepseek-v4.1-flash:cloud
Ollama’s cloud$0.30 / $1.20; $0.15 / $0.60 off-peak1M“Fast coding and agentic tool use with 1M context and native image understanding”
kimi-k3.1-pro:cloud
Ollama’s cloud$2.00 / $10.001M“Long-horizon agentic reasoning with multimodal tool use”

The window is what the model supports, not what Ollama gives it: on a smaller GPU a local model still starts at the default above until you raise it, and its memory use grows with the window. Whether a model that fits your GPU is worth buying a bigger one for is the question in local AI box against cloud.

Some older families are flagged by the launcher itself: codellama, qwen2.5, qwen2.5-coder, llama3 to llama3.3, mistral, starcoder, and deepseek-r1 at 32B and below. Choosing one brings up a notice that it “does not work well with Claude Code”, a suggested agent-capable model, and a choice of Pick another model or Launch anyway.

Ollama’s cloud models

A model name ending in :cloud runs on Ollama’s servers instead of your GPU while still going through your local Ollama, at the model’s full context length. Sign in once with ollama signin, then launch it like any other model. Ollama’s cloud FAQ says it processes prompts and responses “transiently to provide the service but does not store or log that content and never trains on it,” and its pricing page says the models are hosted “primarily in the United States” with some routing to Europe for capacity. It is still not local: your code leaves the machine.

New plans have billed cloud use per token since August 31, 2026. As of November 23, 2026:

There are no five-hour or weekly limits on these plans. Some models are cheaper outside 12:00 to 18:00 UTC on weekdays and all weekend. Concurrency is worth checking, since Claude Code can run subagents in parallel: Pay as you go and Pro take 3 requests at once, Max and Team 10, and requests beyond that queue.

Without Ollama installed at all, Claude Code can call the hosted endpoint directly with a key from ollama.com/settings/keys. The key must go in ANTHROPIC_AUTH_TOKEN, because the endpoint requires Authorization: Bearer and does not take x-api-key alone, and the model goes by its hosted identifier, such as glm-5.3-flash or gemma4:31b, rather than its :cloud name:

ANTHROPIC_BASE_URL=https://ollama.com \
ANTHROPIC_AUTH_TOKEN="$OLLAMA_API_KEY" \
ANTHROPIC_API_KEY="" \
claude --model glm-5.3-flash
Copied

This route sets none of the launcher’s variables. Without the model aliases, the requests Claude Code sends to its Haiku, Sonnet and Opus aliases reach ollama.com under Claude’s names, so set the four alias lines from the manual setup above to the hosted identifier as well. As for the limits, leaving them unset is harmless for a 1M-token model like this one, but gemma4:31b, for one, has a 256K window, so give it CLAUDE_CODE_MAX_CONTEXT_TOKENS=262144. Ollama also says hosted web search and advanced tool controls are “not fully supported” this way. To see what a day of sessions cost:

curl 'https://ollama.com/api/usage?range=24h' \
  -H "Authorization: Bearer $OLLAMA_API_KEY"
Copied

Ollama retires older cloud models from time to time as newer ones arrive, and notifies the users affected first. On September 25, 2026, for example, glm-5.1 gave way to glm-5.2 and qwen3.5:397b to glm-5.3, so a script that names a cloud model is worth checking against the lifecycle page.

To make sure nothing goes to Ollama’s cloud, set OLLAMA_NO_CLOUD=1 for the server, or "disable_ollama_cloud": true in ~/.ollama/server.json, and restart. The log then shows Ollama cloud disabled: true, the launcher ignores a :cloud model with a warning, and Ollama’s web search goes too.

Ollama on another machine

Claude Code and Ollama need not share a computer: a laptop or a small server can run Claude Code against a GPU machine elsewhere. Ollama listens only on 127.0.0.1:11434 until you set OLLAMA_HOST=0.0.0.0:11434 on that machine, and its local API has no authentication. Anything that reaches the port can run your models, and a server signed in to Ollama runs cloud models on your account for any request that reaches it. Keep the port on a private network, or leave Ollama on localhost and reach it through an SSH tunnel:

ssh -N -L 11435:127.0.0.1:11434 you@gpu-box
# then, in another terminal, the variables above with ANTHROPIC_BASE_URL=http://localhost:11435
Copied

The tunnel’s local end is port 11435 so that it cannot collide with an Ollama already listening on 11434 on the Claude Code machine, which would otherwise answer in the GPU box’s place. With the Ollama command-line tool on the Claude Code machine, OLLAMA_HOST=gpu-box:11434 ollama launch claude also works, or OLLAMA_HOST=127.0.0.1:11435 through the tunnel, because the launcher builds the base URL from OLLAMA_HOST. The same endpoint questions come up for OpenClaw, in OpenClaw with Ollama.

What does not work, or works differently

Does anything still reach Anthropic?

The model requests go only to Ollama. Claude Code’s own traffic is another matter. Anthropic’s data usage page has Claude Code’s metrics off by default on Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry and Claude Platform on AWS, and a custom base URL such as Ollama’s is not among them; the launcher switches off error reports, /feedback and surveys, not metrics. And before fetching a web page, Claude Code sends the hostname, and only the hostname, to api.anthropic.com to check it against a blocklist, whatever the provider. To cut that traffic, set:

export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
Copied

and add "skipWebFetchPreflight": true to your settings file. The variable also stops auto-updates, so update Claude Code by hand (how to update Claude Code). The setting lets web fetches go to any address unchecked, which Anthropic suggests pairing with WebFetch permission rules.

Run Claude Code on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.