Run Claude Code for Free? Ollama Adds Anthropic API Compatibility
Ollama v0.14.0 now supports the Anthropic API, letting you run Claude Code locally with open‑source models like Qwen or Llama without an API key, network, or cost, and the article provides a step‑by‑step setup, SDK examples, and an objective assessment of the approach.
If Claude Code is the hottest AI coding agent, Ollama is the king of local LLM deployment. Previously, using Claude Code required an Anthropic API key, incurred network latency, and charged per token.
Ollama v0.14.0 now officially supports the Anthropic API protocol. This means you can drive Claude Code with local open‑source models (e.g., Qwen, Llama) without an API key, internet connection, or any cost.
What Is Anthropic API Compatibility?
Anthropic defines a Messages API that tools like Claude Code rely on. Earlier Ollama only mimicked OpenAI’s protocol, so using Claude’s ecosystem forced you to call Anthropic’s cloud endpoint or a compatible service such as Deepseek.
With the new update, Ollama acts as a local proxy that pretends to be an Anthropic server. When Claude Code sends a request, Ollama translates it into a format the local model understands, runs the inference, and translates the response back.
Step‑by‑Step Guide to Run Claude Code Locally
Step 1: Prepare the environment – Upgrade Ollama to v0.14.0 or later, then install Claude Code:
# macOS / Linux
curl -fsSL https://claude.ai/install.sh | bash
# Windows (PowerShell)
irm https://claude.ai/install.ps1 | iexStep 2: Trick Claude Code – Set two environment variables so Claude Code points to the local Ollama server instead of Anthropic’s cloud:
# The token can be any string; Ollama does not validate it
export ANTHROPIC_AUTH_TOKEN=ollama
# Point to the local Ollama endpoint
export ANTHROPIC_BASE_URL=http://localhost:11434Step 3: Launch Claude Code – Run Claude Code with a locally available model, e.g., gpt-oss:20b or the popular qwen3-coder (Qwen code model):
# Use a local model
claude --model qwen3-coder
# Or use a cloud model for comparison
claude --model glm-4.7:cloudWhen successful, the Claude Code UI appears, but the underlying model runs on your GPU.
SDK Usage for Developers
The same compatibility works for any application built on the Anthropic SDK (Python or JavaScript). Example in Python:
import anthropic
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama', # required but content is ignored
)
message = client.messages.create(
model='qwen3-coder',
messages=[{'role': 'user', 'content': '写一个判断素数的 Python 函数'}]
)
print(message.content[0].text)And in JavaScript:
import { Anthropic } from '@anthropic-ai/sdk'
const anthropic = new Anthropic({
baseURL: 'http://localhost:11434',
apiKey: 'ollama',
})
const message = await anthropic.messages.create({
model: 'qwen3-coder',
messages: [{ role: 'user', content: '写一个判断素数的 Python 函数' }],
})
console.log(message.content[0].text)If the chosen local model supports them, this compatibility also covers Tool Calling and Vision features.
Objective Evaluation
Intelligence gap – Claude Code’s strength comes from Claude Sonnet/Opus’s high reasoning ability. Local 7B‑14B models may struggle with complex multi‑step refactoring tasks and sometimes fail to understand intricate Claude Code prompts.
Context limits – Claude Code expects to read an entire project’s file tree in one go. While Ollama’s cloud models can handle long contexts, running large‑context models locally demands substantial GPU memory.
Compute threshold – A smooth experience generally requires a high‑end GPU such as an RTX 4090 or Apple M‑series silicon. Integrated graphics lead to painfully slow generation.
Beyond personal convenience, this update provides a standardized interface for enterprises to privately deploy AI agents.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
