SysArt
Book a briefing
SysArt

Private LLMs and RAG

Ollama Claude Code Setup: Local Models, Limits and Team Controls

Run Claude Code with Ollama or another local model server: setup steps, model and context choices, what you lose, traffic that still leaves and team controls.

Last reviewed by SysArt Delivery Team9 min readHow we review

In short

Claude Code can run on a local model because Ollama, vLLM, LM Studio and llama.cpp now serve Anthropic's Messages API. Point ANTHROPIC_BASE_URL at the server, or run ollama launch claude, and pick a model with tool calling and at least 64K tokens of context. Anthropic does not support non-Claude models, and some telemetry needs switching off.

Key takeaways

  • Ollama added an Anthropic-compatible /v1/messages endpoint in v0.14.0 (January 2026) and the ollama launch command in v0.15.0, so Claude Code can talk to a local model through ANTHROPIC_BASE_URL.
  • Anthropic's documentation says it does not support routing Claude Code to non-Claude models through any gateway, so this set-up works technically but sits outside vendor support.
  • Choose a model with tool calling and raise the context window: Ollama defaults to 4K tokens below 24 GiB of VRAM and recommends at least 64,000 for coding agents, while Claude Code assumes 1M tokens for model names it does not recognise.
  • A local model keeps prompts and code on your hardware, but Claude Code still sends telemetry, survey ratings and WebFetch domain checks unless you switch them off with the documented variables and settings.
  • For a team, serve the model from a shared GPU server behind an authenticating gateway, pin the endpoint with managed settings and allowedProviders, sandbox the agent and keep code review.
A laptop keyboard in the dark beside a screen filled with green binary digits

Can Claude Code run on local models with Ollama?

Yes, technically. Claude Code speaks Anthropic’s Messages API, and Ollama now serves a compatible endpoint, so Claude Code can send its requests to an open-weight model on your own machine or server.

Claude Code is Anthropic’s coding agent: it reads a repository, edits files and runs commands in a loop driven by a language model. It reads the ANTHROPIC_BASE_URL environment variable to decide where those requests go. Ollama, a popular local model runner, added support for Anthropic’s /v1/messages endpoint in version 0.14.0, released on 10 January 2026. Version 0.15.0, on 21 January 2026, added ollama launch, which starts Claude Code, Codex, OpenCode or Droid already connected to Ollama. As of 17 November 2026, the latest stable Ollama release is v0.40.16.

There is an important caveat. Anthropic’s gateway documentation says it does not support routing Claude Code to non-Claude models through any gateway. A local model behind Ollama is exactly that. The combination works, but neither vendor promises that every Claude Code feature behaves as it does with Claude, and Claude Code adds capabilities with each release that a compatibility layer may not follow.

How do you set up Claude Code with Ollama?

Run ollama launch claude, or set three environment variables and start Claude Code with a local model name. Either way, make sure the model supports tool calling and has a large enough context window first.

The quick path:

  1. Install Ollama and Claude Code, then pull a model that supports tools.
  2. Raise Ollama’s context window before you start the server (see the model section below).
  3. Run ollama launch claude. For scripts or continuous integration, add --yes and --model, and put Claude Code’s own arguments after --.

The manual path sets what ollama launch sets for you:

export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model <local-model>

ANTHROPIC_AUTH_TOKEN fills the Authorization header; the local Ollama server does not check it. Settings files override shell variables, so if requests still go to Anthropic, check the env block in your Claude Code settings. Run /status inside Claude Code to confirm the base URL it is using.

Watch the model name. Ollama’s documentation shows examples ending in :cloud. Those models run on Ollama’s servers, not on your hardware, and a direct cloud connection to ollama.com needs an Ollama API key. If the reason for this set-up is to keep code in-house, use local models only and block the cloud endpoint at the network edge.

Which other local servers work with Claude Code: vLLM, LM Studio or llama.cpp?

As of November 2026, all three document an Anthropic-compatible endpoint, so the same ANTHROPIC_BASE_URL pattern applies. The difference lies in what each is built for.

  • vLLM lists the Anthropic Messages API (/v1/messages and /v1/messages/count_tokens) among its server APIs. It rejects the max_tokens=0 requests some clients send to warm a prompt cache. Its tool-calling guide requires --enable-auto-tool-choice and a --tool-call-parser that matches the model. vLLM is the engine built for many concurrent users on a GPU server.
  • LM Studio documents /v1/messages and shows Claude Code with ANTHROPIC_BASE_URL=http://localhost:1234. When you turn on its authentication option, it checks the x-api-key or bearer header.
  • llama.cpp: its llama-server added the Messages API in January 2026, including streaming, tool use and token counting, according to the project’s announcement. It translates these requests into its existing OpenAI-compatible pipeline.

Each engine has different strengths in throughput, quantisation and hardware support. Our comparison of vLLM, Ollama, llama.cpp and SGLang covers which suits which workload. A laptop runner is fine for evaluation; a team needs a serving engine.

Which local models work with Claude Code, and how much context do they need?

Use an open-weight model with reliable tool calling and at least 64,000 tokens of context, then tell Claude Code the real window. Without tool calling, the agent cannot read files, edit code or run commands.

Ollama’s Claude Code page advises a local model that supports tools, with a context window of 64K tokens or more. The llama.cpp announcement names agentic coding models such as Qwen3 Coder, Kimi K2, MiniMax M2 and Nemotron. For a current family you can host yourself, see our guide to self-hosting Qwen 3.8. Read each model’s licence before production use.

Two context settings matter:

  • On the server. Ollama sets its default context from available GPU memory: 4K tokens below 24 GiB of VRAM, 32K from 24 to 48 GiB and 256K at 48 GiB or more. It recommends at least 64,000 tokens for coding agents. Set it explicitly, for example OLLAMA_CONTEXT_LENGTH=64000 ollama serve, or use the slider in the Ollama app.
  • In Claude Code. Since v2.1.323, Claude Code assumes a 1M-token window for a model ID it does not recognise, and it compacts the conversation against that assumed size. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the window your server really provides, so compaction happens before requests overflow.

Longer contexts cost GPU memory for the key-value cache of every concurrent session. Estimate it with our LLM GPU sizing calculator before you buy hardware.

What do you lose when Claude Code runs on a local model?

You lose Anthropic’s support, some API features and the features that need Anthropic’s servers. How well a given open-weight model handles Claude Code’s agentic loop is something you have to measure: neither Anthropic nor Ollama documents parity with Claude.

AreaWhat happens with a local Anthropic-compatible serverWhat to do
Vendor supportAnthropic does not support non-Claude models in Claude CodeTreat it as an internal platform you own and test
API featuresOllama does not support tool_choice, token counting, prompt caching, batches, citations or PDF document blocks; images must be base64Expect approximate /context counts; Claude Code falls back to a character-based estimate
Request fieldsFor unrecognised model IDs, Claude Code sends fields current Claude models accept, such as effort and context managementIf the server returns 400 errors, set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
Background tasksBehind a custom base URL, background tasks use the main model unless ANTHROPIC_DEFAULT_HAIKU_MODEL pins anotherPin a smaller local model if latency matters
Anthropic-hosted featuresRemote Control turns off when the base URL is not Anthropic’s, and cloud sessions and Claude Code in Slack are not part of a gateway deploymentDistribute managed settings as files and keep work local
Prompt contentClaude Code adds a short attribution block to the system prompt, which non-Anthropic upstreams receive as part of the promptLeave it, or ask your gateway team how it affects caching

Web search is a hosted capability. Ollama’s compatibility page does not list it, and its Claude Code page says hosted web search is not fully supported even on Ollama’s cloud. Plan for local tools and explicit WebFetch rules instead.

Does any data still leave the machine?

Prompts and code go only to the server named in ANTHROPIC_BASE_URL. Some background traffic can still go to Anthropic and third parties, so switch it off and verify at the network edge.

What Claude Code’s data-usage page lists:

  • Usage metrics (latency, reliability, usage patterns; no code, prompts or file paths): opt out with DISABLE_TELEMETRY=1.
  • Error reports: on only for Pro, Max and Ultra sign-ins connected directly to the Claude API; DISABLE_ERROR_REPORTING=1 turns them off regardless.
  • Session quality surveys: run on every provider; CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY=1 disables them. A follow-up asking to upload the session transcript sends it only if the user chooses Yes.
  • WebFetch domain check: before fetching a URL, Claude Code sends the hostname to api.anthropic.com, whichever model provider you use. Turn it off with skipWebFetchPreflight: true in settings and restrict domains with WebFetch permission rules.
  • Feedback reports: behind a gateway without Anthropic credentials, /feedback writes a local archive instead of uploading.

CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns off most of this in one setting, including auto-updates, telemetry, error reporting and surveys. It does not cover the WebFetch check or the automatic installation of the official plugin marketplace, which has its own variable, CLAUDE_CODE_DISABLE_OFFICIAL_MARKETPLACE_AUTOINSTALL. With auto-updates off, distribute new versions yourself.

Two local points matter too. Claude Code stores session transcripts in plaintext under ~/.claude/projects/ for 30 days by default (cleanupPeriodDays changes this), and they can hold code, secrets and personal data. MCP servers, plugins and shell commands the agent runs can reach the network on their own, so an outbound allowlist is the only reliable check.

How do you run Claude Code on local models for a whole team?

Do not ask every developer to run a model on a laptop. Serve one or two approved models from a shared GPU server, put an authenticating gateway in front, and distribute the configuration centrally.

  1. Serve centrally. Run a serving engine such as vLLM on GPU servers you control, sized for concurrent long-context sessions.
  2. Authenticate and log. Ollama’s local server does not validate API keys, so never expose it directly. Put an AI gateway in front that issues a credential per developer, enforces rate limits and logs requests. Developers then hold a gateway credential, and an apiKeyHelper script can fetch rotating credentials from a vault.
  3. Pin the endpoint. Put ANTHROPIC_BASE_URL in the env block of a managed settings file and set allowedProviders to ["customEndpoint"]. From v2.1.285, Claude Code then refuses sessions pointed anywhere else, including Anthropic directly. An availableModels allowlist in managed settings limits which models developers can choose.
  4. Switch off background traffic with the variables and settings above, and allow outbound traffic only to the gateway and internal package mirrors.
  5. Contain execution. Enforce Claude Code’s sandbox through managed settings, deny risky commands and give the agent only the credentials a task needs. Our AI security work covers the threat model, including prompt injection through repository content.
  6. Review and measure. Keep normal code review, export OpenTelemetry metrics, and repeat your model evaluation before changing the model, the engine or the Claude Code version.

If you would rather use an agent designed for any model, our guide to OpenCode with local models covers that route.

What licensing and EU rules apply?

Check two sets of terms and your own data obligations. This is general information, not legal advice; the answer depends on your use case and role.

Licences. Claude Code is not open source: its repository states that use is subject to Anthropic’s Commercial Terms of Service. Running it against a local model does not change that, so have legal review the terms for this use. The open-weight model carries its own licence, which may restrict commercial use or require attribution.

GDPR. Repositories, tickets and logs often contain personal data, such as commit authors’ email addresses or customer records in test fixtures. Keeping inference on your own servers removes an external processor from the model step, but the GDPR still applies to what you process, store and log, including local transcripts and gateway logs. It does not make a deployment compliant by itself.

EU AI Act. The AI literacy duty in Article 4, as amended by the Digital Omnibus on AI, requires providers and deployers to take measures to support the AI literacy of staff who use AI systems on their behalf, without a mandated level. It has applied since 2 February 2025, and national market surveillance authorities supervise it from 2 August 2026. Our overview of AI coding agents in the enterprise covers the wider EU picture, including NIS2 and DORA.

How SysArt helps

SysArt designs and builds private platforms for AI coding agents on infrastructure you control: model serving on your GPUs, an authenticating gateway, managed Claude Code or OpenCode configuration, network controls, evaluation and the governance records around them. We implement on your premises, in your sovereign cloud or in a dedicated EU environment, then hand over with runbooks or operate the platform. See how we deliver on-premises AI.

Featured image by Moritz Erken on Unsplash.

Frequently asked questions

Can Claude Code use Ollama?

Yes. Since version 0.14.0, released in January 2026, Ollama serves a subset of Anthropic's Messages API at /v1/messages. Claude Code reads ANTHROPIC_BASE_URL, so pointing it at http://localhost:11434 with a placeholder token sends its requests to a model running in Ollama. Anthropic does not support non-Claude models in Claude Code, so test the result on your own tasks before relying on it.

What does ollama launch claude do?

It starts Claude Code already connected to Ollama, without setting environment variables yourself. The command arrived in Ollama v0.15.0 and also launches Codex, OpenCode and Droid. For scripts and CI, add --yes and --model, and pass Claude Code's own arguments after a double dash. Models ending in :cloud run on Ollama's servers rather than your machine, so choose a local model when code must stay in-house.

Is Claude Code free with a local model?

There are no per-token fees when the model runs on your own hardware, but Claude Code itself is not open source. Its repository states that use is subject to Anthropic's Commercial Terms of Service. You still pay for GPUs, power and operations, and the model's own licence applies. Ask your legal team to check both sets of terms for your intended use before a wider rollout.

Which local model is best for Claude Code?

No vendor publishes a ranking for this set-up. Ollama advises a local model that supports tool calling, with a context window of 64,000 tokens or more. The llama.cpp team suggests agentic coding models such as Qwen3 Coder, Kimi K2, MiniMax M2 or Nemotron. Compare two or three candidates on closed tickets from your own repositories and record failed tool calls as well as test results.

Does Claude Code send data to Anthropic when using a local model?

Prompts and code go only to the server in ANTHROPIC_BASE_URL. Other traffic can still leave: usage metrics, session survey ratings, update checks and a WebFetch check that sends hostnames to api.anthropic.com. Set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1, set skipWebFetchPreflight to true in settings and restrict outbound network access to confirm nothing else leaves.

Can Claude Code connect to vLLM or LM Studio?

Yes, as of November 2026 both document an Anthropic-compatible endpoint. vLLM lists /v1/messages and /v1/messages/count_tokens among its server APIs, and LM Studio documents /v1/messages with ANTHROPIC_BASE_URL set to its local server, port 1234 in its examples. llama.cpp's llama-server also added the Messages API in January 2026. For vLLM, enable automatic tool calling with the parser that matches your model.

Why does Claude Code compact too late or fail with long prompts on a local model?

Claude Code assumes a 1M-token context window for model names it does not recognise, while a local server may allow only 32K or 64K tokens. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the window your server really provides, and raise the server's context length, for example with OLLAMA_CONTEXT_LENGTH, so compaction happens before requests overflow.

Related insights

Plan your private AI with people who build it

Book a briefing. We look at your use case, data and constraints, and you leave with the deployment options and governance steps that fit.