Skip to content

LearnTutorials

Run Claude Code on a local model with Ollama

Run Claude Code on a free local model with Ollama in under 25 minutes, so your code and prompts stay on your own computer with no API bills.

By Recaply EditorsIntermediate24 min6 stepsUpdated

Two hands type on an open laptop that sits under a small wooden roof, with a padlock hanging from the roof

What you need

Ollama needs macOS 14 Sonoma or newer, and Intel Macs run models on the CPU only. On Windows, it needs Windows 10 22H2 or newer.

  1. Step 1: Install Ollama

    3 min

    Ollama downloads and serves the model, and it speaks the same API that Claude Code expects.

    1. Go to ollama.com/download and install the app for your system.
    2. Linux: run the install command below instead.
    3. Open a new terminal window and run ollama --version.
    Linux: run this
    curl -fsSL https://ollama.com/install.sh | sh

    You should see a version number of 0.15 or higher.

    The version is older than 0.15?

    Click the Ollama icon in the menu bar or taskbar and choose Restart to update. Or download the latest version again.

  2. Step 2: Download a coding model

    8 min

    Claude Code needs a model that can call tools, and Ollama's own Claude Code guide uses Qwen3.5.

    1. Run the command below. It pulls the 9B model, about 6.6 GB.
    2. With 32 GB of memory or more, you can pull the larger qwen3.5:27b instead. It's about 17 GB.
    3. Wait for the download to finish.
    Run this
    ollama pull qwen3.5

    You should see a progress bar that fills up and ends with success.

    Your main drive is running out of space?

    Set the OLLAMA_MODELS variable to a folder on another drive, restart Ollama, then pull the model again.

  3. Step 3: Raise the context window to 64K

    2 min

    Ollama gives models a 4K window on GPUs with under 24 GB of memory. Coding agents need at least 64K.

    1. Mac or Windows: open the Ollama app's settings and move the context length slider to 64K.
    2. Linux, or from a terminal: quit the Ollama app, then start the server with the command below.
    Or run this
    OLLAMA_CONTEXT_LENGTH=64000 ollama serve

    You should see the slider at 64K, or the server running in that terminal with no error.

    ollama serve says the address is already in use?

    The Ollama app is still running. Quit it from the menu bar or taskbar, then run the command again.

    A bigger window uses more memory. If the model slows down a lot, stay at 64K rather than going higher.

  4. Step 4: Install Claude Code

    3 min

    Claude Code is the agent that reads and edits your files. Ollama only supplies the model behind it.

    1. Mac or Linux: run the command below.
    2. Windows: run irm https://claude.ai/install.ps1 | iex in PowerShell.
    3. Open a new terminal window and run claude --version.
    Mac or Linux: run this
    curl -fsSL https://claude.ai/install.sh | bash

    You should see a version number followed by (Claude Code).

    The terminal says it can't find claude?

    Open a new terminal window so it picks up the new install folder, then run the check again.

  5. Step 5: Launch Claude Code on the local model

    3 min

    ollama launch connects Claude Code to Ollama for you, so there are no variables to type.

    1. In the terminal, go to a project folder with cd.
    2. Run the command below.
    3. Type /status to check which model is in use.
    Run this
    ollama launch claude --model qwen3.5

    You should see Claude Code open in your project, with qwen3.5 as the model in /status.

    Claude Code warns that it doesn't recognize the model and assumes 200K tokens?

    Give it the real window so it compacts in time. Quit, run export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000, then launch again.

    To connect by hand, set ANTHROPIC_BASE_URL=http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama and an empty ANTHROPIC_API_KEY. Then run claude --model qwen3.5.

  6. Step 6: Give it a first task

    5 min

    A small task shows that the model can read files, edit them and run commands on your machine.

    1. Paste the prompt below and press Enter.
    2. Approve each file edit or command when Claude Code asks.
    3. In a second terminal window, run ollama ps to see how the model is loaded.
    Your prompt
    Read this project and sum it up in 5 bullets. Then add a file called hello.html with a simple Hello world page.

    You should see a short summary, a new hello.html file, and ollama ps showing 100% GPU with a context of 64K or more.

    Replies come out very slowly?

    Check the PROCESSOR column in ollama ps. A CPU share means the model didn't fit in GPU memory. Close other apps, or try the smaller qwen3.5:4b.

    Local models are smaller than cloud ones. Give them one clear change at a time rather than a whole feature.

You get

Claude Code running on a local Qwen3.5 model through Ollama, with your code and prompts kept on your own computer

Did this guide work for you?

Sources