Running Local LLMs for Coding with Ollama

Run open-weight coding models locally with Ollama: hardware needs, quantization, pulling models, the local API, editor integration and when local makes sense...

Published November 27, 2026

Cloud AI assistants are powerful, but some code cannot leave your machine, some developers work offline, and some teams want predictable costs. Open-weight models running locally answer those needs. Ollama makes it about as easy as installing a package: one command downloads a model and exposes a local API your editor and scripts can use.

The concept

Ollama wraps the llama.cpp inference engine with a simple CLI, a model library and an HTTP API on localhost:11434. Models are distributed in quantized formats (GGUF), which store weights in 4 to 8 bits instead of 16, shrinking memory requirements several times with modest quality loss. A 7-8 billion parameter model at 4-bit fits in roughly 5-6 GB of memory and runs well on a recent laptop GPU or Apple Silicon.

Local models are smaller than frontier cloud models, so set expectations accordingly. They are very good for completion, explaining code, writing small functions, commit messages and private document Q&A. For large multi-file refactors and complex reasoning, the largest cloud models still lead. Many developers use both: local for private or quick tasks, cloud for hard ones.

Sizing hardware

Model sizeMemory (4-bit, approx.)Typical hardwareGood for
1-4B1-3 GBAny modern laptopFast autocomplete, simple edits
7-9B5-7 GB8 GB+ GPU or 16 GB Apple SiliconGeneral coding chat, completion
13-16B9-12 GB12-16 GB GPU or 32 GB unified memoryBetter reasoning
30-34B18-22 GB24 GB GPU or 48 GB unified memoryStrong local coding assistant
70B+40 GB+Multiple GPUs or 64-128 GB unified memoryNear cloud quality on some tasks

Rules of thumb; actual needs depend on context length and quantization.

How the pieces connect

HTTPloadcomputeEditor pluginContinue / otherslocalhost:11434Ollama APIllama.cppGGUF modelGPU / CPUMetal, CUDA, ROCm
Nothing leaves your machine.

Getting started

ollama pull qwen2.5-coder:7b
pulling manifest ... success
ollama run qwen2.5-coder:7b "Write a bash one-liner that lists the 5 largest files under /var/log"
find /var/log -type f -exec du -h {} + | sort -rh | head -n 5
ollama ps
NAME SIZE PROCESSOR UNTIL
qwen2.5-coder:7b 6.0 GB 100% GPU 4 minutes from now
Pull a coding model, ask a question, check what is loaded.

Quantization trade-off

Q8 (8-bit)best quality, 2x size of Q4Q5_K_Mgood balanceQ4_K_Mcommon defaultQ2noticeably worse
Illustrative relative quality by quantization level for the same model.

Practical examples

Call the local API

Ollama exposes its own API and an OpenAI-compatible endpoint.

curl http://localhost:11434/api/generate -d '{
  "model": "qwen2.5-coder:7b",
  "prompt": "Explain what this regex matches: ^\\d{3}-\\d{4}$",
  "stream": false
}'
# OpenAI-compatible
curl http://localhost:11434/v1/chat/completions -H 'content-type: application/json' \
  -d '{"model":"qwen2.5-coder:7b","messages":[{"role":"user","content":"hi"}]}'

Use it from Python with the OpenAI SDK

Point the base URL at Ollama; the API key is ignored.

from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
    model="qwen2.5-coder:7b",
    messages=[{"role": "user", "content": "Write a pytest for a function add(a, b)."}],
)
print(reply.choices[0].message.content)

Customise a model with a Modelfile

Set a system prompt and context length once.

FROM qwen2.5-coder:7b
PARAMETER num_ctx 16384
PARAMETER temperature 0.2
SYSTEM "You are a senior Laravel developer. Answer concisely with code."
# ollama create laravel-helper -f Modelfile && ollama run laravel-helper

Common mistakes

  • Choosing a model too large for available memory, causing swapping and painfully slow output.
  • Expecting a small local model to match the largest cloud models on complex refactors.
  • Exposing the Ollama port to the network without authentication.
  • Using the default small context window and wondering why the model forgets earlier parts of a long file.
  • Ignoring model licenses; open-weight does not always mean unrestricted commercial use.

Key takeaways

  • Ollama makes local, private LLMs a one-command install with a local API.
  • Quantization (4-5 bit) lets 7-34B models run on developer hardware.
  • Local models suit private, offline and quick tasks; cloud models lead on hard reasoning.
  • Keep the API on localhost and check model licenses.

FAQ

Do I need a GPU?

No, but it helps a lot. Apple Silicon unified memory works very well; CPU-only inference works for small models but is slower.

Which local model is best for code?

It changes frequently. Look at current code-specialised open-weight families and try two or three sizes on your own tasks.

Can multiple developers share one local model server?

Yes. Run Ollama or a server like vLLM on a shared GPU machine inside your network, behind authentication.

More Tooling articles