AIchimp AIchimp
Directory Models Guides Alternatives Compare AI Coding & Dev Foundation Models & Search AI Image & Design AI Video & Audio
Terminal Coding 5 min read Updated: 2026-11-22

Run Claude Code Locally with Ollama & LM Studio (Zero API Cost)

Point Anthropic's Claude Code CLI straight at local Ollama (v0.14.0+) or LM Studio (v0.4.1+) using native /v1/messages endpoints—zero proxies needed.

Both Ollama (v0.14.0+) and LM Studio (v0.4.1+) now expose native Anthropic-compatible /v1/messages endpoints. That means Claude Code works completely offline against local open coding models like Qwen3.8-27B, qwen3-coder, or Gemma 4—with zero proxy scripts and zero per-token bills once you adjust the context window to 32K–64K+.

How It Fits Together

1. Update Local Runner

Upgrade Ollama to v0.14.0+ or LM Studio to v0.4.1+ for native /v1/messages support.

Ollama Ollama

2. Load 64K Context Model

Pull Qwen3.8-27B or qwen3-coder and set context length to at least 32K–64K.

LM Studio LM Studio

3. Point & Launch CLI

Set ANTHROPIC_BASE_URL, dummy ANTHROPIC_AUTH_TOKEN, unset ANTHROPIC_API_KEY, and launch claude.

Claude Code Claude Code

Exact Commands for Ollama and LM Studio

Notice two tiny details that trip people up: pass any non-empty dummy string for ANTHROPIC_AUTH_TOKEN, and explicitly unset ANTHROPIC_API_KEY in your shell so Claude Code never tries to validate against Anthropic's cloud servers.

Switch Claude Code to local Ollama (port 11434) or LM Studio (port 1234)
# --- Option 1: Ollama (v0.14.0+) ---
ollama pull qwen3-coder
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
unset ANTHROPIC_API_KEY
claude --model qwen3-coder
# Tip: Ollama also includes shortcut: ollama launch claude

# --- Option 2: LM Studio (v0.4.1+, set 64K context!) ---
lms load qwen/qwen3-coder-30b --context-length 65536
lms server start --port 1234
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
unset ANTHROPIC_API_KEY
claude --model qwen/qwen3-coder-30b

Why Context Length Matters So Much Locally

Claude Code carries multi-file diffs, tool schemas, and conversation logs inside every turn. Leaving Ollama or LM Studio on a tiny 4K–8K default causes instant truncation or broken tool calls.

Minimum vs recommended local specs for running agentic Claude Code loops
Hardware SetupContext Window TargetRecommended Local ModelBest Use
16GB Mac / 12GB GPU 32K Context (minimum) Gemma 4 12B / Qwen3.8 smaller quants Scoped single-module fixes & confidential scripts
24GB GPU / 32GB–64GB Mac 64K Context (sweet spot) Qwen3.8-27B / qwen3-coder-30b Daily private repo edits with strong tool-calling reliability
Hybrid Cloud + Local OpenCode 128K–1M Context Switch freely between local Ollama & Claude / GLM-5.3 Zero-cost scouting locally, frontier accuracy on commits

Before You Start

  • Always unset ANTHROPIC_API_KEY—leaving a cloud key exported alongside ANTHROPIC_BASE_URL triggers auth conflicts or unintended cloud fallback.
  • Never skip setting context length to 32K–64K+ when loading models in LM Studio or custom Ollama Modelfiles; small 4K defaults break Claude Code tool schemas immediately.
  • Be realistic about speed and accuracy on tiny 7B models: if a complex refactor stalls locally, switch back to OpenCode or pay-per-token DeepSeek / Claude for that task.

Tools Used in This Guide

Compare Related Tools

Common Questions

Do I still need LiteLLM or claude-code-router proxies in late 2026?

No for Ollama v0.14.0+ and LM Studio v0.4.1+, both include native /v1/messages Anthropic protocol endpoints directly. Proxies are only needed for custom non-Anthropic REST providers.

How do I run the exact same environment setup in Windows PowerShell?

Use $env:ANTHROPIC_BASE_URL='http://localhost:11434'; $env:ANTHROPIC_AUTH_TOKEN='ollama'; Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue; claude --model qwen3-coder.

Does OpenCode also support connecting the same local Ollama server?

Yes—OpenCode works seamlessly with Ollama and makes it easier to swap models mid-session between local weights and cheap APIs like DeepSeek or GLM-5.3.