Back to blogs

Tuesday, Jul 7, 2026

How to Set Up Claude Code with Ollama for Free on a Local AI Model

Learn how to run Claude Code with Ollama on a local AI model for free. This guide covers installation, environment variables, model selection, and how to keep your coding workflow offline and private.

How to Set Up Claude Code with Ollama for Free on a Local AI Model

How to Set Up Claude Code with a Local Ollama Model (Free & Offline)

If you've been searching for how to run Claude Code with Ollama, this guide walks you through the exact setup. Instead of paying for a monthly subscription, you can use Claude Code with a local AI model through Ollama, allowing you to code with an open-source model running directly on your own computer.

This setup is completely local, keeps your data on your machine, and works without sending requests to Anthropic's servers. If you want a free, offline coding assistant, this is the simplest path.

Note: This method uses Claude Code's CLI with a locally hosted OpenAI-compatible model. You're not running Anthropic's Claude model locally—you are using Claude Code as the interface while an open-source model handles the responses.


Prerequisites

Before getting started, you'll need:

  • Claude Code CLI
  • Ollama
  • A computer with enough RAM to run a local LLM (16 GB RAM is recommended for larger models)

Step 1: Install Claude Code

Visit the Claude Code website and install the CLI for your operating system.

macOS / Linux / WSL

curl -fsSL https://claude.ai/install.sh | bash

Windows

Use either the Command Prompt or PowerShell installation command provided on the Claude Code installation page.

After installation, Claude Code will try to connect to Anthropic's servers by default. We'll change that in a later step.


Step 2: Install Ollama

Download and install Ollama from the official website.

Once installed, Ollama lets you run open-source language models directly on your computer.


Step 3: Download a Local Model

Open Ollama and choose any model you'd like to use.

Some popular choices include:

  • GPT-OSS 20B
  • DeepSeek
  • Gemma
  • Qwen

For this guide, we'll use GPT-OSS 20B.

Download the model:

ollama run gpt-oss:20b

The download may take several minutes depending on your internet speed since the model is several gigabytes in size.

Once the download finishes, test it by asking a simple question:

Hi

If you receive a response, your local model is working correctly.


Step 4: Redirect Claude Code to Ollama

By default, Claude Code connects to Anthropic's API.

Instead, we'll point it to the local Ollama server.

Run the following command in your terminal:

export ANTHROPIC_BASE_URL=http://localhost:11434

Claude Code also expects an API token. Since Ollama doesn't require one, you can provide any random value:

export ANTHROPIC_AUTH_TOKEN=dummy

These environment variables tell Claude Code to communicate with your local Ollama server instead of Anthropic.

Windows (PowerShell)

$env:ANTHROPIC_BASE_URL="http://localhost:11434"
$env:ANTHROPIC_AUTH_TOKEN="dummy"

Step 5: Launch Claude Code

Now simply run:

claude

Claude Code should start without asking you to purchase a subscription or configure an Anthropic account.

At this point, it is already communicating with your local AI model.


Step 6: Select the Correct Model

First, list the models installed in Ollama:

ollama list

Example output:

NAME
gpt-oss:20b

Now launch Claude Code with that model:

claude --model gpt-oss:20b

Replace gpt-oss:20b with whichever model you downloaded.

Claude Code will now use your local model instead of the default one.


Why Use a Local Model?

Running AI models locally has several advantages:

  • 💰 No monthly subscription fees
  • 🔒 Your code never leaves your computer
  • 🌐 Works offline after downloading the model
  • 🔄 Easily switch between different open-source models
  • ⚡ Faster iteration without API rate limits

It's a great setup for learning, experimenting, and personal projects.


Limitations

Local models are improving rapidly, but there are still a few trade-offs:

  • Large models require significant RAM and disk space.
  • Responses may be slower depending on your hardware.
  • Performance may not match the latest proprietary Claude models on complex coding tasks.

For production workloads, a cloud-hosted model may still provide better results.


Conclusion

Using Claude Code with Ollama is an excellent way to experience an AI-powered coding assistant without paying for a subscription. Once everything is set up, you can easily switch between different open-source models while keeping your code completely private.

If you're learning, building side projects, or simply want to experiment with local AI, this setup is definitely worth trying.

FAQ

Can Claude Code run with Ollama?

Yes. Claude Code can point to a local Ollama server by using the ANTHROPIC_BASE_URL environment variable and a placeholder API token.

Which local model should I use?

For general coding tasks, a strong instruction-tuned model such as GPT-OSS 20B, DeepSeek, Gemma, or Qwen is a good starting point. If your machine has less RAM, choose a smaller model that runs comfortably on your hardware.

Does this work offline?

After the model finishes downloading, the workflow runs locally. That means you can keep using Claude Code without sending your prompts to Anthropic's servers.

Designed & developed by Vishesh Verma