# 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.

Updated Nov 19, 2026 · By Ari Vale

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: https://docs.vast.ai/guides/reference/referral-program?ref_id=623346).

## The short answer

To use Ollama with Claude Code, install Ollama (v0.15.0 or later) and run `ollama launch claude`. It picks a model, configures Claude Code and starts a session. To set it up by hand, set ANTHROPIC_AUTH_TOKEN=ollama, ANTHROPIC_API_KEY="" and ANTHROPIC_BASE_URL=http://localhost:11434, then run `claude --model <model>`. Before you start, raise Ollama's context to 64k (`OLLAMA_CONTEXT_LENGTH=64000 ollama serve`). The default is 4k on GPUs under 24 GiB, and Claude Code will lose track of your repo. (Ollama docs, re-checked Nov 14, 2026.)

- **Fastest:** `ollama launch claude`
- **Manual:** 3 environment variables, then `claude --model <model>`
- **Must-do:** set the context to 64k, then check `ollama ps`
- **Not supported by Ollama's Anthropic API:** tool_choice, token counting, hosted web search

## The fast way: `ollama launch claude`

```shell
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](https://docs.ollama.com/api/anthropic-compatibility), 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](https://aliteq.com/run-coding-agents-on-local-models-ollama).

> **Updated November 14, 2026**
>
> Written on Ollama v0.34.4 (Sep 23, 2026) from Ollama's Claude Code page, accessed Sep 25, 2026. Re-checked November 14, 2026 against v0.40.16 (November 9): the commands and the 64k advice are unchanged; Ollama's compatibility page now also lists prompt caching, PDF documents, citations and the Batches API as not supported, added below. We quote the docs; we haven't benchmarked Claude Code on local models ourselves.

![Flat illustration of a developer in an armchair typing on a laptop, with a small home server plugged in beside a plant](https://media.aliteq.com/media/software/how-to-use-ollama-with-claude-code-2026.jpg)
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](https://docs.ollama.com/context-length) lists the defaults by [VRAM](https://aliteq.com/tools/vram-calculator): 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.

```shell
# 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](https://aliteq.com/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](https://docs.ollama.com/faq). Set them there and restart Ollama.

## Step 2 (fast path): ollama launch claude

```shell
ollama launch claude
```

That's it. `ollama launch` arrived in [Ollama v0.15.0](https://github.com/ollama/ollama/releases/tag/v0.15.0). It lets you choose a model, configures Claude Code to use [Ollama](https://aliteq.com/how-to-manage-local-ai-models-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:

```shell
# 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:

```shell
# 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](https://ollama.com/search?c=tools). 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](https://aliteq.com/can-you-run-qwen3-coder-locally) 30B (19 GB download, 256K max context) and [gpt-oss 20B](https://aliteq.com/gpt-oss-20b-8gb-12gb-gpu-moe-offload) (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 about 24 GB of VRAM.

- 16GB card (16 GB): does not fit
- 24GB card (3090 / 4090) (24 GB): fits
- 32GB card (5090) (32 GB): fits

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](https://aliteq.com/cost-to-run/qwen3-coder-30b-a3b#best-gpu) and [best GPU for gpt-oss 20B](https://aliteq.com/cost-to-run/gpt-oss-20b#best-gpu). If none of your cards fit, the pillar covers [renting a 48GB card by the hour](https://aliteq.com/run-coding-agents-on-local-models-ollama).

The 24GB cards in that chart are the used [RTX 3090](https://aliteq.com/gpus/rtx-3090) and the [RTX 4090](https://aliteq.com/gpus/rtx-4090); the 32GB one is the [RTX 5090](https://aliteq.com/gpus/rtx-5090). For other coder models ranked by the card they need, see our [best local LLM for coding on a single GPU](https://aliteq.com/best-local-llm-for-coding-single-gpu).

**Your GPU too small for a 30B coder?** Card under 24GB? Rent a 24GB RTX 4090. This link opens Vast.ai with our Ollama + Open WebUI template, so Ollama is ready when the machine starts; run it with OLLAMA_KV_CACHE_TYPE=q8_0 so Qwen3-Coder 30B fits at 64k context (about 21 GiB on our engine). Shut it down when the session ends. [Rent a 24GB card by the hour](https://cloud.vast.ai/?template_id=26e7446a7d6906ee366b620c84e1e422&ref_id=623346) (Referral link: we earn a commission if you buy.) Live RTX 4090 prices on Vast.ai, from and typical: https://aliteq.com/vast-ai-pricing

## 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](https://docs.ollama.com/api/anthropic-compatibility).
- **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](https://aliteq.com/how-to-use-ollama-with-opencode), MIT, one config file) and Codex ([ollama launch codex](https://aliteq.com/how-to-use-ollama-with-codex-cli), Apache-2.0, built around gpt-oss). Disk filling up with models you tried? [Delete Ollama models](https://aliteq.com/how-to-manage-local-ai-models-ollama) with one command.

**Want the comfortable setup for a full workday?** A 32GB RTX 5090 runs Qwen3-Coder 30B at 64k context without squeezing the cache. Runpod rents it in Secure Cloud datacenters with one-click templates; point Claude Code at the pod over an SSH tunnel and stop it when the session ends. [Rent a 32GB RTX 5090 on Runpod](https://console.runpod.io/signup?ref=nuninlts) (Referral link: we earn a commission if you buy.) Live RTX 5090 prices on Runpod, from and typical: https://aliteq.com/runpod-pricing

Prefer an editor extension to a terminal agent? Our guide to a [local AI coding assistant in VS Code](https://aliteq.com/local-ai-coding-assistant-vs-code) covers that route, and [Qwen3-Coder vs GitHub Copilot](https://aliteq.com/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](https://aliteq.com/run-openclaw-hermes-local-model-ollama). Live hourly prices for the cards above are on our [cloud GPU price tracker](https://aliteq.com/cloud-gpu).

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](https://aliteq.com/how-to-run-a-local-llm-on-your-pc-beginners-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](https://github.com/ollama/ollama/issues/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

**Q: How do I fix "context deadline exceeded" in Ollama?**

A: 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.

**Q: What does ollama launch claude do?**

A: 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.

**Q: How do I run Claude Code in the CLI with an Ollama model?**

A: 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.

**Q: Do I need an Anthropic account to use Claude Code with Ollama?**

A: 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.

**Q: Why does Claude Code lose track of my project with Ollama?**

A: 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`.

**Q: Which Ollama version do I need?**

A: 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.

**Q: What's the best local model for Claude Code?**

A: 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).

**Q: Can I use Ollama's cloud models with Claude Code instead?**

A: 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.

## Sources

- [Ollama docs — Claude Code integration (accessed Sep 25 and Nov 14, 2026)](https://docs.ollama.com/integrations/claude-code)
- [Ollama docs — Anthropic compatibility, Not supported / Partial support tables (accessed Sep 25 and Nov 14, 2026)](https://docs.ollama.com/api/anthropic-compatibility)
- [Ollama docs — CLI Reference: Launch integrations (read Nov 14, 2026)](https://docs.ollama.com/cli)
- [Ollama release v0.40.16, Nov 9, 2026 (read Nov 14, 2026)](https://github.com/ollama/ollama/releases/tag/v0.40.16)
- [Ollama docs — Context length (accessed Sep 25, 2026)](https://docs.ollama.com/context-length)
- [Ollama docs — FAQ (accessed Sep 25, 2026)](https://docs.ollama.com/faq)
- [Ollama release notes v0.14.0 / v0.15.0](https://github.com/ollama/ollama/releases)
- [Ollama library — qwen3-coder / gpt-oss tags](https://ollama.com/library/qwen3-coder/tags)
- [Claude Code docs](https://code.claude.com/docs/en/overview)
- [Higgsfield plans and pricing (official page, checked Dec 2, 2026)](https://higgsfield.ai/pricing?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-claude-code--md)
- [Illustration generated with Higgsfield](https://higgsfield.ai?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-claude-code--md)
- [Ollama docs, Troubleshooting: logs and OLLAMA_DEBUG (official docs, read Nov 19, 2026)](https://docs.ollama.com/troubleshooting)
- [Ollama GitHub issue #17484, Error: context deadline exceeded (read Nov 19, 2026)](https://github.com/ollama/ollama/issues/17484)

---

Canonical: https://aliteq.com/how-to-use-ollama-with-claude-code

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