How to Swap Claude Code's Brain for a Local Ollama Model
Running Claude Code against a local model eliminates per-token billing and keeps source code off cloud servers, but the integration is fragile: a wrong auth field or leftover VPN proxy setting silently breaks model discovery, and missing tool-calling support degrades the agent's automation without an obvious error.
A three-layer architecture places CC Switch between Claude Code and a local Ollama instance, intercepting API calls and converting them into OpenAI-compatible chat completions. The setup requires pointing CC Switch at Ollama's default endpoint (`http://localhost:11434/v1`), syncing the model list, and enabling a local routing service to bridge the protocol gap. Once configured, the `/model` command inside Claude Code surfaces the local models alongside the official ones.
Common failures trace back to two misconfigurations: the authentication field must be set to `ANTHROPIC_API_KEY` rather than the default token, and VPN system-proxy settings often hijack localhost traffic, producing 502 errors even after the VPN app is closed. The fix is either adding `127.0.0.1` and `localhost` to the VPN's bypass list or explicitly clearing the system proxy.
Local models bring zero API cost and full data privacy, but two constraints remain. Ollama's default context window is small and needs manual adjustment via the `num_ctx` parameter for longer coding sessions, and models that lack function-calling support will silently break Claude Code's tool-use features.
The integration's fragility comes from a mismatch in defaults: Claude Code expects Anthropic's auth scheme, but Ollama speaks OpenAI's format with no auth, so every field must be explicitly overridden — a single wrong dropdown breaks the whole chain.
VPN system-proxy pollution is a recurring footgun in local LLM setups because the failure mode (502 on localhost) looks like a server crash, not a networking misconfiguration, leading developers to restart services instead of checking proxy settings.
Tool-calling support is the hidden gatekeeper for local models in agentic coding; a model that generates good code but can't participate in Claude Code's tool loop will appear to work while silently degrading the agent's capabilities.