Ollama: Run AI Models Free on Your Laptop and Use Them in Claude Code
Install Ollama, download a free model like Gemma 4, chat with it offline, then run Claude Code on it with one command. Beginner guide, about 20 minutes.

Ollama lets you download open AI models like Gemma, DeepSeek, Kimi or Llama and run them on your own computer, with no API bill and no internet once the model is downloaded. By the end of this guide you’ll have a model chatting in your terminal and Claude Code running on top of it.
It takes about 20 minutes plus download time. You need a Mac, Windows or Linux computer with enough memory for the model (more on that below).
What you’re building
Ollama is a free, open-source app (MIT license, 182k+ GitHub stars) that downloads AI models and runs them locally. Its GitHub description lists Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen and Gemma, and the full catalogue is at ollama.com/library.
Once a model is downloaded, Ollama serves it from your machine at localhost:11434. Any app that speaks to that address can use it, and Claude Code is one of them:
ollama pull <model> → model saved on your disk → ollama launch claude → Claude Code on that model
Running locally also means your prompts stay on your computer. The Ollama FAQ says it plainly: “Ollama runs locally. We don’t see your prompts or data when you run locally.”
Before you start: the honest catch
- You need good RAM. A model lives in your computer’s memory while it runs. The default Gemma 4 download is 6.6 to 9.5 GB, and the docs’ own example shows it using 9.6 GB of memory once loaded. Smaller models exist, such as
gemma4:e2bat 4.6 to 7.5 GB. - Local models are not Claude. A model that fits on a laptop is less capable than the cloud model behind a Claude subscription. It’s great for practice, small tasks and private work, and weaker on big codebases.
- Not every model works with Claude Code. Claude Code needs a model that supports “tools” (the ability to run commands and edit files). Gemma 4 has it. The original Llama 3 does not, so it’s fine for chatting but not for Claude Code. The tools filter on Ollama’s site lists the ones that do.
- Downloads are big. Models range from a few GB to hundreds of GB, and they’re stored in
~/.ollama/modelson a Mac.
Step 1: Install Ollama
Pick your system and paste the command from the Ollama README into a terminal.
macOS or Linux:
curl -fsSL https://ollama.com/install.sh | sh
Windows (PowerShell):
irm https://ollama.com/install.ps1 | iex
You can also download the app from ollama.com/download. On a Mac it needs macOS Sonoma (14) or newer.
Check it worked:
ollama --version
If you see a version number, Ollama is installed.
Step 2: Download a model and chat with it
The README’s starter model is Gemma 4. One command downloads it and opens a chat:
ollama run gemma4
The first run downloads the model, so give it a few minutes. When you see a >>> prompt, type a question and press Enter. Type /bye to exit.
To download a model without opening a chat, use pull. To see what you have:
ollama pull gemma4
ollama list
To try others, copy the name from ollama.com/library, for example ollama run llama3 for Meta’s Llama 3.
How to check it’s really local: turn off Wi-Fi and ask another question. It still answers.
Step 3: Give the model enough context for coding
Context length is how much text the model can keep in mind at once. Ollama’s default is small (4k tokens on machines with less than 24 GiB of graphics memory), and the docs say coding tools need at least 64,000.
The easy way is the slider in the Ollama app’s settings:

Or set it from the terminal when you start the server:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
A bigger context uses more memory. To check what you got, run ollama ps while a model is loaded. It shows the model’s size, its context length, and whether it runs on your GPU or CPU.
The same settings window has an Airplane mode toggle. It keeps your data local by turning off Ollama’s cloud models and web search.
Step 4: Run Claude Code on your local model
Open a terminal in your project folder and run:
ollama launch claude
If Claude Code isn’t installed yet, Ollama offers to install it. Then it asks you to choose a model. Pick a local one with tools support, like gemma4.
The docs suggest a first prompt to try:
Explain how this repository is organized.
How to check it worked: Claude Code answers about your files, and ollama ps in another terminal shows the model loaded.
Troubleshooting
ollama is not found
Close and reopen your terminal. On a Mac, open the Ollama app once: it checks that the ollama command is on your PATH and offers to add it.
Answers are very slow
The model may not fit in your graphics memory and is partly running on the CPU. Run ollama ps and look at the PROCESSOR column. 100% GPU is fastest. Try a smaller model such as gemma4:e2b, or lower the context length.
Claude Code forgets things or gives up on big tasks
The context is probably still at the small default. Set it to 64k (Step 3). On large repositories the docs recommend 64k or higher.
Claude Code can’t edit files with my model
The model likely doesn’t support tools. Switch to one listed under the tools filter, such as gemma4.
What else you can do with it
ollama launch codexandollama launch opencodeconnect other coding agents the same way.- Ollama also offers cloud models for bigger jobs (for example
gemma4:cloud). These run on Ollama’s servers, so they’re no longer offline. Turn on Airplane mode, or setOLLAMA_NO_CLOUD=1, if you want local only. - Apps and scripts can talk to Ollama directly at
http://localhost:11434. The README has examples for Python and JavaScript.
Full documentation: docs.ollama.com.
Quick recap
- Install Ollama with the one-line installer or the app.
- Run
ollama run gemma4to download a model and chat with it. - Set the context length to 64k in settings, or with
OLLAMA_CONTEXT_LENGTH=64000 ollama serve. - Run
ollama launch claudein your project and pick a local model with tools support. - Use
ollama psto check memory, context and GPU use.