Claude Code locally: what actually works with a local model

Claude Code can run on a model that lives on your own computer. We cover the setup, how it differs from cloud models, and when you should count dollars instead of hardware.

6 min · · агенты · сравнение

The query "claude code locally" usually means one of two things: running the agent itself on your own computer, or making it work on a model that also runs on your machine with no cloud involved. Claude Code always does the first. The second is possible, with caveats. Below we cover how to connect it, what the model and hardware must provide, and when a cheap cloud model over an API is the more practical choice.

What "Claude Code locally" means

Claude Code is a console program. It reads project files, runs commands and sends requests to a model over an Anthropic-compatible API. The ANTHROPIC_BASE_URL variable decides where those requests go. That gives three setups:

  1. The default cloud model. The agent is local, the model is remote.
  2. A local server with an Anthropic-compatible API. Both the agent and the model run on your machine.
  3. A gateway with a set of models. The agent is local, and you pick a model from the provider's list.

About "claude opus locally": Claude models (Opus, Sonnet) cannot be downloaded to your computer, because their weights are not published. You can only run other models locally and use Claude Code as the shell around them.

Connecting a local model through Ollama

Ollama has an Anthropic-compatible API, and its documentation mentions Claude Code directly. The shortest path, according to the Ollama docs:

bash
ollama launch claude

The command configures the connection and opens a model picker. For scripts and CI the docs describe a non-interactive form: the --yes flag skips the picker, requires --model, and everything after -- is passed to Claude Code:

bash
ollama launch claude --model <model> --yes -- -p "how does this repository work?"

If you prefer manual setup, two environment variables are enough:

bash
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model <model>

The ollama token is a placeholder: the local server requires it but does not check it. Take the model name from your Ollama catalog; the docs examples include qwen3-coder, for instance. Messages, streaming and function calling are supported, while tool-choice controls and Anthropic's hosted web search are only partly supported. Check the Anthropic compatibility page in the Ollama docs for current limits.

What the model and hardware need to provide

An agent needs more than answers to questions. The model must offer:

  • Tool calling. Claude Code works by reading files, editing them and running commands. A model without solid tool calling will describe actions instead of performing them.
  • A long context. Ollama advises setting the context to 64k or more for larger repositories. By default, per the Ollama docs, the window depends on VRAM: 4k tokens below 24 GiB, 32k at 24-48 GiB and 256k from 48 GiB. For an agent 4k is nearly useless: Claude Code's system prompt and tool descriptions alone take a large part of it.
  • Memory for that context. The larger the window, the more VRAM or RAM goes to the attention cache. Exact numbers depend on the model and quantization, so estimate on the concrete model rather than from generic tables.

When memory is short, the model either will not start with the window you need or will be very slow. That is the most common source of disappointment with "local Claude Code".

How a local model differs from a cloud one

It is easier to compare what can be measured. For gateway models we have price, context and the Artificial Analysis intelligence index. For your local model, find the index yourself and do not compare it by eye with the numbers below: quality on your project is only established by running your own tasks.

Model (id)Input / output, $ per 1MContextStrength index
claude-opus-5-50.8 / 41M58
claude-sonnet-5-50.4 / 21M48
glm-5.3-flash0.04 / 0.04128K42
deepseek-v4.1-flash0.013 / 0.0381M39

Prices as of October 18, 2026. The current list and prices: GET https://api.zukko.pro/v1/models or the "Models" page in your account.

What is cheaper: hardware or tokens

A local model charges nothing per token, but the hardware has a price. Take a sample agent session: 3M input tokens and 0.3M output tokens, cache ignored. Formula: input × input price + output × output price.

  • glm-5.3-flash: 3 × 0.04 + 0.3 × 0.04 = 0.12 + 0.012 = $0.132.
  • deepseek-v4.1-flash: 3 × 0.013 + 0.3 × 0.038 = 0.039 + 0.0114 = $0.0504.
  • claude-sonnet-5-5: 3 × 0.4 + 0.3 × 2 = 1.2 + 0.6 = $1.80.
  • claude-opus-5-5: 3 × 0.8 + 0.3 × 4 = 2.4 + 1.2 = $3.60.

Now take a hypothetical figure: say the machine for a local model costs $2000. That equals 2000 / 0.0504 ≈ 39,700 sessions on deepseek-v4.1-flash, or 2000 / 1.80 ≈ 1,100 sessions on claude-sonnet-5-5. Plug in your own hardware price, and add electricity and your own time separately. A real cloud bill depends on caching: in agent sessions most of the input is read from cache and priced differently, so treat these numbers as an order of magnitude, not a forecast.

When a local model makes sense

  • Company rules forbid sending code outside, and there is no approved provider.
  • You work offline or in a closed network.
  • A model already sits on your server for other tasks and the hardware is idle.
  • You are studying how the agent loop works and want a free sandbox.

When a cloud model is the better choice

  • You need a large model that will not fit in your memory.
  • The repository is big and the local context window is small.
  • Tasks are occasional: the hardware would sit idle, and tokens pay off sooner.
  • You want to switch models by task: a cheap one for routine work, a strong one for hard problems.

Connecting Claude Code to the gateway instead

If you decide to try a cloud model, setup takes five minutes. The Anthropic format is used, ANTHROPIC_BASE_URL has no /v1, and the key goes into ANTHROPIC_AUTH_TOKEN. The ~/.claude/settings.json file:

bash
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.zukko.pro",
    "ANTHROPIC_AUTH_TOKEN": "fetch_your_key",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5"
  }
}

To experiment with the cheapest model, run ANTHROPIC_MODEL=glm-5.3-flash claude once and see how it handles your tasks. Note that its context is 128K, not 1M as with Claude models. A detailed walkthrough is in the Claude Code docs, and choosing a model by price and index is covered in which model to pick for Claude Code. For a broader look at local versus cloud, see local model or API. Create a key in your account; access from Russia goes through the gateway, with payment by SBP, MasterCard or crypto.

FAQ

Can I run Claude Opus locally?

No. The weights of Claude models are not published, so you cannot run them on your own computer. Other models run locally, and Claude Code stays only as the shell.

Do I need an Anthropic account for Claude Code with a local model?

For a connection through Ollama you only need ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN from the example above. If you previously signed in to Claude Code with an account, run /logout once so the old login does not interfere.

How large should the context be?

Ollama recommends 64k tokens or more for larger repositories. On a small window the agent loses files and instructions, so first check which window is actually enabled for your model.

What should I start with: a local or a cloud model?

If you have no privacy requirements, start with a cheap cloud model and compare the result on your own tasks. If a local model handles the same tasks, weigh the hardware cost against tokens using the formula above.

zukko

Pay 25×
less

for Claude Code & ChatGPT

One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.

Get API keyDocumentation

api.zukko.pro · fetch_*

Claude Code locally: Ollama or a cloud model · Zukko