← all posts
[ guide ]June 24, 202610 min read

How to Use Claude Code & Coding Agents with a Local LLM

Can you run Claude Code on a local LLM? Technically yes — but there are two real catches: it speaks the Anthropic API, and its large system prompt eats a small model's context window. Here's the honest path, plus the lighter terminal agent that actually works well on your own GPU.

"Can I run Claude Codeon a local LLM?" is one of the most-asked questions in self-hosted AI, and most answers online are either "no" or a config snippet that quietly doesn't work in practice. The honest answer is: technically yes, but there are two real catches— and once you understand them, you'll probably pick a different tool for local coding and keep Claude Code for the cloud work it's great at. This page walks the real arc, from someone who actually tried it.

Watch: the two catches, and the clean path — in about two minutes.

Catch #1 — Claude Code speaks the Anthropic API, not OpenAI

Almost every local inference server (llama.cpp, Ollama, LM Studio, vLLM) exposes an OpenAI-compatible endpoint — /v1/chat/completions. Claude Code does not speak that. It talks to whatever ANTHROPIC_BASE_URL points at using Anthropic's Messages API (/v1/messages), a different request and response shape. So you can't simply point Claude Code at localhost:11434and have it work — the formats don't match.

The workaround is a translation proxy: a small service that accepts Anthropic-format requests and re-emits them as OpenAI calls to your local model. claude-code-router and LiteLLM both do this. You set ANTHROPIC_BASE_URL to the proxy, and the proxy forwards to your local server or a gateway upstream.

claude code → translation proxy
# Claude Code talks to whatever ANTHROPIC_BASE_URL points at,
# using the Anthropic Messages API format — NOT OpenAI's.
export ANTHROPIC_BASE_URL="http://localhost:8787"   # a translation proxy
export ANTHROPIC_AUTH_TOKEN="anything"              # the proxy checks/forwards this

# The proxy (e.g. claude-code-router or LiteLLM) converts Anthropic
# /v1/messages requests into OpenAI /v1/chat/completions calls and
# forwards them to your local model or gateway upstream.

If your endpoint already speaks the Anthropic Messages API you can skip the proxy — but most local stacks are OpenAI-shaped, so plan on a shim. Getting the format right is the easy half of the problem. The hard half is next.

Catch #2 — the context-window trap (the real gotcha)

This is the one that bites people after they've solved the API format. Claude Code is designed for frontier cloud models with very large context windows, so it ships a large system prompt plus extensive tool definitions and sends them on every request. On a cloud model with a huge window, that overhead is negligible. On a local model, it can be most of your budget — before you've added a single line of your own code.

It gets worse because of defaults. Many local runtimes ship a small default context window — Ollama's default num_ctxis modest, and LM Studio loads at a conservative context length unless you raise it. Combine a small default window with Claude Code's heavy built-in prompt and the model can be effectively full on arrival, with no room to actually read your files or hold a conversation.

raise the context window — and pay for it in VRAM
# The trap: Claude Code's own system prompt + tool defs are large.
# On a runtime that defaults to a small context window, they can fill it.

# Ollama defaults num_ctx to a small value — raise it explicitly:
#   (in a Modelfile)  PARAMETER num_ctx 32768
# LM Studio: set the context length slider up (e.g. 32768) before loading.
# Either way, more context = more VRAM for the KV cache.

To make Claude Code usable locally you therefore need both a large-context local model (32k at the very least, ideally 128k) and to explicitly configure the runtime to allocate that context (Ollama num_ctx, LM Studio context length). That extra context is real KV-cache memory on top of the weights — so this path realistically wants a 24GB-class card running a large-context model, just to give Claude Code's own overhead somewhere to live.

The honest recommendation: right tool for each job

After fighting both catches, the pragmatic conclusion is simple: don't force Claude Code onto a local model. Keep Claude Code for cloud / Anthropic work, where its big context budget is free and it genuinely shines. For local coding on your own GPU, switch to a lighter-weight terminal agent whose system prompt doesn't blow the context budget — that one change makes a small-context local model feel usable instead of suffocated.

AgentAPI it speaksLocal-friendly?Notes
Claude CodeAnthropic MessagesAwkwardNeeds proxy + large context; best on cloud
oh-my-pi (omp)OpenAI + customExcellentLight prompt, custom providers — recommended local
ClineOpenAI-compatibleGoodWants a 32B coder + big context for agentic edits
AiderOpenAI-compatibleGoodBase-URL swap; great for focused edits
Continue.devOpenAI-compatibleGoodIDE autocomplete + chat on your GPU

The specific recommendation is oh-my-pi (the binary is omp) by can1357. It's an open-source terminal coding agent that loads custom providers from ~/.omp/agent/models.yml, so you declare a Wide Area Intelligence provider and code against a model on hardware you own — zero per-token cost, code never leaving your machines.

the lighter local path — omp + your GPU
# The lighter local path: oh-my-pi (omp) with a WideAreaAI provider.
bun install -g @oh-my-pi/pi-coding-agent

# ~/.omp/agent/models.yml — point omp at your own GPU via the gateway
providers:
  wideareaai:
    baseUrl: https://wideareaai.com/api/v1
    apiKey: WIDEAREAAI_API_KEY        # resolved from the agent .env
    api: openai-completions
    models:
      - id: Qwen3-Coder-30B-A3B-Instruct
        name: WideAreaAI Qwen3 Coder
        contextWindow: 32768
        cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }

Full step-by-step: run the oh-my-pi coding agent on your own GPU with Wide Area Intelligence.

Where the gateway fits — and fixes the failure case

Whichever OpenAI-compatible agent you choose, a gateway is what turns "a model on one machine" into "a model my agent can rely on." Wide Area Intelligence serves your chosen model from a GPU node behind one OpenAI-compatible endpoint (https://wideareaai.com/api/v1) with revocable keys and multi-node load balancing — reachable from any machine, no port forwarding.

It also directly answers the context-window trap's worst case: capability-aware cloud failover.When a small-context local model genuinely can't handle a task, the gateway fails the request over to a cloud model on prepaid credits instead of hard-failing — so your agent keeps working and you only pay for the requests that truly needed the cloud. That's the "right tool for each job" principle enforced at the routing layer. How capability-aware failover works →

01

Keep Claude Code for the cloud

It's built for frontier models with huge context — use it where that's free, not where you're fighting num_ctx.
02

Use a light agent locally

oh-my-pi (or Cline / Aider / Continue) with a large-context coder model your card can serve — see the best local coding models.
03

Put it behind a gateway

One endpoint, one key, reachable from anywhere, with cloud failover for the tasks local can't handle.

Not sure your GPU can serve a large-context coder model in the first place? Check with can I run it? and the context window calculator, then bring your GPU online with Wide Area Intelligence →It's free for up to two nodes.

Frequently asked questions

Can Claude Code run on a local LLM?
Technically yes, but with two real catches. First, Claude Code speaks the Anthropic Messages API, not the OpenAI-compatible format most local servers expose — so you must set ANTHROPIC_BASE_URL to an Anthropic-compatible endpoint or run a translation proxy like claude-code-router or LiteLLM. Second, and more limiting: Claude Code ships a large system prompt and extensive tool definitions that consume a big chunk of the context window before you type anything, so a small-context local model can be almost full before it sees your code. It works best with a large-context local model (32k+) explicitly configured, and many people get a better result switching to a lighter local agent.
Why does Claude Code use so much context on a local model?
Claude Code is built for frontier cloud models with very large context windows, so it front-loads a substantial system prompt plus detailed tool/function definitions on every request. On a cloud model that's a rounding error; on a local model whose runtime defaults to a small context window (for example Ollama's default num_ctx, or a modest LM Studio context length), that built-in overhead can consume most or all of the window, leaving little room for your files. The fix is a large-context local model with the runtime explicitly told to allocate that context — which also costs extra VRAM.
What's the best coding agent for a local LLM?
For local models, a lighter-weight terminal agent whose system prompt doesn't blow the context budget tends to work much better than Claude Code. oh-my-pi (omp) is a good fit: it supports custom OpenAI-compatible providers, so you can point it at a model on your own GPU through a gateway. Cline, Aider, and Continue also work well because they speak the OpenAI API directly. Keep Claude Code for cloud/Anthropic work where its big context budget is free, and use a lighter agent for local.
How do I point a coding agent at my own GPU?
OpenAI-compatible agents (oh-my-pi, Cline, Aider, Continue, Codex CLI, Qwen Code) need three things: a base URL, an API key, and a model ID. Wide Area Intelligence gives you one OpenAI-compatible base URL (/api/v1) and a revocable key, and serves your chosen model from a GPU node with cloud failover. Point the agent's custom/OpenAI provider at that URL and it runs against your own hardware — and when a small local model can't handle a task, the gateway fails over to a cloud model.
Do I need a translation proxy to use Claude Code with a local model?
Yes, unless your endpoint already speaks the Anthropic Messages API. Claude Code talks to ANTHROPIC_BASE_URL using Anthropic's format, so to reach an OpenAI-compatible local server you put a shim in between — claude-code-router and LiteLLM both translate Anthropic↔OpenAI and let you set the upstream to your local/gateway endpoint. Even with the proxy in place, the context-window issue still applies, which is why a lighter local-first agent is often the better answer.

/// get started

That GPU is already paid for.
Put it on the network.

Create your gateway — free →