Run Claude Code with Ollama on Your Own VPS
Updated Aug 2026
Point Claude Code at a self-hosted Ollama server — run open-source coding models like Qwen3-Coder with no API bill, using Ollama's Anthropic-compatible API.
- Ollama 0.15 or newer, installed locally or on a VPS (see Deploy Ollama on a VPS)
- Claude Code installed on your workstation
- Enough RAM/VRAM for a tool-calling coding model (~9 GB for the smallest good option)
Why run Claude Code against your own models?
Claude Code is a terminal coding agent, and by default it talks to Anthropic's API. Since early 2026, Ollama ships an Anthropic-compatible /v1/messages endpoint — which means Claude Code can drive open-source models running on hardware you control. No per-token bill, no code leaving your infrastructure.
The trade-off is honest: local models are noticeably weaker than the hosted Claude models at multi-step agentic work. For sensitive codebases, air-gapped environments, or high-volume grunt work (test generation, refactors, docs), a self-hosted backend is a real option. For hard architectural work, expect a quality gap.
Pick a model that can call tools
Claude Code leans hard on tool calling — the model must support it, and it needs context headroom. Ollama's own integration docs recommend at least 32K context, ideally 64K or more.
Models we'd actually point Claude Code at, all tool-calling capable:
- glm-4.7-flash — the lightest option that behaves well in agent loops; runs in roughly 9 GB of memory. Start here on modest hardware.
- qwen3-coder:30b — the sweet spot for dedicated coding work. It's a ~19 GB download and wants 24 GB of VRAM (or unified memory) to run comfortably.
- deepseek-r1:32b — strong reasoning; needs about 20 GB of VRAM.
On a CPU-only VPS these run, but slowly — agent loops make many model calls, so tokens-per-second matters more here than in chat. See the sizing section of our Ollama deployment guide for RAM math.
The one-command path: ollama launch claude
Recent Ollama releases include a launcher that wires everything for you:
ollama launch claude
It configures Claude Code to talk to your local Ollama and starts it. Pin a model explicitly with:
ollama launch claude --model qwen3-coder:30b
That's the whole setup when Ollama runs on the same machine as Claude Code.
The manual path: point Claude Code at a VPS
If Ollama runs on a VPS (the setup this site cares about), configure Claude Code by environment variable:
export ANTHROPIC_AUTH_TOKEN=ollama # required by the CLI, ignored by Ollama
export ANTHROPIC_BASE_URL=http://<your-vps-tunnel>:11434
claude --model qwen3-coder:30b
ANTHROPIC_AUTH_TOKEN can be any non-empty value — Ollama doesn't check it. ANTHROPIC_BASE_URL is the Ollama server's address; no /v1 suffix needed. There's no /login flow in this mode.
Do not expose port 11434 to the public internet. Ollama has no built-in authentication — anyone who can reach the port can run your models. Reach the VPS over a private channel instead:
# SSH tunnel: your laptop's localhost:11434 → the VPS's Ollama
ssh -N -L 11434:localhost:11434 you@your-vps
Then use ANTHROPIC_BASE_URL=http://localhost:11434 as if it were local. A mesh VPN like Headscale or NetBird does the same job permanently, and a reverse proxy with auth in front of Ollama works if you must serve multiple users.
What won't work like the hosted API
Ollama's Anthropic-compatibility layer is deliberately scoped. The documented gaps that matter for Claude Code:
- No prompt caching. Every request re-processes the system prompt and conversation history, so long sessions get slower and burn more compute than the hosted API would.
- No forced tool choice. The
tool_choiceparameter isn't supported; occasionally a model will answer in prose when Claude Code expected a tool call. Better models misfire less. - Approximate token counts. The token-counting endpoint isn't implemented, so context-window bookkeeping is an estimate.
- Images must be base64. URL-referenced images aren't fetched.
None of these break the core loop — edit, run, test, commit works. They're the reason the experience trails the hosted models even before model quality enters the picture.
Cost math
A VPS that runs glm-4.7-flash around the clock costs a flat monthly price — compare that against a metered API bill that scales with every agent loop. If you're running batch agentic workloads daily, the crossover comes fast; if you use Claude Code an hour a week, the hosted API is cheaper and better. Our Ollama VPS guide has current provider picks sized for each model tier.