Logo
FrontierNews.ai

Claude Code Just Got Free: How to Run Anthropic's Coding Agent on Your Own Hardware

As of January 2026, you can redirect Claude Code, Anthropic's terminal coding agent, to run on local open-source models instead of Anthropic's cloud servers, eliminating API costs entirely. Ollama v0.14 shipped native Anthropic Messages API compatibility, meaning two environment variables are all it takes to route Claude Code from Anthropic's infrastructure to your own machine. Your code never leaves your hardware, and the agent receives responses in the exact format it expects.

What Changed in Ollama's January 2026 Update?

Claude Code is fundamentally a client that speaks the Anthropic Messages API, sending requests to an endpoint and receiving responses. That endpoint has always been Anthropic's cloud servers. In January 2026, Ollama introduced native compatibility with this API protocol, meaning Ollama can now respond to Claude Code requests using the same tool-calling format and streaming behavior as Anthropic's servers.

The practical result is straightforward: set two environment variables to point Claude Code at your local Ollama server instead of Anthropic's cloud, and the agent continues working exactly as designed. It does not know or care that a local model is answering instead of Claude Opus. It simply receives responses in the format it expects and keeps functioning.

What Are the Real Trade-offs of Running Claude Code Locally?

Running Claude Code on local hardware offers genuine benefits alongside real limitations. The advantages include zero API costs after initial hardware setup, complete privacy since your code and data never leave your machine, and the full Claude Code workflow including file reading, editing, command execution, and multi-step reasoning. However, open-source models do not match Claude Opus 5's capabilities, and response speed can be slow in some configurations, potentially affecting usability for complex agentic tasks.

How to Set Up Claude Code with Ollama Locally

  • Hardware Requirements: You need at least 8GB of RAM (16GB recommended, 32GB or more ideal), a computer running macOS, Linux, or Windows, and Node.js 18 or later installed.
  • Install Ollama: Download and install Ollama from ollama.ai. On macOS, use "brew install ollama"; on Linux, run the installation script; on Windows, download the installer which sets up as a background service automatically.
  • Start the Ollama Server: Run "ollama serve" in a terminal and leave it running, or on macOS it starts automatically after installation. Verify it is running by checking "curl http://localhost:11434/api/version".
  • Pull a Coding Model: Select a model based on your hardware. For 8GB RAM, pull "qwen2.5-coder:7b" which scores 76% on HumanEval. For 16GB RAM, pull "glm-4.7-flash," a 30B mixture-of-experts model with only 3B active parameters per token, featuring a 198K context window and 79.5% tool-calling performance on agent benchmarks. For 24GB or more VRAM, pull "qwen3-coder:30b" for the best local coding performance.
  • Install Claude Code: Run "npm install -g @anthropic-ai/claude-code" to install the command-line tool globally.
  • Configure Environment Variables: Set "ANTHROPIC_AUTH_TOKEN=ollama" and "ANTHROPIC_BASE_URL=http://localhost:11434" to redirect Claude Code to your local server. Add these to your shell configuration file (like ~/.zshrc or ~/.bashrc) to make them permanent.
  • Remap Model Tiers: Claude Code internally assigns tasks to different Claude model tiers (Haiku for simple tasks, Sonnet for medium, Opus for complex). Since Ollama does not have models named "claude-haiku" or "claude-opus," you must remap all three tiers to your local model by setting "ANTHROPIC_DEFAULT_HAIKU_MODEL," "ANTHROPIC_DEFAULT_SONNET_MODEL," and "ANTHROPIC_DEFAULT_OPUS_MODEL" to the same local model you pulled.
  • Launch Claude Code: Run "claude --model glm-4.7-flash" (or whichever model you pulled) to start the agent. It will connect to your local Ollama server with no network calls to Anthropic and no token charges.

How to Optimize Performance for Practical Use

Most setup guides stop at basic configuration, but developers then experience response times of 30 to 60 seconds and abandon the setup. Performance optimization is critical for actual usability. Enable Flash Attention by setting "OLLAMA_FLASH_ATTENTION=1" to reduce memory usage and speed up attention computation, which makes a meaningful difference for mixture-of-experts models like glm-4.7-flash and qwen3-coder:30b.

Configure the context window correctly since Claude Code uses large context windows for reading codebases. Set a minimum of 32K tokens by running "ollama run glm-4.7-flash --num_ctx 32768," or for models with larger windows like qwen3-coder, use "ollama run qwen3-coder:30b --num_ctx 65536." You can also set this permanently in a model configuration file for consistent performance across sessions.

Which Models Actually Work Best?

Model selection depends on your available hardware. The glm-4.7-flash model is the cleanest starting recommendation for most systems with 16GB RAM, offering strong agentic performance with a 198K context window and 79.5% tool-calling accuracy on agent benchmarks. Qwen2.5-Coder 7B fits in 8GB VRAM and scores 80.1% on HumanEval, handling 90% of routine coding tasks, though it is not the most powerful option. For developers with 24GB or more VRAM, qwen3-coder:30b provides the best local coding performance. For 32GB or more RAM on Mac systems, qwen3.6:27b scores 77.2% on SWE-bench, a comprehensive software engineering benchmark.

Model downloads take 10 to 20 minutes depending on internet speed. GLM-4.7-Flash is approximately 12.8GB, while smaller models like qwen2.5-coder:7b are significantly more compact. The trade-off is clear: larger models deliver better performance but require more hardware resources and longer download times.

When Should You Use Local Claude Code Versus Paying for the Real Thing?

Local Claude Code makes sense for developers who run frequent coding tasks on their own hardware and want to eliminate per-token costs over time. The setup requires 10 to 20 minutes of initial configuration and model downloading, plus the hardware investment. However, for complex agentic tasks requiring Claude Opus-level reasoning, or for developers who need guaranteed reliability and speed, Anthropic's cloud API remains the better choice. Local models are good; they are not Claude Opus 5. The honest assessment is that local setups work well for routine coding tasks and development workflows where speed is less critical than cost and privacy.