How to Run Claude Code for Free with Local Models
(Ollama Setup Guide)
Don't want to figure this out alone? I walk members through every step inside the community. Join the Skool → skool.com/raycfu

WHAT THIS IS
Claude Code is Anthropic's coding tool that lives in your terminal. It reads your codebase, writes code, runs tests, debugs errors, and ships changes. Normally it costs money because it connects to Anthropic's API.
Ollama is a free tool that lets you run AI models locally on your own computer. In January 2026, Ollama added support for the Anthropic Messages API, which means you can now point Claude Code at a local model running on your machine instead of paying for the Anthropic API.
The result: Claude Code running for free, completely offline, with your code never leaving your computer.
The tradeoff: local models are not as smart as Anthropic's top models like Opus or Sonnet. But for learning Claude Code, building demos, writing boilerplate, scaffolding projects, and doing quick fixes, they are more than good enough. And when you hit API rate limits on your paid plan, you can switch to local and keep working instead of waiting.
WHAT YOUR COMPUTER NEEDS
This is important. Local models eat memory. If your machine cannot handle it, the experience will be painfully slow.
32GB RAM or more: This is the sweet spot. You can run the best local coding models comfortably and the experience is actually usable.
16GB RAM: You can run smaller models but expect it to be rough. More wrong answers, more retries, slower overall.
8GB RAM: You will struggle. The system will push into swap memory and everything slows to a crawl. Not recommended.
If you are on a Mac with Apple Silicon (M1, M2, M3, M4), the unified memory architecture helps a lot. A 32GB M-series Mac handles local models very well.
If you are on a PC, a dedicated NVIDIA GPU with 16GB or more VRAM (like an RTX 3090 or 4090) makes a huge difference. CPU-only setups work but are significantly slower.
You also need Node.js 18 or later installed on your machine.
STEP 1: INSTALL OLLAMA
Ollama is the engine that runs the AI model on your machine. Go to ollama.com and download the installer for your operating system.
On Mac: Download the app from ollama.com, open it, and it installs itself. It runs quietly in the background.
On Windows: Download the installer from ollama.com and follow the on-screen instructions.
On Linux: Open your terminal and run this:
curl -fsSL https://ollama.com/install.sh | sh
After installation, open a terminal and verify it is working:
ollama --version
You should see a version number. If you get an error, the Ollama service might not be running yet. Start it manually with:
ollama serve
Ollama runs as a background service on port 11434. You can confirm it is running by visiting http://localhost:11434 in your browser.
STEP 2: PICK AND DOWNLOAD A MODEL
Not every model works well with Claude Code. Claude Code sends a massive system prompt (around 16,000 tokens) and requires tool-calling support, which means you need a model that can handle large context windows and function calls.
Here are the models that actually work well as of 2026, ranked by quality:
FOR POWERFUL MACHINES (32GB+ RAM or good GPU):
qwen3-coder (recommended for most people) The current community favorite for local coding. Strong reasoning, good tool support, handles complex tasks.
To download: ollama pull qwen3-coder
glm-4.7-flash Very fast, 128K context window, solid tool-calling support. Great if you want speed over raw intelligence.
To download: ollama pull glm-4.7-flash
devstral (24B parameters) Strong coding model, works well on Mac M-series with 32GB.
To download: ollama pull devstral
FOR LESS POWERFUL MACHINES (16GB RAM):
qwen2.5-coder:7b Smaller model that still handles basic coding tasks. Good starting point if your hardware is limited.
To download: ollama pull qwen2.5-coder:7b
After downloading, test that the model works:
ollama run qwen3-coder
Type a simple question like "write a hello world in Python" and make sure you get a response. Press Ctrl+D to exit the chat. If this works, your model is ready.
STEP 3: INSTALL CLAUDE CODE
If you do not have Claude Code installed yet, install it from your terminal.
On Mac or Linux:
curl -fsSL https://claude.ai/install.sh | bash
On Windows (Command Prompt):
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
After installation, verify it works:
claude --version
STEP 4: CONNECT CLAUDE CODE TO YOUR LOCAL MODEL
This is the key step. You need to tell Claude Code to talk to your local Ollama server instead of Anthropic's API. There are two ways to do this.
OPTION A: THE QUICK WAY (ollama launch)
This is the simplest method. Ollama has a built-in command that handles everything for you:
ollama launch claude --model qwen3-coder
That is it. Ollama sets up the connection, launches Claude Code, and points it at your local model. You can replace qwen3-coder with whatever model you downloaded.
If you want it to auto-pull the model and skip the selection menu:
ollama launch claude --yes --model qwen3-coder
OPTION B: THE MANUAL WAY (environment variables)
If the launch command does not work on your version of Ollama, or if you want more control, you can set the environment variables yourself.
On Mac or Linux, add these to your terminal before running Claude Code:
export ANTHROPIC_BASE_URL="http://localhost:11434" export ANTHROPIC_AUTH_TOKEN="ollama" export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
Then start Claude Code:
claude
On Windows (PowerShell):
$env:ANTHROPIC_BASE_URL = "http://localhost:11434" $env:ANTHROPIC_AUTH_TOKEN = "ollama" $env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"
Then run:
claude
The CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC variable stops Claude Code from trying to send telemetry or check for updates over the internet. This keeps everything fully local.
MAKING IT PERMANENT
If you do not want to type those environment variables every time, you can add them to your shell profile.
On Mac or Linux, add the three export lines to your ~/.bashrc or ~/.zshrc file. Then run "source ~/.bashrc" or "source ~/.zshrc" to apply them.
Alternatively, you can put them in your Claude Code settings file. Create or edit ~/.claude/settings.json:
{ "env": { "ANTHROPIC_BASE_URL": "http://localhost:11434", "ANTHROPIC_AUTH_TOKEN": "ollama", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" } }
This way the settings persist across sessions without touching your shell profile.
STEP 5: VERIFY EVERYTHING IS WORKING
Once Claude Code starts, you should see it connect to your local model. Run a simple test:
Navigate to any project folder:
cd ~/my-project
Start Claude Code:
claude (or ollama launch claude --model qwen3-coder)
Run the /init command. Claude Code will scan your codebase and set itself up.
Give it a simple task: "write a Python function that reverses a string"
If you get a response, everything is working. Your code is being processed entirely on your machine.
To double-check that nothing is going to the internet: disconnect from WiFi and run another prompt. If you still get a response, you are fully offline.
STEP 6: CHECK YOUR PERMISSIONS
This trips people up. By default, Claude Code running with local models may have most permissions denied. If it cannot see your files or run commands, you need to fix this.
Inside Claude Code, type:
/permissions
Make sure the basic tools are allowed: Read, Write, Edit, Bash. If they are denied, add them to your allow list. You can do this in the /permissions menu or by editing your .claude/settings.json file.
WHICH MODEL SHOULD YOU ACTUALLY USE
Here is the honest breakdown based on community testing:
qwen3-coder: Best overall for coding. Strong reasoning, handles multi-step tasks, good tool support. This is what most people should start with if their hardware can handle it.
glm-4.7-flash: Fastest option. 128K context window means it can handle large codebases. Slightly less smart than qwen3-coder but much faster.
qwen2.5-coder:7b: Best for limited hardware. Runs on 16GB RAM. Gets the basics done but struggles with complex multi-file tasks.
devstral: Strong alternative to qwen3-coder. Works particularly well on Mac M-series machines.
If you are not sure, start with qwen3-coder. If it is too slow on your machine, drop down to glm-4.7-flash or qwen2.5-coder:7b.
WHAT LOCAL MODELS ARE GOOD AT
Reading and explaining code. Point it at an unfamiliar file and ask what is going on. It gives you clear breakdowns. This works very well even with smaller models.
Writing boilerplate. Helper functions, form handlers, utility files, simple components. The output is usable with minimal edits.
Scaffolding projects. Setting up a new project structure, creating starter files, configuring basic setups. This is where local models save you real time.
Quick fixes between rate limits. When your paid Anthropic credits run out mid-session, switch to local and keep working on smaller tasks instead of waiting.
WHAT LOCAL MODELS ARE NOT GREAT AT
Complex multi-file refactoring. They lose track of dependencies and context across many files. If you need serious architectural changes, use the real Anthropic API.
Getting things right on the first try. Expect more iterations than you would with Opus or Sonnet. The model will get close, you fix the last 10 to 20 percent.
Speed on CPU-only machines. A simple "hello" prompt can take 30 to 60 seconds on CPU. With a GPU or Apple Silicon it is much faster, usually a few seconds.
Large context handling. Even though some models advertise 128K context, the practical limit on consumer hardware is lower. Very large codebases will be slow.
HOW TO SWITCH BETWEEN LOCAL AND PAID
You do not have to pick one forever. The best workflow is to use both.
Use the Anthropic API (Opus, Sonnet) for heavy lifting: complex features, multi-file changes, architectural decisions.
Use local models for everything else: quick fixes, boilerplate, explanations, learning, and keeping momentum when you hit rate limits.
To switch back to the Anthropic API, just unset the environment variables:
unset ANTHROPIC_BASE_URL unset ANTHROPIC_AUTH_TOKEN
Or remove the env section from your ~/.claude/settings.json and restart Claude Code.
TROUBLESHOOTING
"Connection refused" error: Ollama is not running. Start it with "ollama serve" in a separate terminal window.
"Model not found" error: Check what models you have downloaded with "ollama list" and make sure you are using the exact model name.
Claude Code cannot see your files: Check /permissions inside Claude Code. Make sure Read, Write, Edit, and Bash are in the allow list.
Very slow responses: This is expected on CPU-only machines. If you have a GPU, make sure Ollama is using it. On NVIDIA, check with "nvidia-smi" to see if the model is loaded on the GPU.
Model keeps giving wrong answers: Try a larger model if your hardware can handle it. The 7B models are limited. Moving to 24B or 30B makes a noticeable difference in code quality.
JSON-only output: Some models default to JSON formatting. Try a different model or add instructions in your prompt to respond in plain text.
"Unknown command: launch": Your Ollama version is too old. Update to v0.14.0 or later. Or use the manual environment variable method instead.
You just read the full playbook. Most people will close this tab and never implement it. The ones who do usually hit a wall around the technical setup and quit.
Inside the Skool, I walk you through the exact build step-by-step, troubleshoot your setup live in the community, and share the scripts and templates I use to actually land paying clients.
If you want the shortcut instead of the long way around:
