Claude Code & Context Engineering

Local LLMs for Coding: Ollama and LM Studio Set Up Honestly

22 October 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Run coding models on your own hardware with Ollama or LM Studio: real memory requirements from published model data, the context-length trap and its fix, which agents connect, and what local models still cannot do.

Table inside: Hardware-to-model sizing table

Contents
  1. The short version
  2. The two runtimes, and which one you want
  3. The memory arithmetic nobody shows you
  4. Sizing table (4-bit quantisation, ~64K context)
  5. Choosing a model: what actually matters
  6. The context trap, and the fix
  7. Connecting an agent
  8. What local models are genuinely good for
  9. Pre-flight checklist
  10. How we researched this
  11. The verdict

You can run a genuinely useful coding model on your own machine today, at zero cost per token, with your code never leaving the room. Most first attempts still end in disappointment — and it is nearly always the same two causes: a model too big for the memory it was given, or a context window left at a default sized for chat, not agents.

This guide covers the memory arithmetic that decides which models you can run, a sizing table built from published model data, the context trap and its fix in both runtimes, and an honest account of where local models stop being enough.

Figures come from the model publishers’ cards and the runtimes’ documentation, checked November 2026. Where a number is arithmetic rather than a published figure, it is labelled as such.

The short version

The two runtimes, and which one you want

Ollama LM Studio
Shape Terminal-first server and CLI Desktop app with model browser and chat
Local API http://localhost:11434, OpenAI-compatible at /v1 http://localhost:1234/v1, OpenAI-compatible
Model handling One command per model: ollama pull <model> Search, download and load from the GUI
Settings style Flags, environment variables, Modelfiles Visible controls for quantisation, context, GPU offload
Apple Silicon note Uses Metal acceleration Also offers MLX-format models, Apple’s framework, often faster on Macs
Pick it if You live in the terminal and script things You want to see what the model is doing first

Ollama is the option every serious coding agent knows how to talk to — OpenCode, Cline, Continue, Aider. Pick it if agents and scripting are the goal.

LM Studio earns its place as the inspection tool: quantisation, context length and offload are sliders instead of flags, which makes it the better place to learn what your hardware can hold before wiring anything into an agent.

Both load GGUF-format quantised models. Quantisation is the compression that makes local models practical: storing weights at 4-bit precision (the common Q4_K_M build) takes roughly a quarter to a third of the full-precision memory, at a quality cost coding tasks tolerate better than most.

The memory arithmetic nobody shows you

A model fits if weights + KV cache + overhead fit in fast memory. The weights are the file you download. The KV cache is the memory the model reserves for its context window — and it is allocated for the full window you configure, whether or not the conversation grows into it. This is why “the model fits” and “the model works” are different statements.

Mixture-of-experts models add a trap of their own. An MoE activates only some parameters per token, which buys speed — but all parameters load into memory. The “A3B” in a model name describes the active count, not the footprint.

Worked example: Qwen3-Coder-30B-A3B

Per Qwen’s published model card (checked November 2026): 30.5B total parameters, 3.3B active per token, 128 experts, a native context of 262,144 tokens, Apache 2.0 licence. Published GGUF builds put the Q4_K_M file at roughly 17–19 GB depending on the build.

Add the cache, using published size calculations for this model:

Context you configure Approximate total memory
8K tokens ~19 GB
32K tokens ~21 GB
128K tokens ~30 GB
Full 256K tokens ~33 GB

So the honest requirement for this model at a working agent context is 24 GB as a tight floor, 32 GB or more for comfort — and the full advertised context window needs a 48 GB-class machine. The model card’s 256K headline and your hardware’s reality are both true; they are just answers to different questions.

Sizing table (4-bit quantisation, ~64K context)

Your fast memory Model class to pick Realistic use
8 GB 4B–9B coder models Completions, small functions, chat help
16 GB 9B–14B coder models Single-file edits, explanations, tests
24 GB 27B–30B MoE coder models (tight) Careful agent work, medium tasks
32–64 GB 30B class with real context headroom The local sweet spot for agents
CPU only, any RAM Small models only Trying the setup; too slow for agents

Below the top rows, keep expectations in single-file territory. The models are not stupid; they are small, and agent work multiplies every weakness across dozens of steps. The Cline vs Aider comparison covers two agents that both accept local endpoints, if you are choosing the client side of this setup.

Choosing a model: what actually matters

Parameter count is the number everyone quotes and the one that decides the least. When you are picking a coding model to download, check these instead:

On speed, one structural note: an MoE model’s generation speed tracks its active parameter count more than its total. That is the entire appeal of the 30B-A3B shape — 30B-class knowledge with small-model pace — and the reason the sizing table can recommend it on a single 24 GB card.

The context trap, and the fix

Here is the failure that makes most first attempts feel broken: the agent “forgets” your instructions and loses the plot mid-task, because its configured window is too small to hold them.

Ollama no longer has one default. Per Ollama’s context length documentation (checked November 2026), the default is chosen from your VRAM:

Your VRAM Default context
Under 24 GiB 4,096 tokens
24–48 GiB 32,768 tokens
48 GiB or more 262,144 tokens (capped at the model’s own maximum)

The same documentation states that tasks requiring large context — web search, agents and coding tools — should be set to at least 64,000 tokens. On a typical 16 GB card, the 4,096-token default is a quarter of the way there. That gap, not model quality, is what most “local agents are useless” verdicts are actually measuring.

The fix, in Ollama — pick one layer:

Verify, don’t trust: run ollama ps and read the CONTEXT column — that is the window actually loaded — and the PROCESSOR column, which should say 100% GPU. A CPU/GPU split means model plus context did not fit, and the slowdown will be severe.

In LM Studio, set the context length before loading the model, and watch the memory estimate move as you raise it — the jump is the KV cache, made visible. The same discipline applies to context budgets in cloud agents; the context budget audit works through the accounting.

Connecting an agent

Both runtimes expose an OpenAI-compatible endpoint, so connecting an agent is a base URL and a model name: Ollama at http://localhost:11434/v1, LM Studio at http://localhost:1234/v1. OpenCode and Cline both take these directly, as do Aider and Continue.

Do the context fix first, then test with a task that spans three files before trusting the setup with real work. A one-file test passes on configurations that fall apart at step twelve. If the agent supports a cheaper model for sub-tasks, the settings that cut Claude Code’s cost shows the same routing idea in a cloud tool — the pattern transfers even when the product does not.

What local models are genuinely good for

What they are not good for, yet, on hardware most people own: long autonomous sessions. Tool-calling reliability — emitting exactly the structured calls an agent loop needs, every time, for fifty steps — is where smaller open models fail first. A model that gets one call in twenty wrong will usually fail a fifty-step task somewhere in the middle. Frontier cloud models are not perfect here either, but the gap is real, and closing it is most of what the subscription buys.

Pre-flight checklist

FAQ

How much RAM do I need to code with a local LLM? For chat help and completions, 16 GB of total system memory runs small models. For agent work, plan on 24 GB or more of GPU or unified memory, so a 27B–30B-class model fits with a 64K context window — the context needs memory too, and it is the part everyone forgets.

Is Ollama or LM Studio better? Ollama for terminal workflows, scripting and agent connections; LM Studio for a graphical interface, visible settings and MLX performance on Apple Silicon. Both expose an OpenAI-compatible local API, so agents connect to either — and nothing stops you using LM Studio to size a model and Ollama to serve it.

Can local models replace Claude Code or Cursor? They can replace the model behind some agents — OpenCode, Cline and Aider accept local endpoints — but not the capability. On consumer hardware, expect reliable single-file help and useful drafting, not long autonomous multi-file work.

Why does my local agent forget instructions mid-task? Usually the context window. On machines under 24 GiB of VRAM, Ollama’s default is 4,096 tokens, while its own documentation recommends at least 64,000 for coding tools. Raise the window, verify with ollama ps, and most of the “forgetting” disappears — at the price of the extra cache memory.

Which quantisation should I download? Start with Q4_K_M. It is the build most model publishers treat as the reference 4-bit version, and for coding work the quality difference from Q8_0 is small next to the memory it saves — memory you will want for context. Move up a level only with memory to spare; move down only to make a model fit at all.

Is it really free and private? The runtimes are free, the models are downloads, and inference happens on your machine, so prompts and code do not leave it. Two honest caveats: “open-weight” licences vary by model — check the licence card before commercial use — and your time and electricity are real costs, just small ones.

How we researched this

Desk research from primary sources, checked November 2026: Qwen’s model card for Qwen3-Coder-30B-A3B (parameters, context, licence), published GGUF file sizes, Ollama’s context length documentation for the VRAM-tiered defaults and the 64,000-token recommendation, and both runtimes’ published documentation for ports and API compatibility. Memory totals for the worked example are arithmetic from those published figures — labelled as approximations, not measurements from our hardware. No benchmark scores are quoted, because the honest ones depend on hardware we would have to specify and test.

The verdict

Set up with the arithmetic done and the context fixed, a local model is the best free tier in coding: private, unlimited, and good enough for completions, explanations and first drafts. Set up carelessly, it is a slow chatbot that forgets — and the difference is two settings, not two models. Start local for the work it is genuinely good at, keep a cloud agent for the long autonomous jobs, and let the Cursor setup guide or your terminal agent of choice handle the rest of the workflow.

Category: Claude Code & Context Engineering · Tags: #ai-coding #ai-agents #context-engineering

Next step: this article is part of Claude Code guides, which covers the full topic from first setup to advanced use.

Related guides