OpenCode + Ollama together: run a free coding agent on your own laptop

You don't need a gaming PC to run a free, private coding agent. How to set up OpenCode and Ollama together on an 8, 16 or 32 GB laptop, which small models actually work, the settings that make or break them, and an honest look at what they can and can't do.

Three memory bars titled Will it fit? Your memory is a room. An 8 GB laptop holds the OS, browser and editor, the qwen3.5:4b model at 3.4 GB and a 16 to 32K context, with almost no room left; good for learning and small edits. A 16 GB laptop holds the OS, browser and editor, qwen3.5:9b at 6.6 GB and a 32 to 64K context, with some free space; good for everyday small tasks. A 32 GB laptop or Mac holds the OS, browser and editor, qwen3-coder:30b at 19 GB and a 64K context, with some free space; good for real multi-file work. The legend says furniture is what is already running, the worker is the model with a fixed size, and the desk is the context, which grows with use. If it doesn't fit, part of the work moves to the slow storeroom, the CPU or disk, and everything crawls.
Fig. 1 — Your memory is a room. The furniture is already there, the model is a worker of fixed size, and the context is a desk that grows as you work.

Every OpenCode tutorial seems to show it running on a huge desktop with an expensive graphics card. Most of us have an ordinary laptop. So: can you run a free, private coding agent on the laptop you already own?

Yes: put OpenCode and Ollama together, pick the right model size, and change two or three settings. This guide shows which small models work on 8, 16 and 32 GB of memory, how to set them up with OpenCode and Ollama, how to tell when something doesn’t fit, and, honestly, what a small model can and can’t do for you.

New to the pieces? What is OpenCode explains the agent, and OpenCode vs Ollama explains how the two work together. This guide is about making them fit on your machine.

The short answer

Your laptop Start with Download size Good for
8 GB memory qwen3.5:4b about 3.4 GB Learning, explaining code, small edits in one file
16 GB memory qwen3.5:9b about 6.6 GB Everyday small tasks: a method, a test, a bug fix
32 GB, or a GPU with 24 GB qwen3-coder:30b about 19 GB Real multi-file changes

All three support tools, which OpenCode needs. On 16 GB you can also try gemma4:12b (about 7.7 GB), and gpt-oss:20b (about 14 GB) if you close almost everything else first. Model lists change fast, so check the sizes on ollama.com before you download.

The picture: your memory is a room

Your laptop’s memory (RAM) is a room, and three things have to fit inside it:

  1. The furniture. Windows or macOS, your browser, your code editor. It is already there before you start, and it often takes 4 GB or more.
  2. The worker. That is the model. Its size is fixed: qwen3.5:4b always takes about the same space.
  3. The desk. That is the context window: everything the model has to look at right now, like your files, your rules and the conversation so far. The desk grows as you work, and a coding agent needs a big desk.

If everything fits in the room, the work is fast. If it doesn’t, some of it gets pushed into the storeroom: the slower CPU, or worse, the disk. The work still happens, but everything crawls.

So choosing a model is really a question of: after the furniture, is there space for the worker and a big enough desk?

Why a coding agent needs more than a chat

You may have chatted happily with a small model in Ollama. A coding agent is harder for two reasons.

It needs tools. OpenCode works by asking the model to call tools: “read this file”, “run this command”. The model must support tool calling. On ollama.com, look for the tools badge on the model page.

It needs a big desk. Every step, OpenCode sends your files, the project rules, the list of tools and the conversation so far. That fills a small desk fast. On most laptops, Ollama starts with a desk of only about 4,000 tokens, and Ollama’s own advice for coding tools is at least 64,000 when your memory allows. On a small laptop you won’t always get to 64K, but you must at least raise it from the default.

Mac, Windows or Linux: where does the model run?

The same model can feel very different on different laptops:

  • Mac with an M-series chip: the graphics chip shares the main memory (Apple calls it unified memory), so most of the 16 or 32 GB can go to the model. This is why Macs are good at local AI.
  • Laptop with an NVIDIA graphics card: the card’s own memory (VRAM, often 6 or 8 GB on laptops) is the fast part of the room. A model that fits in VRAM is quick; anything that spills over goes to the CPU and slows down.
  • Laptop with no separate graphics card: the model runs on the CPU. It works, just slowly. Stick to the 4b size here, and be patient.

Set it up, step by step

1. Install Ollama and pull a model

If you don’t have Ollama yet, follow how to run an LLM on your own computer. Then download the model for your laptop, for example:

ollama pull qwen3.5:4b

2. Make the desk bigger, and the desk cheaper

Two settings matter most:

  • Context length (the size of the desk). Aim for 32,000 on 8 GB and 64,000 on 16 GB or more.
  • A smaller cache. Ollama keeps a working copy of the desk in memory, called the KV cache. Setting it to q8_0 makes it about half the size with almost no loss in quality. It needs flash attention switched on.

The quickest way to try them is to start the Ollama server from a terminal with the settings in front:

OLLAMA_CONTEXT_LENGTH=32000 OLLAMA_FLASH_ATTENTION=1 OLLAMA_KV_CACHE_TYPE=q8_0 ollama serve

(Quit the Ollama app first, or the app’s server will already be using the port.) To make the settings permanent:

  • Ollama desktop app: move the context length slider in Settings.
  • macOS: run launchctl setenv OLLAMA_CONTEXT_LENGTH 32000 (and the same for the other two), then restart Ollama.
  • Windows: open Edit the system environment variables, add OLLAMA_CONTEXT_LENGTH, OLLAMA_FLASH_ATTENTION and OLLAMA_KV_CACHE_TYPE as user variables, then quit Ollama from the tray and start it again.
  • Linux (service install): run sudo systemctl edit ollama, add one Environment="NAME=value" line per setting under [Service], then restart the service.

3. Start OpenCode with your model

Open a terminal in your project and let Ollama set things up:

cd my-project
ollama launch opencode --model qwen3.5:4b

Or just run opencode: it finds Ollama on its own, and your local models show up when you type /models.

4. Check that it fits

While OpenCode is working, open a second terminal and run:

ollama ps

It lists each loaded model with its size in memory, the context it loaded with, and a processor column. Read the processor column like this:

  • 100% GPU: everything fits in the fast part of the room.
  • A CPU/GPU split, like 40%/60%: part of the model spilled into the storeroom. Expect it to slow down. Try a smaller context or a smaller model.
  • 100% CPU: normal on a laptop with no graphics card; on a laptop with one, it means the model didn’t fit at all.

Also check the context column. If it still says about 4,096, your context setting didn’t take effect: restart Ollama.

What small models do well, and where they struggle

Here is an honest picture of a 4b or 9b model inside OpenCode:

Works well Struggles
“Explain what this class does” “Refactor the whole project to use records”
Writing one method or one unit test Changes that touch many files at once
Fixing a clear error message Vague goals like “make it better”
Renaming, adding comments, small cleanups Long sessions with lots of back and forth
Answering questions about your code, privately Tricky bugs that need deep reasoning

The bigger qwen3-coder:30b moves a lot of the right column into the left one. It is a mixture-of-experts model: it has 30 billion weights in total but uses only about 3 billion for each word, which is why it runs faster than its size suggests, as long as you have the memory to hold it.

“A small local model is a keen junior who works for free. Give it small, clear jobs and it does them well.”

Seven tips to get good results from a small model

  1. Give small, specific tasks. “Add a discount(double rate) method to PriceCalc and a test for it” works far better than “improve pricing”.
  2. Plan first. Switch to OpenCode’s read-only Plan agent, let it propose the steps, then let Build do them one by one.
  3. Keep AGENTS.md short. Every line is sent with every step and takes up desk space. Keep it to the rules that matter.
  4. Start a new session for each new task. An old, long conversation fills the desk with things the model no longer needs.
  5. Close the heavy furniture. A browser with 40 tabs can easily eat the memory your model needed.
  6. Keep one model loaded. Switching models loads a second worker into the room. Stick to one, or set OLLAMA_MAX_LOADED_MODELS=1.
  7. Go local-first, not local-only. Use the free local model for everyday work, and when a task is too hard, connect a cloud model with /connect and switch with /models for just that task.

Try it yourself: a three-task test

Benchmarks on someone else’s machine don’t tell you much. The best test is your own laptop and your own code. Pick a small project and give OpenCode these three tasks, one per session:

  1. Explain: “Explain what PriceCalc.java does and list its public methods.”
  2. Edit: “Add a method that applies a percentage discount, with input checks.”
  3. Test: “Write a unit test for the new method and run it until it passes.”

Write down, for each task: the model, the context size, roughly how long it took, and whether it got it right without your help. Then try the next size up if your memory allows. In ten minutes you’ll know exactly what your laptop can handle, and which kinds of tasks you’ll still send to a cloud model.

Common problems and fixes

What you see Likely cause Fix
Your model is missing from /models Ollama isn’t running, or the model can’t use tools Start Ollama; pick a model with the tools badge
It forgets what it was doing halfway The context (desk) is too small Raise OLLAMA_CONTEXT_LENGTH, check with ollama ps
It prints JSON or “tool calls” as text instead of acting The model is too small or weak at tool calling Try the next size up, such as 4b → 9b
Painfully slow The model spilled to the CPU or disk Smaller context, smaller model, close other apps
Ollama crashes or runs out of memory The worker and desk don’t fit in the room Lower the context, turn on the q8_0 cache, or step down a size

Common questions

Can I really run OpenCode on 8 GB? Yes, for learning and small edits with qwen3.5:4b and a modest context. It is a good way to learn how coding agents work for free. For daily work, 16 GB is much more comfortable.

Do I need a graphics card? No, but it helps a lot with speed. Without one the model runs on the CPU: it works, just slowly. Macs with M-series chips use their shared memory and do well without a separate card.

Is it really free? Yes. OpenCode and Ollama are free, and so are the open models. You only pay for the electricity, and with a little patience.

Does my code leave my laptop? Not with a local model. Just avoid model tags that end in :cloud: those run on Ollama’s servers, not yours.

Which model is “the best”? The best one is the biggest one that fits in your room with a big enough desk. Start with the table at the top, run the three-task test, and adjust.

Key takeaways

  • Your memory is a room: the OS and apps (furniture), the model (worker) and the context (desk) must all fit, or things move to the slow storeroom.
  • Start with qwen3.5:4b on 8 GB, qwen3.5:9b on 16 GB, and qwen3-coder:30b on 32 GB or a 24 GB graphics card.
  • Raise the context length (32K to 64K) and use the q8_0 cache with flash attention to make the desk cheaper.
  • Check everything with ollama ps: you want the right context and as much on the GPU as possible.
  • Give small models small, clear tasks, plan first, and switch to a cloud model only when a task is too hard.

Next, read OpenCode vs LangChain vs Claude Code to see where a local coding agent fits among the other AI tools, or go back to what is Ollama to see how the model server works inside.

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.