aliteq.

Type to search every guide, tool and GPU page.

How to use Ollama with Claude Code, with ollama launch claude and local models

One command, or three environment variables. Plus the 64k context setting Ollama's defaults don't give you, the VRAM that costs, and what Ollama's Anthropic API doesn't support.

Ari ValeLinks and sources checked Updated Published 6 min read
Flat illustration of a developer in an armchair typing on a laptop, with a small home server plugged in beside a plant

This page has referral links: we earn a commission if you buy, at no cost to you.

Our Vast referral code: 623346 (link: https://cloud.vast.ai/?ref_id=623346). New users get no bonus from it; we earn 3% of what referred users spend (Vast's referral program docs).

Our Runpod referral code: nuninlts (link: https://console.runpod.io/signup?ref=nuninlts). A new account that signs up with Google through it and loads $10 gets a one-time bonus credit, a fixed $5 for European customers and a random $5 to $500 elsewhere (Runpod says most get $5), valid 90 days; we earn 3% of Pod and 5% of Serverless spend for the first 6 months (Runpod's referral docs).

Share
Share on X

The fast way: `ollama launch claude`

ollama launch claude                       # pick a model, configure Claude Code, start a session
ollama launch claude --model qwen3-coder:30b   # skip the picker with a model you've pulled

Note the app name is claude, not claude-code. Per Ollama's CLI reference (read November 14, 2026), ollama launch configures and starts an external app with an Ollama model; it supports Claude Code, OpenCode, Codex, VS Code and Droid. Before you run it, give the model 64k of context (step 1 below), or Claude Code loses track of your repository.

Claude Code is Anthropic's terminal agent. It reads a codebase, edits files and runs commands. It normally talks to Anthropic's API, but since Ollama v0.14.0 added an Anthropic-compatible Messages API, you can point it at a model on your own machine instead. This is the setup, straight from Ollama's docs, with the one setting that trips most people up. If you're still choosing between agents, start with our Claude Code vs Codex vs OpenCode comparison.

Flat illustration of a developer in an armchair typing on a laptop, with a small home server plugged in beside a plant
Claude Code in your terminal, talking to a model on the box next to you. · Illustration generated with Higgsfield

Step 1: set the context length first

Do this before anything else. Ollama's Claude Code page says: "For larger repositories, set the context length to 64k or higher." Its context-length page lists the defaults by VRAM: under 24 GiB you get 4k, 24–48 GiB gets 32k, 48 GiB and up gets 256k. Claude Code's system prompt and tool definitions take a big bite of that before your code even arrives.

# Ollama v0.34.4 docs — context-length
OLLAMA_CONTEXT_LENGTH=64000 ollama serve

# optional: halve the KV-cache memory (Ollama FAQ)
OLLAMA_KV_CACHE_TYPE=q8_0 OLLAMA_CONTEXT_LENGTH=64000 ollama serve

If you use the Ollama desktop app instead of ollama serve, the docs say to change the context slider in the app's settings. On Windows, Ollama reads your user and system environment variables, per the FAQ. Set them there and restart Ollama.

Step 2 (fast path): ollama launch claude

ollama launch claude

That's it. ollama launch arrived in Ollama v0.15.0. It lets you choose a model, configures Claude Code to use Ollama and starts the session. For scripts or CI, the docs show a non-interactive form. --yes skips the prompts and pulls the model if needed, but requires --model, and anything after -- goes straight to Claude Code:

# from Ollama's docs (Sep 25, 2026); swap in a local model name to stay offline
ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"

Note that the docs' example uses a :cloud model, which runs on Ollama's servers, not your GPU. If staying local is the point, use a model you've pulled, like qwen3-coder:30b.

Step 2 (manual path): three environment variables

If you'd rather wire it yourself, for example to keep your existing Claude Code install, the docs give the install commands and three variables:

# 1. Install Claude Code (from Ollama's docs)
# macOS / Linux
curl -fsSL https://claude.ai/install.sh | bash
# Windows (PowerShell)
irm https://claude.ai/install.ps1 | iex

# 2. Point it at Ollama
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434

# 3. Run it with a local model
claude --model qwen3-coder:30b

One gotcha the docs call out: Claude's own settings can override shell variables. If Claude Code still seems to hit Anthropic, check your Claude settings for a base URL or credentials and run /status inside Claude Code to see where it's connected.

Which local model, and will it fit?

Ollama's docs send you to its tools-capable models list. The model has to support tool calling, or Claude Code can't edit files or run commands. The two we'd shortlist for coding are Qwen3-Coder 30B (19 GB download, 256K max context) and gpt-oss 20B (14 GB, 128K), per the Ollama library. At the 64k context Claude Code wants, our VRAM engine gives:

Qwen3-Coder 30B at 64k context needs ≈24.0 GiB
Qwen3-Coder 30B-A3B · Q4_K_M · 64k context · fp16 KV needs ≈24 GB
16GB card16 GBover 8 GB
24GB card (3090 / 4090)24 GBfits
32GB card (5090)32 GBfits
Our engine. With OLLAMA_KV_CACHE_TYPE=q8_0 it's about 21.0 GiB. gpt-oss 20B at 64k needs about 15.6 GiB (14.1 GiB with q8_0).

Full tables by GPU are on best GPU for Qwen3-Coder and best GPU for gpt-oss 20B. If none of your cards fit, the pillar covers renting a 48GB card by the hour.

The 24GB cards in that chart are the used RTX 3090 and the RTX 4090; the 32GB one is the RTX 5090. For other coder models ranked by the card they need, see our best local LLM for coding on a single GPU.

What doesn't work the same as Anthropic's API

  • tool_choice, which forces or disables specific tool use: listed as not supported on Ollama's Anthropic compatibility page.
  • Token counting (/v1/messages/count_tokens): not supported.
  • Hosted web search: not fully supported. Ollama offers its own web search you can wire in instead.
  • Images by URL: not supported. Base64 images work.
  • Extended thinking: basic support; budget_tokens is accepted but not enforced.
  • Prompt caching (cache_control), PDF documents, citations and the Batches API: not supported, per the same page (read November 14, 2026).

Most everyday Claude Code work (reading files, editing, running commands) doesn't depend on those. But if a plugin or workflow of yours relies on forced tool choice, expect it to behave differently. That's the honest trade: the workflow comes with you offline, not every API feature does.

Pros

  • + One command (`ollama launch claude`) and you're running
  • + Your code stays on your machine with a local model
  • + Same Claude Code workflow and commands you already know

Cons

  • − Needs 64k context, which is 24GB-class VRAM for a 30B coder
  • − tool_choice, token counting and hosted web search not fully supported
  • − Claude Code itself is proprietary (Anthropic Commercial Terms)

Weighing the alternatives? The same one-command setup exists for OpenCode (ollama launch opencode, MIT, one config file) and Codex (ollama launch codex, Apache-2.0, built around gpt-oss). Disk filling up with models you tried? Delete Ollama models with one command.

Prefer an editor extension to a terminal agent? Our guide to a local AI coding assistant in VS Code covers that route, and Qwen3-Coder vs GitHub Copilot compares a local coder with the paid default. For other open agents built on local models, see OpenClaw vs Hermes Agent. Live hourly prices for the cards above are on our cloud GPU price tracker.

This guide is part of our how to run a local AI model on your own PC in 2026 — a genuinely simple beginner's guide guide. Related guides: .

"Error: context deadline exceeded" with ollama launch claude

This error means a request to Ollama ran out of time before it finished. Ollama's docs have no page for it. In Ollama's GitHub issues (for example #17484) it comes up in two moments: while a model is still downloading, and while a big model is loading into memory. Try these in order:

  • Download the model on its own first. Run ollama pull <model> and let it finish before ollama launch claude. If the pull stalls, run the same command again.
  • On a work or school network with a proxy, set HTTPS_PROXY for the Ollama server, not HTTP_PROXY, and install the proxy's certificate as a system certificate. Ollama's FAQ says both.
  • For a big model on a slow first load, run ollama run <model> "hi" once, check ollama ps shows it loaded, then launch.
  • If it still fails, set OLLAMA_DEBUG=1, restart Ollama and read server.log. On Windows it's in %LOCALAPPDATA%\Ollama, per Ollama's troubleshooting page.

Quick answers

How do I fix "context deadline exceeded" in Ollama?
It means a request timed out, usually while a model is downloading or loading. Run ollama pull <model> on its own first, set HTTPS_PROXY (not HTTP_PROXY) if you are behind a proxy, load a big model once with ollama run before ollama launch claude, and check server.log with OLLAMA_DEBUG=1 if it keeps failing.
What does ollama launch claude do?
It lets you pick an Ollama model, points Claude Code at Ollama's Anthropic-compatible API and starts a session. Add --model to skip the picker. For scripts, --yes skips the prompts and pulls the model if needed, and anything after -- goes to Claude Code.
How do I run Claude Code in the CLI with an Ollama model?
Either run ollama launch claude, or set ANTHROPIC_AUTH_TOKEN=ollama, ANTHROPIC_API_KEY="" and ANTHROPIC_BASE_URL=http://localhost:11434, then run claude --model followed by a model you have pulled, such as qwen3-coder:30b.
Do I need an Anthropic account to use Claude Code with Ollama?
Ollama's manual setup sets ANTHROPIC_API_KEY to an empty string and ANTHROPIC_AUTH_TOKEN to "ollama", so requests go to your local Ollama server, not Anthropic's API. Claude Code is still Anthropic's software, used under Anthropic's Commercial Terms.
Why does Claude Code lose track of my project with Ollama?
Context length. Ollama defaults to 4k tokens on GPUs under 24 GiB and 32k on 24–48 GiB, and its docs recommend 64k or more for Claude Code. Start Ollama with OLLAMA_CONTEXT_LENGTH=64000 and check the CONTEXT column in ollama ps.
Which Ollama version do I need?
Anthropic API compatibility arrived in Ollama v0.14.0 (January 2026), and ollama launch in v0.15.0. The newest release on Nov 14, 2026 was v0.40.16 (Nov 9), and the commands on this page match its docs.
What's the best local model for Claude Code?
It needs tool calling and a long context. Qwen3-Coder 30B is the common pick on a 24GB GPU (about 24.0 GiB at 64k on our engine, 21.0 GiB with an 8-bit KV cache). gpt-oss 20B fits 16GB cards (about 15.6 GiB, or 14.1 GiB with q8_0).
Can I use Ollama's cloud models with Claude Code instead?
Yes. Ollama's docs show setting ANTHROPIC_BASE_URL=https://ollama.com with your OLLAMA_API_KEY as the auth token, with no local install. That runs the model on Ollama's servers, so your code leaves your machine.

Found this useful? Share it

Share
Share on X

Founder & chief editor

Ari Vale

Founder and chief editor of Aliteq (a PC hardware shop from 2019, now a US-based publication). Ari Vale is my pen name: I stay anonymous, the work doesn't. I research the questions people actually ask, check every price and limit against the vendor's own pages, and write down what I'd choose and why. I use the cloud-GPU and AI-video services I write about.

Work out the hardware

GPUs in this article

Specs, the AI models each one runs, and where to buy or rent it.

Email list

Local AI, only the changes that matter

A new model your GPU can actually run, a GPU price move worth acting on, or a fix that saves you an evening. Nothing in between.

Written and sent by hand. One-click unsubscribe in every email. Emails may contain referral links.

Keep reading