—
Release date: January 16, 2026
Requires: Ollama v0.14.0+
This README explains how to run Claude Code using Ollama with full Anthropic Messages API compatibility, allowing you to use Claude Code with open‑source local models or Ollama Cloud models.
Claude Code is Anthropic’s agentic coding tool that runs directly in your terminal. With Ollama acting as an Anthropic‑compatible backend, you can replace Claude models with local or cloud models seamlessly.
curl -fsSL https://claude.ai/install.sh | bash
irm https://claude.ai/install.ps1 | iex
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
Configure the following environment variables so Claude Code talks to Ollama instead of Anthropic’s cloud.
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
The API key is required by the SDK but ignored by Ollama.
claude --model gpt-oss:20b
claude --model glm-4.7:cloud
Ollama Cloud models always run at their maximum context length.
gpt-oss:20bqwen3-coderglm-4.7:cloudminimax-m2.1:cloudClaude Code performs best with 64k+ token context models.
To adjust local model context length, refer to the Ollama context length documentation.
Existing applications using the Anthropic SDK can connect to Ollama by simply changing the base_url.
import anthropic
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama', # required but ignored
)
message = client.messages.create(
model='qwen3-coder',
messages=[
{'role': 'user', 'content': 'Write a function to check if a number is prime'}
]
)
print(message.content[0].text)
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: 'Write a function to check if a number is prime' }],
})
console.log(message.content[0].text)
Models can invoke tools exactly like Claude models.
import anthropic
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama',
)
message = client.messages.create(
model='qwen3-coder',
tools=[
{
'name': 'get_weather',
'description': 'Get the current weather in a location',
'input_schema': {
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA'
}
},
'required': ['location']
}
}
],
messages=[{'role': 'user', 'content': "What's the weather in San Francisco?"}]
)
for block in message.content:
if block.type == 'tool_use':
print(f'Tool: {block.name}')
print(f'Input: {block.input}')
For the complete compatibility list, see the Anthropic compatibility documentation.
With Ollama acting as an Anthropic‑compatible backend, Claude Code becomes a powerful local‑first coding agent that works with open‑source and cloud models—without changing your existing Anthropic‑based workflows.
Happy hacking 🚀