Kipt

Your prompts and skills, one keystroke away.

Explore

Claude Code with Ollama: run local models with ollama launch claude

Run Claude Code on Ollama local or cloud models with ollama launch claude or three environment variables. Model mapping, 64K context, limits and how to switch back.

By the Kipt team · Updated 28 October 2026

Can Claude Code run on local models with Ollama?

Yes: run ollama launch claude, pick a model, and Claude Code starts with every request going to your local Ollama server instead of Anthropic. It works because Ollama serves an Anthropic-compatible /v1/messages endpoint, added in Ollama v0.14.0 in January 2026.

Two caveats up front. First, this path is documented by Ollama, not Anthropic. Anthropic's gateway docs say it "doesn't support routing Claude Code to non-Claude models through any gateway". Second, results depend on the model: Claude Code is an agent that makes many tool calls in long contexts, and small local models with short context windows struggle with that.

This page covers local models and Ollama's own cloud models. For routing Claude Code through a company gateway such as LiteLLM, see the Claude Code proxy and LLM gateway guide.

How do you set it up with ollama launch claude?

Install Ollama, then run:

ollama launch claude

The Ollama Claude Code page lists this as the way to start. It opens a model picker and launches Claude Code. If Claude Code is not installed, the launcher asks whether to install it with Anthropic's install script. To skip the picker:

ollama launch claude --model qwen3.5

For scripts, Docker or CI, add --yes. It skips selectors, pulls the model when needed and requires --model. Anything after -- goes straight to Claude Code:

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

What the launcher does is worth knowing, because it is the reference for a manual setup. Ollama's source (cmd/launch/claude.go) sets these for the Claude Code process only:

Variable Value Why
ANTHROPIC_BASE_URL Your Ollama host, by default http://localhost:11434 Sends requests to Ollama
ANTHROPIC_AUTH_TOKEN ollama Required by the client, ignored by the local server
ANTHROPIC_API_KEY empty Stops an API key in your environment from being used instead
ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL Your model Points the opus, sonnet and haiku aliases at it
CLAUDE_CODE_SUBAGENT_MODEL Your model Subagents use it too
CLAUDE_CODE_MAX_CONTEXT_TOKENS The model's context length (cloud models) Tells Claude Code the real window

It also turns off error reporting, the feedback survey and claude.ai MCP servers, and sets CLAUDE_CODE_AUTO_MODE_SERVER=0 because, in the source's words, "Ollama does not provide Anthropic's server-side auto-mode checks."

How do you configure it by hand with environment variables?

Pull a model, then set three variables and start Claude Code. The variables come from Ollama's manual setup section, and qwen3-coder is the example model on Ollama's Anthropic compatibility page:

ollama pull qwen3-coder

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434

claude --model qwen3-coder

Ollama's manual steps stop there. A suggestion that goes beyond Ollama's docs: Claude Code also uses model aliases: /model sonnet, subagents, and background work that runs on the small fast model, such as conversation summarization. Those aliases resolve to Claude model IDs your Ollama server does not have. The launcher source maps every tier to your model, so you can do the same by hand:

export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3-coder
export CLAUDE_CODE_SUBAGENT_MODEL=qwen3-coder

Each of these is defined in Anthropic's environment variables reference; the env vars guide explains where to put them. Claude settings files can override shell variables, so if a settings.json has an env block with a base URL or key, update it there. Run /status inside Claude Code to check which endpoint and credential are active.

Which local and Ollama cloud models should you pick?

Pick a model that supports tool calling and a long context. Ollama's integration page says to "Choose a model and set a 64k+ context window" for local models and links to the tools filter on ollama.com. Ollama's own examples use qwen3.5, qwen3-coder and gemma4 locally, and gemma4:cloud, glm-5.3-flash and kimi-k2.7-code:cloud on its cloud.

Ollama cloud models run on Ollama's servers, so you can use large models without downloading them. There are two ways in:

  • Through your local server: run ollama signin, then use a cloud name such as gemma4:cloud with no separate pull.
  • Direct to ollama.com, no local install: set an Ollama API key and point Claude Code at Ollama's cloud.
ANTHROPIC_BASE_URL=https://ollama.com \
ANTHROPIC_AUTH_TOKEN="$OLLAMA_API_KEY" \
ANTHROPIC_API_KEY="" \
claude --model glm-5.3-flash

The cloud endpoint requires bearer authentication, which is why ANTHROPIC_AUTH_TOKEN is used rather than ANTHROPIC_API_KEY.

What hardware and context length do you need?

Context is the setting people miss. Ollama's context length docs give its defaults by VRAM and say coding tools need at least 64,000 tokens:

GPU memory (VRAM) Ollama's default context
Under 24 GiB 4k
24 to 48 GiB 32k
48 GiB or more 256k

So on most laptops and single-GPU desktops you must raise it. Use the context slider in the Ollama app's settings, or start the server with:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

A larger context needs more memory. Run ollama ps and check the CONTEXT column for the allocated window and PROCESSOR for whether the model fits on the GPU; Ollama recommends avoiding offload to CPU. Cloud models are set to their maximum context by default. Supported GPUs are listed on Ollama's hardware support page.

A second suggestion, also not a step in Ollama's docs: tell Claude Code the same number. The launcher only sets it for cloud models. The reasoning: for a model ID it does not recognize, Claude Code assumes a 200K window and auto-compacts at that point, per the model configuration docs. With a 64K local model, the conversation can fill the model's window before Claude Code compacts. To set the real size:

export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000

For IDs that do not start with claude-, the docs say this variable applies directly. The context window guide explains compaction in more detail.

What stops working when you leave Anthropic's models?

Some Claude Code features depend on Anthropic's API, and Ollama implements a subset of it. From Ollama's Anthropic compatibility page and Anthropic's docs:

Area What happens
Prompt caching Not supported (cache_control blocks are not honored)
Token counting endpoint Not supported; Ollama's token counts are approximations
Forcing a tool (tool_choice) Not supported
PDFs and URL images PDFs not supported; images only as base64
Hosted web search Not fully supported. Ollama offers its own web search API with an Ollama account
Extended thinking budgets budget_tokens accepted but not enforced
Remote Control Disabled when ANTHROPIC_BASE_URL points at a host other than api.anthropic.com (since v2.1.196)
Flag-gated features With ANTHROPIC_AUTH_TOKEN, no API key and a non-Anthropic base URL, Claude Code cannot fetch feature flags, so some newer features may be missing

Quality is the other limit. Claude Code's prompts and tools are built for Claude models, and Anthropic does not support other models behind it. Start with a small, well-scoped task and judge the results before trusting a local model with larger work.

How do you switch back to your Claude subscription?

If you used ollama launch claude, there is nothing to undo. The launcher adds its variables only to the Claude Code process it starts, so running claude on its own uses your normal login.

If you exported the variables, clear them in that shell and remove them from your shell profile and any settings.json env block:

unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY \
  ANTHROPIC_DEFAULT_OPUS_MODEL ANTHROPIC_DEFAULT_SONNET_MODEL \
  ANTHROPIC_DEFAULT_HAIKU_MODEL CLAUDE_CODE_SUBAGENT_MODEL \
  CLAUDE_CODE_MAX_CONTEXT_TOKENS

Start Claude Code and run /status to confirm it shows your claude.ai account. While a gateway credential is active, Anthropic's docs say requests carry it "in place of a developer's claude.ai subscription login", so your plan's limits and billing apply again only once it is gone. The Claude Code pricing guide covers plans, and the models guide covers choosing between Claude models.

Do your skills and prompts still work on a local model?

Skills, CLAUDE.md and custom slash commands are plain text that Claude Code adds to the conversation, so they travel with you whichever model answers. How well a smaller model follows them is the open question, so short, specific skills tend to hold up better. Kipt keeps prompts and Agent Skills as Markdown in a private GitHub repo you own, and one npx skills add command installs every skill into Claude Code, which makes it easy to test the same skills on Claude and on a local model side by side.

Sources: Ollama: Claude Code, Ollama: Anthropic compatibility, Ollama: context length, Claude Code environment variables and Claude Code model configuration.

Questions

Can Claude Code use Ollama?

Yes. Ollama has served an Anthropic-compatible Messages API since v0.14.0, so Claude Code can talk to it directly. Run ollama launch claude, or set ANTHROPIC_BASE_URL to http://localhost:11434, ANTHROPIC_AUTH_TOKEN to ollama and ANTHROPIC_API_KEY to an empty string, then start claude with --model and a model you have pulled.

What context length does Claude Code need on Ollama?

Ollama's docs say coding tools should have at least 64,000 tokens of context. Ollama's default depends on VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB and 256k at 48 GiB or more, so most machines need OLLAMA_CONTEXT_LENGTH=64000 or the app's context slider raised.

Does Anthropic support Claude Code with Ollama models?

No. Anthropic's gateway docs say it does not support routing Claude Code to non-Claude models through any gateway. The setup is documented by Ollama, and some Claude Code features depend on Anthropic's API, so expect gaps.

Do I need a Claude subscription to use Claude Code with Ollama?

You need Claude Code installed, but requests to Ollama do not use your claude.ai login. When a gateway token such as ANTHROPIC_AUTH_TOKEN is active, Claude Code sends that credential instead of your subscription, and your plan's usage limits do not apply to those requests.

How do I switch Claude Code back to Claude after using Ollama?

If you used ollama launch claude, just run claude on its own: the launcher only sets its variables for the Claude Code process it starts. If you exported the variables yourself, unset ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY plus any model variables, remove them from settings files, and run /status to confirm.

More in Claude Code

All guides

Keep your prompts and skills in one place, in your own GitHub. Install every skill with one command.

Get started

Kipt is an independent product, not affiliated with or endorsed by Anthropic, OpenAI, Cursor or GitHub. Claude, ChatGPT, Codex, Cursor and GitHub are trademarks of their owners.