Cindy Zhu.
Free guides
Building Claude

Run Claude Code on a free local model

Hey, it's Cindy ๐ŸŒฑ You commented LOCAL, so here is the real setup: Ollama, a coding model, one setting almost everyone gets wrong, and two environment variables.
btw the waitlist for AI System Club is now open! If you're keen on using AI to automate your content, video editing, job search, business or build AI agents, feel free to sign up (only if you want to hehe). Ps. the waitlist gets first dibs:)
Read this before you start, because the headline is doing some work. This does not give you Claude for free. What you get is Claude Code, the terminal tool, driving an open-weight model running on your own laptop. The tool is free, the model is free, and the model is not Claude. Anthropic's setup docs say Claude Code needs a paid plan or a third-party API provider, and pointing it at Ollama is that third-party route, so no Claude subscription is involved. Expect noticeably weaker reasoning than Sonnet or Opus, especially on multi-file work. Set that expectation now and you will enjoy this a lot more.
the trade

What you get, and what you give up

You get: no bill No API charges and no subscription for this route. Ollama is free, the models are open weights, and Claude Code is free to install. Practising the agentic loop for eight hours costs you electricity.
You get: your files stay put Prompts and code go to a model running on your own machine, not to a provider. For work you are not allowed to send anywhere, that is the whole point of the setup.
You give up: capability A 30B open model is a solid assistant and it is not close to a frontier model on long agentic tasks. Expect more wrong turns, weaker planning, and more supervision from you.
You give up: speed "No rate limits" means no provider is throttling you. Your laptop still is. On consumer hardware expect a slow, steady stream of tokens rather than the pace you are used to.
๐Ÿ’ก The setup got much simpler in 2026. Ollama added a native Anthropic-compatible Messages endpoint in v0.14.0, so Claude Code talks to it directly. Older guides that tell you to install a translation proxy or a router are out of date, and you can ignore them.

reality check

Can your machine actually run this?

This is the question the short videos skip, and it decides whether you have a good afternoon or a frustrating one. A model has to fit in memory, and on a Mac that is unified memory shared with everything else you have open. Sizes below are the real download sizes from Ollama's library, and you want headroom on top for the context window.

16GB, tight Run qwen2.5-coder:7b (4.7GB) or gpt-oss:20b (14GB, which Ollama lists as running on as little as 16GB). Fine for single-file edits and learning the tool. It will struggle with anything that spans a whole project.
24GB, workable qwen2.5-coder:14b (9.0GB) is comfortable here and leaves room for a bigger context window. This is the point where the agent loop starts feeling useful rather than like a demo.
32GB or more, the sweet spot qwen3-coder:30b (19GB) is the model to want. It is a 30B model with about 3.3B parameters active per token, so it punches above what its size suggests while staying loadable on a laptop.
What is out of reach qwen3-coder:480b is a 290GB download and Ollama states it needs at least 250GB of memory. That is server hardware. Nothing you can do with settings makes it fit on a laptop.
โš ๏ธ Free disk space matters as much as memory. Models are downloaded and kept, so budget 20GB or more per coding model you try. If you pull three to compare, that is most of a 60GB dent in your drive.

step one

Install Ollama

  1. โฌ‡๏ธ Download it. Go to ollama.com/download and grab the installer for macOS or Windows. It installs like any normal app and puts a small icon in your menu bar or system tray.
  2. ๐Ÿง On Linux, one line instead. Run curl -fsSL https://ollama.com/install.sh | sh in your terminal. The quickstart covers the variations.
  3. ๐Ÿ”ข Check your version is 0.14.0 or newer. Run ollama --version. The Anthropic-compatible endpoint that makes this whole thing work arrived in v0.14.0, so on anything older Claude Code will not connect. Update from the releases page if you are behind.
  4. โœ… Confirm it is listening. Ollama runs a local server on port 11434. Open localhost:11434 in a browser and you should see the words "Ollama is running". If you do not, open the Ollama app so the server starts.

step two

Pull a coding model

Pick one from the hardware table above and pull it. The download is large and one-time, so start it and go make a coffee.

ollama pull qwen3-coder:30b

# smaller machines
ollama pull qwen2.5-coder:14b
ollama pull qwen2.5-coder:7b

# Ollama's own general-purpose suggestion
ollama pull gpt-oss:20b
  1. ๐Ÿ“š Check the model page before you commit. Every model has its own page in Ollama's library with the exact tags and sizes: qwen3-coder, qwen2.5-coder, gpt-oss. Tags matter, because qwen3-coder with no tag pulls the 30B build.
  2. ๐Ÿ’ฌ Test it on its own first. Run ollama run qwen3-coder:30b and ask it something. If it is unusably slow here, in a plain chat with no tools, it will be worse inside an agent loop. Better to find that out now than after three more setup steps.
  3. โ˜๏ธ Know what the cloud tags are. Models with a -cloud suffix run on Ollama's servers, not your machine. They are useful and they are neither local nor part of the free setup described here, so leave them alone if the point is privacy or zero cost.

step three, the one people miss

Raise the context window

This is the step that separates a working setup from one where Claude Code behaves strangely, forgets the file it opened two messages ago, or loops. Ollama picks a default context length from your available GPU memory, and per its context length docs that default is 4k tokens on machines with under 24GiB. Claude Code loads a large system prompt plus your files plus a running conversation, so 4k is nowhere near enough.

  1. ๐ŸŽš๏ธ In the Ollama app, move the slider. Open Ollama's settings and set the context length to at least 32k. Ollama's own recommendation for this setup is a model running with at least 32K tokens of context.
  2. โŒจ๏ธ Or set it when you start the server. If you run Ollama from the terminal, use OLLAMA_CONTEXT_LENGTH=32768 ollama serve. Bump it to 65536 if your machine has the memory spare.
  3. ๐Ÿงฎ Remember it costs memory. A bigger context window needs more memory on top of the model itself. If your machine starts swapping and everything crawls, drop back to a smaller model rather than a smaller context, because a small context breaks the tool outright.

step four

Install Claude Code and point it at Ollama

  1. ๐Ÿ“ฆ Install Claude Code. On macOS, Linux or WSL run curl -fsSL https://claude.ai/install.sh | bash. On Windows PowerShell run irm https://claude.ai/install.ps1 | iex. Homebrew (brew install --cask claude-code) and WinGet also work, and all the options are in the setup docs.
  2. ๐Ÿ”‘ Set the two environment variables. These are what redirect Claude Code away from Anthropic's servers and at your local Ollama. The token is required by the tool but not checked by Ollama, so the literal word "ollama" is fine.
  3. ๐Ÿš€ Launch it with your model. Pass the model name with --model, using exactly the tag you pulled.
  4. โšก Or use the shortcut. Ollama ships a helper that sets all of this for you: run ollama launch claude and it opens Claude Code already wired to your local server.
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434

claude --model qwen3-coder:30b
๐Ÿ“Œ Make it stick, or keep it temporary on purpose. Those two lines last only for that terminal window. That is often what you want, so a plain claude in a different window still uses your normal setup. If you would rather have it permanent, add the two export lines to ~/.zshrc on a Mac. On Windows PowerShell use $env:ANTHROPIC_AUTH_TOKEN="ollama" and $env:ANTHROPIC_BASE_URL="http://localhost:11434".

step five

The five-minute honesty test

Before you decide this replaces anything, give the local model a real task and watch how it handles being wrong. Open Claude Code in a small practice folder and paste this in. It is deliberately a task with a trap in it, because a smooth answer to an easy question tells you nothing.

โœ… test whether your local model is good enough
Before you write any code, tell me your plan in five lines or fewer, and tell me which part of it you are least confident about.

Then build me a small command line tool in Python that reads every .txt file in a folder I give it, counts how often each word appears across all of them, and writes the top 20 words to a CSV. Handle the cases where the folder does not exist, where it contains no .txt files, and where a file is not valid UTF-8, and do not let any of those crash the program.

When you are finished, create three test files yourself, run the tool against them, and paste the actual output back to me. If the output is wrong, fix it and run it again rather than telling me it should work.

Finally, tell me honestly what you would do differently with more capability, and name anything in this task you found difficult.
๐ŸŒฑ What you are watching for: does it make a plan, does it actually run the thing, and does it notice its own mistakes. A model that writes plausible code but never verifies it is fine for drafting and a poor fit for agentic work. That is the honest dividing line, and it tells you which jobs to send where.

the fine print

What does not work through the local endpoint

Ollama's compatibility layer covers the Messages API, and it does not cover everything Anthropic's own API offers. These gaps are listed in Ollama's Anthropic compatibility docs, and they explain most of the odd behaviour people run into.

  • No prompt caching. Every request reprocesses the system prompt and the conversation from scratch, which is a big part of why long sessions feel slower and slower.
  • The tool_choice parameter is ignored. When Claude Code wants to force a specific tool call, the local endpoint does not honour it, so tool use is less reliable.
  • No token counting endpoint, and the token counts you do see are approximations from the model's own tokenizer rather than exact figures.
  • No PDF support, and no image URLs. Base64 images work, images referenced by URL do not.
  • Extended thinking is basic. A thinking budget is accepted but not enforced, so do not rely on it to control depth.
  • No batches API and no request metadata. Neither matters much for everyday use, and both matter if you were planning to script around it.

be precise about this

The privacy claim, stated accurately

Your prompts and your code go to a model process on your own machine, and no provider sees them. That is real and it is the strongest reason to run this setup. It is not the same as being fully offline, though. Claude Code checks for updates in the background and makes other network calls, which Anthropic documents in its network configuration page. If you need something genuinely airtight, turn off auto-updates with the DISABLE_AUTOUPDATER setting listed in the environment variables docs, and confirm the behaviour on your own network before you trust it with anything sensitive.


the actual verdict

When local is worth it, when to switch back

Worth it: learning the loop Getting fluent with Claude Code takes hundreds of small experiments, and doing those on a local model costs nothing. Learn the tool here, then bring the habit to a frontier model.
Worth it: files that cannot leave Client data, personal records, anything covered by a policy you would rather not test. A local model is the only version of this that is genuinely defensible.
Switch back: real builds Anything spanning many files, anything where a subtle bug costs you a day, anything you are shipping. The capability gap shows up exactly where the stakes are.
Switch back: when you are stuck If you have gone three rounds and it is still circling, the model is the bottleneck, not your prompt. Switching costs one command, and staying stubborn costs an evening.
๐Ÿ“Œ Switching back is one line: open a fresh terminal window without those two exports set, and claude runs on your normal setup again. Nothing you did here is permanent or hard to undo.

Sources

Ollama, Anthropic API compatibility: the env vars and the full list of gaps
Ollama's announcement of Claude Code support and the recommended models
Ollama, context length defaults by available memory and how to change them
Qwen3-Coder in the Ollama library: tags, sizes and memory requirements
Qwen2.5-Coder in the Ollama library: every size from 0.5b to 32b
gpt-oss in the Ollama library, including the 16GB memory note
Anthropic, Claude Code setup: install commands, requirements and authentication
Anthropic, network configuration: what Claude Code connects to

the waitlist is now open

AI System Club is launching soon

Build AI systems with me through recorded lessons you can follow at your own pace. Join the waitlist for first access and the founding price.

btw this list gets first dibs
the moment doors open :)