IntermediateClaudeBuilding
How to Use Claude Code for Free With Ollama (Local Models)
Searching "how to use Claude Code for free with Ollama"? Here's the honest version: Anthropic's free plan doesn't include Claude Code, but Ollama can run a free open model on your own computer and plug it straight into the Claude Code app with one command, ollama launch claude. You don't pay Anthropic or Ollama a cent. The one setting most people miss is the 64k context window, so this guide covers that, then has your new free agent build a silly Excuse Generator web page. Written from Ollama's and Anthropic's official docs on November 16, 2026, and tested on a real run on a Linux machine the same day.
What you'll make: Claude Code running free on your computer with a local Qwen 3.5 model, plus a one-page Excuse Generator website it builds for you.
- Time
- About 45 minutes
- Checked
If a button name on the screen does not match this guide, follow the action. These products rename buttons often.
Steps
What you'll make (and what "free" means here)
Claude Code, Anthropic's coding agent, running in your terminal for $0, powered by a free open model that runs on your own computer through Ollama. To prove it works, you'll have it build a tiny "Excuse Generator" web page you can open in your browser and show someone.
Be clear on the trade: you are using the Claude Code app, but not Claude the AI model. The thinking is done by an open model (Qwen 3.5 in this guide). It's free and private, but slower and less capable than Claude. Anthropic's own docs say it "doesn't support routing Claude Code to non-Claude models through any gateway," so this is Ollama's setup, not an official Anthropic one.
Checked November 16, 2026:
- Normal Claude Code is not free. Anthropic's setup page says "The free claude.ai plan does not include Claude Code access."
- Local models in Ollama cost $0. Ollama's pricing page lists "Pay as you go: $0" with "Run models locally" and "No subscription."
- Ollama's cloud models are not free. They're billed per token, so this guide sticks to local ones.
I wrote these steps from Ollama's and Anthropic's official docs on November 16, 2026, then tested them on a real run on a Linux machine the same day. The notes below include what actually happened, and the fix for each hiccup. The Mac and Windows Settings slider wasn't part of that run, so if a menu looks a bit different there, follow the action.
Words you'll see:
- Local model: an AI model downloaded to your computer. Nothing you type leaves your machine.
- Ollama: a free app that downloads and runs open models, and can pretend to be Anthropic's API so Claude Code can talk to it.
- Context window (context length): how much text the model can keep in mind at once, measured in tokens (roughly word pieces).
- Terminal: the text window where you type commands (Terminal on Mac, PowerShell on Windows).
Install Ollama and download a model
- Download Ollama from ollama.com/download and install it. On Windows it then runs in the background.
- Open a terminal and download the model:
ollama pull qwen3.5That's the 9B version, about 6.6 GB. Ollama's library lists it with tools support, which Claude Code needs, and a 256K context window.
Smaller computer? Use
qwen3.5:4binstead (about 3.3 GB). It's faster but makes more mistakes. Wherever this guide saysqwen3.5, typeqwen3.5:4b.Turn the context window up to 64k (don't skip this)
This is the step most people miss. Ollama's docs say coding tools "should be set to at least 64000 tokens," but Ollama picks a smaller default based on your graphics memory (VRAM): just 4k below 24 GiB, which is most laptops. Claude Code sends a lot of instructions with every request, so at 4k it forgets what it's doing.
- Ollama app (Mac or Windows): open Ollama's Settings and drag the context length slider to 64k.
- Linux has no Settings slider. On Linux, or on the command line anywhere, stop Ollama and start it with a bigger context:
OLLAMA_CONTEXT_LENGTH=64000 ollama serveFor a systemd install, run
sudo systemctl edit ollama, add this Environment line, then restart the service:Environment="OLLAMA_CONTEXT_LENGTH=64000"After you launch Claude Code and the model is loaded, check that the setting took:
ollama psThe CONTEXT column should show 64000. That's what we saw on the real run.
A bigger context uses more memory. If your computer crawls, switch to the smaller model before you lower the context.
Launch Claude Code with one command
- Make an empty folder for your project and go into it:
mkdir excuse-generator cd excuse-generator- Before you launch, raise Claude Code's idle timeout. On our first run, the local model went quiet while it wrote the whole file, and Claude Code gave up with "API Error: The response stopped arriving":
export CLAUDE_STREAM_IDLE_TIMEOUT_MS=1800000In Windows PowerShell, set the same variable with
$env:CLAUDE_STREAM_IDLE_TIMEOUT_MS="1800000". 3. Launch Claude Code through Ollama:ollama launch claude --model qwen3.5Ollama's docs say it offers to install Claude Code if you don't have it yet. Say yes. When Claude Code opens, it's talking to the model on your computer, not to Anthropic. You may also see a warning that model "qwen3.5" isn't recognized; that's harmless, and it still worked on our run. 4. If it asks whether you trust the folder, choose Yes. The trust prompt defaults to No, so you have to pick Yes yourself. 5. Type
/statusinside Claude Code to check the connection.Prefer to set it up by hand? Install Claude Code from Anthropic (
curl -fsSL https://claude.ai/install.sh | bashon Mac or Linux,irm https://claude.ai/install.ps1 | iexin Windows PowerShell), then run this on Mac or Linux (set the idle timeout first, the same as above):export CLAUDE_STREAM_IDLE_TIMEOUT_MS=1800000 export ANTHROPIC_AUTH_TOKEN=ollama export ANTHROPIC_API_KEY="" export ANTHROPIC_BASE_URL=http://localhost:11434 claude --model qwen3.5The token
ollamais a placeholder. Ollama's docs say it's "required but ignored" by the local server.Build the Excuse Generator
Paste the prompt below into Claude Code. Local models are slower than Claude, so give it a few minutes. The file-approval prompt may never appear if Claude Code is already in auto mode; if it does ask, read each request and approve it.
When it finishes, open
index.htmlfrom yourexcuse-generatorfolder in your web browser and click the button a few times. Then check the page: on our run, qwen3.5 (9B) made 10 options per part instead of the 15 the prompt asked for, so look at the output and re-ask if something is short or off. Then try one fix, like "make the button bigger and add a confetti burst when I click it."Prompt to paste
Build a single-page "Excuse Generator" website in this folder. Put everything in one file called index.html (HTML, CSS and JavaScript together, no libraries, no internet needed). It has a big title, a big button that says "Give me an excuse", and an area that shows a random, silly excuse for being late, built from three parts: a who ("My neighbor's goat"), an action ("ate"), and a what ("my car keys"). Include at least 15 options for each part. Bright colors, works on a phone screen too. When you're done, tell me exactly how to open it.If it doesn't work
Fixes from our real run, plus Ollama's and Anthropic's docs:
- "API Error: The response stopped arriving" and a broken or half-written page: this happened twice on our first run. Claude Code gives up when streamed output stops for too long while the local model writes the whole file. Fix: quit, run
export CLAUDE_STREAM_IDLE_TIMEOUT_MS=1800000, launch again, and retry the prompt. On the second try, prompt to a finishedindex.htmltook about 1.5 minutes. - The trust prompt defaults to No: move down and choose Yes.
- No file-approval prompt: that's normal if Claude Code is already in auto mode. Check the folder for the files it wrote.
- Fewer options than you asked for: qwen3.5 (9B) made 10 options per part instead of the 15 we requested. Check the output and re-ask it to add more or fix what's off.
- Claude Code still asks you to log in, or uses your paid Claude plan: Ollama's docs say "Claude settings can override shell variables." Check your Claude Code settings for an old base URL or credentials, fix them, and run
/statusagain. Anthropic notes that setting onlyANTHROPIC_BASE_URLwithout a token keeps your saved claude.ai login active, so setANTHROPIC_AUTH_TOKENtoo. - It forgets the task, loops, or gives up halfway: the context is too small. Run
ollama psand check the CONTEXT column says at least 64000. Ollama's docs say to also check PROCESSOR: "100% GPU" is fastest; a CPU split means it's spilling into slower memory. - "API error" or the model can't use tools: pick a model whose Ollama library page lists tools. Qwen 3.5 does.
- It's painfully slow: try
qwen3.5:4b, and close other heavy apps. That's the price of free. - Web search doesn't work: Ollama's docs say Claude Code's hosted web search isn't fully supported through Ollama. Paste the info in yourself.
- "API Error: The response stopped arriving" and a broken or half-written page: this happened twice on our first run. Claude Code gives up when streamed output stops for too long while the local model writes the whole file. Fix: quit, run
Ideas to try next
You've got a free, private coding agent on your own computer. A few more to try:
- Turn it into a game. Ask it to make the Excuse Generator keep score of the silliest excuse, voted by your family.
- Make a party tool. A random "who does the dishes" picker or a countdown to a birthday, all in one HTML file.
- Learn the real thing next. See Get started with Claude Code for the paid, Claude-powered version and handy habits like CLAUDE.md.
- Build a helper of your own. Try Build your first AI agent with tool use.
- Connect your tools. When you're ready, Build an MCP server shows how agents plug into other apps.
Tips
64k context or it falls apart. Ollama's docs say coding tools need at least 64000 tokens; the default on most laptops is 4k. On Linux there is no Settings slider: start the server with
OLLAMA_CONTEXT_LENGTH=64000and confirm withollama ps.Set the idle timeout before you launch.
export CLAUDE_STREAM_IDLE_TIMEOUT_MS=1800000stopped the 'response stopped arriving' error on our real run, and the page finished in about 1.5 minutes.Pick a model with tools support. Claude Code edits files and runs commands through tools, so the model has to support them.
Check the output, and don't wait forever for an approval prompt. The file-approval prompt may never appear in auto mode. On our run, qwen3.5 (9B) also made 10 options per part instead of 15, so re-ask if needed.
Free means local. Ollama's cloud models are billed per token; stick to models you've pulled to your computer.
These steps were tested on a real Linux run on November 16, 2026. The Mac and Windows Settings slider, and the manual launch commands, are still from the official docs, so if something differs there, follow the current docs linked above.
Common questions
Can you use Claude Code for free?
Not with Claude's own models: Anthropic says the free claude.ai plan doesn't include Claude Code. But you can run the Claude Code app for $0 by pointing it at a free local model through Ollama, as this guide shows. You get Claude Code's tools with an open model doing the thinking.
Is this still Claude?
It's Claude Code, the app, but not the Claude model. An open model such as Qwen 3.5 answers instead, so expect slower, less polished results. Anthropic doesn't support or endorse routing Claude Code to non-Claude models.
Do I need an Ollama account?
Not for local models. Ollama's quickstart says to sign in only if you want cloud models, and those are billed per token.
Does it work on Windows?
Yes. Ollama has a Windows app, and Claude Code installs natively on Windows 10 1809 or later from PowerShell. Run the same ollama launch claude --model qwen3.5 command in PowerShell.
Which model should I use?
Start with qwen3.5 (about 6.6 GB). If your computer struggles, use qwen3.5:4b (about 3.3 GB). Whatever you pick, its Ollama library page should list tools support.
More guides
BeginnerClaudeDocuments
Explain a bill or official letter
Paste a bill or letter into free Claude and get plain English, the deadline, and what is actually being asked.
About 10 minutes using Claude
BeginnerClaudeWriting
Write a clear email
Tell free Claude who you are writing to and what you need. You get a short draft, and you send it yourself.
About 8 minutes using Claude
BeginnerClaudeWriting
Rewrite resume bullets from real work
Ask free Claude for three resume bullets that use only the facts you provide, with blanks where a number is missing.
About 12 minutes using Claude