How to Run a Small LLM on Your Laptop for Offline Coding

A small LLM for offline coding runs entirely on your laptop, with no API key, no monthly bill, and no code leaving your machine. You ask a question, the model answers from your own hardware, and nothing travels to a server. That sounds like a small thing until you work on a client codebase under NDA, on a plane, or on hotel Wi-Fi that drops every ten minutes. Then local stops being a hobby and becomes the only setup that works.

The catch is that a laptop is not a data center. A model that writes decent code needs several gigabytes of RAM, and the one that fits is rarely the one topping the leaderboards. This guide shows you how to pick one that fits, install it, and wire it into your editor.

What “small” actually means on a laptop

A language model is mostly a big file of numbers called weights. A 7-billion-parameter model stored at full precision needs roughly 28 GB of memory, which rules out nearly every laptop. Quantization shrinks those numbers. A 4-bit quantized version of the same model needs about 4 GB, and that is the version people actually run locally.

Quantization costs some accuracy, but for code completion and short explanations the loss is smaller than most people expect. What matters more is the context window: how much code the model can hold in memory at once. A model with a 4,000-token window can read one medium file. A model with a 32,000-token window can read several files, but it also eats more RAM while it works. Pick the window you need, not the biggest number on the page.

As a rough guide, 8 GB of RAM handles a 3-billion-parameter quantized model comfortably. 16 GB handles a 7-billion-parameter model. 32 GB opens the door to 13-billion-parameter models, and 64 GB or a laptop with a strong discrete GPU gives you real headroom. If you are not sure where your machine lands, our guide on how to pick a small language model for offline coding on a laptop walks through the same sizing decision in more detail.

Pick a small LLM for offline coding that fits your RAM

Start with the RAM you have, not the model you want. Check your total memory, subtract 4 GB for the operating system and your editor, and spend what is left on the model. A model that swaps to disk because it does not fit in RAM will generate a token every few seconds, which is too slow to use.

For most developers, the sensible starting point is a code-focused model in the 3B to 7B range, quantized to 4-bit. Code-specific models like Qwen2.5-Coder and DeepSeek-Coder tend to write better code at the same size than general-purpose models, because their training data leaned heavily on repositories and documentation.

Two details in the model name tell you most of what you need to know. The number, such as 3B or 7B, is the parameter count. The suffix, such as Q4_K_M, is the quantization level: Q4 means 4-bit, and K_M is a common middle ground between size and quality. If you see “instruct” in the name, the model was tuned to follow instructions, which is what you want for a coding assistant. Base models without that tuning ramble and finish your sentences instead of answering. Our comparison of when a 7B model beats GPT-4 for your use case covers the cases where a small model genuinely holds its own, and the cases where it does not.

Install Ollama and pull your first model

Ollama is the simplest way to run a model locally. It handles downloading, quantization, and serving the model behind a local API, so you do not have to compile anything or manage GPU drivers by hand. Install it from the official site for macOS, Windows, or Linux, then open a terminal and pull a model:

ollama pull qwen2.5-coder:7b

That downloads a few gigabytes, so do it on a connection you trust and let it finish. Then start a chat in the terminal to check that it works:

ollama run qwen2.5-coder:7b

Ask it to write a function you already know well, such as a debounce helper or a CSV parser. You are not testing whether it can write code. You are testing speed. Watch how fast tokens appear. On a modern laptop with 16 GB of RAM, a 7B quantized model should produce roughly 10 to 30 tokens per second. Below 5 tokens per second, the model is too big for your machine and you should drop to a 3B model. If you want to compare runtimes before settling, the Ollama vs LM Studio vs llama.cpp comparison lays out where each one fits.

Connect the model to your editor

A terminal chat is a test, not a workflow. The model earns its keep inside your editor, where it can see the file you are editing. Continue is a free, open-source extension for VS Code and JetBrains that talks to a local Ollama server, and it takes about five minutes to set up. Install the extension, open its settings, and point it at the model you just pulled. Our walkthrough on building a local AI coding assistant with Ollama and Continue covers the configuration step by step, including the settings file entries.

Once it is connected, three features do most of the work. Inline completion suggests the next few lines as you type. Chat lets you ask about a selected block of code, and it works best when you select the code first instead of describing it in words. Edit mode rewrites a selection according to an instruction, such as “add error handling” or “convert this to async”.

Ollama listens on localhost by default. Leave it that way: if you expose it on your network, anyone on that network can send prompts to it, and your code snippets travel with those prompts.

Write prompts that work with a small model

Small models fail on vague prompts that a large cloud model would handle by guessing well. “Fix this bug” gives a 7B model too little to work with. Paste the error message, name the file, and state what the code should do instead. The extra thirty seconds of context is usually the difference between a usable answer and a confident wrong one.

Give the model one job per prompt. Asking it to refactor a module, add tests, and update the docs in a single message produces a long answer that is wrong in three places at once. Split the work: refactor first, review the diff, then ask for tests against the new code. Small models also do better with examples than with rules. Show one input and one expected output, and the model will follow the pattern more reliably than if you describe the pattern in prose.

Set expectations by file size. A small model handles a single function or a short file well. Hand it a 1,000-line file and ask for a summary, and it will drop details and invent connections between parts it never read. When you need to work across files, paste the two or three relevant functions yourself instead of assuming the model can see the whole project.

What offline coding can and cannot do

A local model is good at the repetitive middle of coding work. It writes boilerplate, converts between formats, explains a function you did not write, drafts unit tests for a pure function, and suggests names for things. It is also good at private work: proprietary code, unreleased features, and anything covered by a client agreement that forbids sending code to a third party. That privacy is the real reason many teams go local, more than cost or speed.

It is weaker at the edges. It will not keep up with a framework released last month, because its training data ends before that release. It struggles with architecture decisions that span many files, and it invents library functions that do not exist when it does not know the right one. Treat every API call it suggests as unverified until you check it against the actual docs or your editor’s autocomplete.

Once the setup works, keep it boring. Pick one model, one editor extension, and one way of prompting, and use them for a month before changing anything. The goal was never to run a model locally. The goal was to write code without waiting on a connection, and that only happens when the setup stays out of your way.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.