Run Claude Code Locally for Free With Ollama


📺

Article based on video by

Sharbel A. — Watch original video ↗

Claude Code can inspect files, run commands, and revise a project without sending your source code to Anthropic—but the local setup has one detail many guides blur: Claude Code is the harness, not the model. I spent time tracing that distinction and the practical trade-offs so you can decide whether Ollama is worth running on your hardware.

📺 Watch the Original Video

What Claude Code With Ollama Actually Means

Claude Code Ollama usually means running the official Claude Code command-line client with a model served by Ollama, rather than sending requests to Anthropic’s hosted models. Ollama’s integration uses an Anthropic-compatible API, so the workflow stays familiar while the model runs locally.[2][6]

Claude Code is the agent harness

Claude Code is the part that inspects your project, reads and edits files, runs terminal commands, calls tools, makes plans, and repeats the process until a task is complete. Think of it as the agent harness: the shell around the model that turns suggestions into actual work.

What surprised me here is how much of the experience belongs to the harness, not the model. You can launch it with `ollama launch claude –model qwen3.5`, for example, and still work through the same terminal-oriented flow.[2][3]

Ollama supplies the local language model

Ollama runs the underlying model on your computer. Its local server normally listens at `http://localhost:11434`, and local requests do not require an API key.[1][4]

That separation matters. Swapping in Qwen, GPT-OSS 20B, or another model does not automatically replace Claude Code with a different coding client. The model changes; the project inspection, file operations, and tool workflow can remain Claude Code’s.

Genuine Claude Code versus third-party clones

The official Claude Code CLI is Anthropic’s client connected to Ollama’s compatible endpoint. Other projects may imitate its interface, but they can differ in planning, tool calls, permissions, context handling, and reliability.

This is where many tutorials get it wrong: “Claude Code-style” does not necessarily mean the actual Claude Code client.

What stays the same and what changes

The main benefits are local source-code processing, no Anthropic usage charges, and control over model choice. Ollama’s documentation recommends at least a 32K-token context window for Claude Code, with 64K or more useful for larger repositories.[2][6]

But local models can be slower, weaker at complex reasoning, or less dependable with multi-step tool use than hosted Claude models. Choose Ollama when privacy, predictable local use, and experimentation matter more than maximum coding quality and speed—like choosing a workshop in your garage instead of a faster remote service.

Install Ollama and Claude Code on Your Platform

Ollama runs the language model locally, while Claude Code remains the agent that reads files, edits code, runs commands, and works through multi-step tasks. Think of Ollama as the engine and Claude Code as the driver.

macOS installation

Download and install Ollama for macOS, then open the Ollama application before starting Claude Code. Confirm the command-line tool is available:

“`bash

ollama –version

“`

If Claude Code is not installed, Ollama’s launcher can offer to install it when you run `ollama launch claude`.[6] In my experience, opening the app first prevents the confusing “connection refused” error that beginners often meet.

Linux installation

Install Ollama from the terminal:

“`bash

curl -fsSL https://ollama.com/install.sh | sh

“`

Start the service if your installation does not launch it automatically:

“`bash

ollama serve

“`

Then check the installation:

“`bash

ollama –version

“`

Linux setups vary, so a service managed by `systemd` may already be running. You usually need around 4 GB just for the Windows installation, while model files can require several additional gigabytes.[7]

Windows installation

Install the Windows application with the official installer, or use PowerShell:

“`powershell

irm https://ollama.com/install.ps1 | iex

“`

Ollama runs in the background and makes the `ollama` command available in PowerShell or Command Prompt.[7] Environment variables use different syntax here than they do in macOS or Linux shells, so don’t copy `export` commands blindly.

Verify the Ollama service

Ollama normally listens locally at `http://localhost:11434`.[7] Test it with:

“`bash

curl http://localhost:11434

“`

A response confirms that the local service is reachable. If nothing responds, open the Ollama app or start `ollama serve`.

Download and test a model

Download and run an initial model:

“`bash

ollama pull qwen3.5

ollama run qwen3.5

“`

`pull` downloads the model weights; `run` loads them into memory. Those are separate limits: a model might fit on disk but still need more RAM or VRAM than your computer has. Check available storage first, especially with larger models and long context windows.

Once the model works, launch the integration:

“`bash

ollama launch claude –model qwen3.5

“`

Ollama’s launcher guides setup and avoids manual configuration in many cases.[2] If you configure Claude Code yourself, set `ANTHROPIC_BASE_URL` to `http://localhost:11434` and ensure an old cloud API key does not redirect requests to Anthropic.[3]

Connect Claude Code to Ollama and Configure Context

The quickest way to run the real Claude Code CLI with a local Ollama model is:

“`bash

ollama launch claude

“`

Ollama configures the connection for you, so there’s no need to copy environment variables by hand.[1][2]

The quickest launcher command

Run that command from your repository directory. Ollama will guide you through choosing a model, while Claude Code keeps its usual terminal access, file editing, project inspection, and agent workflow.

In my experience, this is the cleanest starting point because it avoids small configuration mistakes that can be surprisingly hard to spot.

Selecting a specific model

To launch directly with Qwen3.5:

“`bash

ollama launch claude –model qwen3.5

“`

Ollama specifically documents this model with the Claude Code integration.[1][2] Make sure the model is available first, if necessary:

“`bash

ollama pull qwen3.5

“`

Manual environment-variable configuration

If you prefer explicit control on macOS or Linux, use:

“`bash

export ANTHROPIC_AUTH_TOKEN=ollama

unset ANTHROPIC_API_KEY

export ANTHROPIC_BASE_URL=http://localhost:11434

claude –model qwen3.5

“`

Windows users should set the equivalent variables with PowerShell syntax, such as `$env:ANTHROPIC_AUTH_TOKEN=”ollama”` and `$env:ANTHROPIC_BASE_URL=”http://localhost:11434″`.

Clearing `ANTHROPIC_API_KEY` matters. A stale key can send requests to Anthropic’s paid hosted service instead of your local Ollama server—like setting the GPS destination correctly but leaving an old route active.

Set a context window for coding projects

Use at least 64K tokens for larger repositories.[1][2] An optional shell setting is:

“`bash

export OLLAMA_CONTEXT_LENGTH=131072

ollama serve

“`

That larger window can hold more repository files, command output, tool history, and conversation messages, but it also uses more memory and may reduce speed. A model might support more than 64K, yet the serving limit, available RAM or VRAM, and the model’s behavior determine what you can actually use.[1][2]

Prevent accidental cloud requests

Before sharing sensitive code, inspect Claude Code’s startup output and confirm both the model name and `http://localhost:11434`. Then ask a simple repository question and verify that the response comes from the expected local model.

This quick check is worth doing every time you change models or shell configuration; “local” is useful only if the request is genuinely staying local.

Choose a Model That Matches Your Hardware and Work

The best starting point for a local Claude Code experiment is Qwen3.5. Ollama currently lists a Claude Code launcher for it, along with a 256K context window; the default entry is roughly 6.6–7.6 GB, depending on the tag.[1]

That does not mean you should immediately choose the biggest available model. Your computer has to hold the model weights, context memory, KV cache, operating-system overhead, and whatever else is open. The advertised download size is only the suitcase, not everything you pack around it.

Lightweight models for limited RAM or VRAM

For a laptop with limited memory, begin with a small quantized model—often a 4B or 7B-class option. Q4 generally uses less memory and runs faster than Q8 or full precision, though difficult debugging and planning can lose some accuracy.[7]

GLM-4.7-Flash is another resource-conscious candidate, particularly if tool calling and long-context work matter. I’d validate it on your own repository, though; a model that looks excellent in a demo can stumble when it has to recover from a failed command.

Balanced coding models

If coding quality is the priority, consider Qwen3-Coder. Check the exact Ollama tag first, because availability, model size, context settings, and tool behavior can differ between variants.

GPT-OSS 20B can occupy the middle ground when your system has enough RAM or VRAM. Gemma is a sensible general-purpose alternative, but multi-turn tool reliability can vary by model and version—so “works once” is not enough evidence.

Larger models for stronger reasoning

Use the simple rule I’ve found most practical: small quantized models for laptops, mid-sized models for balanced speed and quality, and larger models when stronger reasoning justifies the memory cost. A 256K context window sounds impressive, but if your machine starts swapping, responsiveness collapses.

CPU versus GPU inference

CPU-only inference is perfectly usable for experimentation, but token speed is usually lower. GPU acceleration—or unified memory on some systems—makes Claude Code feel much more responsive.

Run the same small task on two models: inspect a repository, make one targeted change, run tests, and compare accuracy, speed, and tool recovery. That benchmark tells you more than a model leaderboard ever will.

Use Claude Code Locally Safely and Fix the Problems You Will Hit

Running the actual Claude Code CLI with a local Ollama model gives you the familiar agent harness—terminal access, file editing, planning, and tests—without sending your project to Anthropic. Ollama documents this setup through its Anthropic-compatible local endpoint at `http://localhost:11434`.[1]

A practical local coding workflow

Start inside the project you actually intend to change. After Ollama is running and the model is installed, launch Claude Code with:

“`bash

ollama launch claude –model qwen3.5

“`

Ollama also supports launching Claude Code directly with a selected model such as `qwen3.5`.[1][4] Before asking for edits, say: “Explain this repository, map the important directories, and identify the test and lint commands.” That first pass is like giving a GPS time to learn the roads before asking it to reroute.

A realistic sequence is: identify a bug, ask for a repair plan, approve the plan, edit the files, run tests or linters, inspect failures, and review the Git diff. I always recommend committing first—or creating a checkpoint—before substantial changes.

Authentication and endpoint errors

Set the local Anthropic-compatible variables explicitly:

“`bash

export ANTHROPIC_API_KEY=””

export ANTHROPIC_AUTH_TOKEN=ollama

export ANTHROPIC_BASE_URL=http://localhost:11434

“`

Those values prevent an old cloud API key from taking precedence.[1] If connections fail, confirm Ollama is open or its service is running, test the local endpoint, and retry the launcher. If Claude Code reports a missing model, run `ollama list`, copy the exact tag, then pull it:

“`bash

ollama pull

“`

Tool-use and command-execution failures

A model can write plausible prose and still struggle with tools. Try a coding-focused model such as Qwen3-Coder or GPT-OSS 20B, simplify the task, and provide acceptance criteria like “run the tests and report the failing command.” Check that the model supports dependable tool calling; this is where most tutorials get too casual.

Keep Claude Code inside the intended project directory. It can execute shell commands and modify files, so never approve destructive operations automatically.

Slow responses and memory pressure

Slow output usually means the model, context, or hardware is too ambitious. Use a smaller quantized model, reduce context length, close memory-heavy applications, and prefer GPU acceleration when available.

For crashes or out-of-memory errors, lower the model size or quantization level and leave room for the operating system and KV cache. A Q4 model may be less capable than Q8, but it can be the difference between usable and unusable.

Context overflow and incomplete repository understanding

Large advertised context does not guarantee good performance. Narrow the agent’s work to a specific directory, or ask it to summarize completed work before continuing. In my experience, a short, accurate working brief often beats dumping an entire repository into one request.

Privacy and permissions checklist

Local inference keeps prompts and source code on your machine only if the endpoint stays local and installed tools or extensions do not transmit data elsewhere.[1] Protect `.env` files, SSH keys, cloud credentials, customer records, and personal data; review approvals before every command that deletes, migrates, publishes, or changes permissions.

Choose local Claude Code by checking six things: hardware, privacy requirements, acceptable speed, model quality, context needs, and willingness to troubleshoot. If you need maximum coding quality with minimal setup, cloud remains simpler; if keeping code local matters more, Ollama is a practical trade-off.

Frequently Asked Questions

Can you run the real Claude Code locally with Ollama?

Yes. Ollama can launch the genuine Claude Code CLI while routing model requests to a local Ollama server, so you keep Claude Code’s terminal, file-editing, and agent workflow instead of using a clone. For example, run `ollama launch claude`, then choose a local model such as `qwen3.5`.[2]

What is the command to launch Claude Code with Ollama?

The simplest command is `ollama launch claude`; Ollama handles the integration setup for you. If you want to choose the model yourself, configure the local endpoint and run `claude –model qwen3.5` with `ANTHROPIC_BASE_URL=http://localhost:11434`, `ANTHROPIC_AUTH_TOKEN=ollama`, and an empty `ANTHROPIC_API_KEY`.[2]

Which Ollama model is best for Claude Code on a laptop?

What I’ve found is that `qwen3.5` is a sensible starting point because it is explicitly shown in the Claude Code integration examples and is easier to run than very large models. Start with a 7B–14B coding-capable model on a typical 16–32 GB laptop; move to a larger quantized model only if response quality matters more than speed.[2]

How do I fix Claude Code authentication errors when using Ollama?

Most authentication errors come from Claude Code still seeing an Anthropic key or an old setting. Clear the key and set `ANTHROPIC_AUTH_TOKEN=ollama`, `ANTHROPIC_API_KEY=””`, and `ANTHROPIC_BASE_URL=http://localhost:11434`, then run `/status` in Claude Code to verify the connection.[2]

How much RAM or VRAM does Claude Code with Ollama need?

Claude Code itself is relatively light; the model is what determines hardware needs. As a practical baseline, allow roughly 8–16 GB of system RAM for a small 7B–14B model, while a 35B model can require around 22 GB just for a Q4 model file, so a 32–64 GB laptop is much more comfortable; 8 GB of VRAM generally means choosing a smaller or heavily quantized model.[10]

Start with a small test repository, run `ollama launch claude –model qwen3.5`, and compare the local workflow with the hosted setup before moving important projects over.

Subscribe to Fix AI Tools for weekly AI & tech insights.

O

Onur

AI Content Strategist & Tech Writer

Covers AI, machine learning, and enterprise technology trends.