Local AI Coding with Opencode
Recently, local AI models have improved significantly. Running a capable coding assistant directly on your own machine is now possible without extremely expensive hardware. You can now run a highly capable coding assistant entirely on-device. No subscriptions, no latency spikes, and zero data leaving your machine
In this article, I’ll walk through the local AI development setup I currently use:
The Stack
- Provider: LM Studio (for Hugging Face integration and MLX support)
- Model: OpenAI-OSS-20B (MLX 4-bit quantized)
- Agent: OpenCode
- IDE Integration: Continue (VS Code extension)
Hardware Context
I’m running this on a MacBook M4 Pro with 24GB of RAM. This is the current “sweet spot” for local LLMs. It’s enough memory to fit 20B-30B parameter models with 4-bit quantization while leaving enough headroom for your IDE, Docker containers, and browser tabs.
Setting Up the Provider: LM Studio
While there are many runners (Ollama, vLLM, etc.), I prefer LM Studio for my local setup because of its deep integration with Hugging Face and its transparent handling of Apple’s MLX framework.
Choosing the Right Model
When searching for a model, look for three things:
- Tooling/Function Calling Support: Since we are using an agent (OpenCode), the model must understand how to call tools.
- GPU Offload: Look for the “Full GPU Offload Possible” tag. If you see “Likely too large,” your system will swap to system RAM, and the token-per-second rate will crater.
- Quantization: For a 20B model on 24GB RAM, 4-bit quantization is the gold standard for balancing intelligence and speed.
I’ve settled on OpenAI’s GPT-OSS-20B (MLX version). It’s specifically optimized for Apple Silicon and punches well above its weight in reasoning and code generation.
MLX quantization uses Apple’s new AI/ML framework for Apple silicon. LM Studion automatically suggests that version also.
Memory and Context
When loading the model, don’t stick to the default 4k context window. Modern agents like OpenCode need to “see” more of your project to be effective. I recommend bumping this as high as your memory allows — at least 8k or 16k if possible.
Serving the Model
To make the LLM accessible to our coding tools, we need to expose it via a local API.
- Navigate to the Local Server tab in LM Studio.
- Ensure the port is set (default is
1234). - Click Start Server.
LM Studio provides an OpenAI-compatible endpoint at http://localhost:1234/v1. This is crucial because almost every developer tool designed for AI can talk to an OpenAI-formatted API.
You can also copy that to clipboard using menu bar option Copy LLM Server Base URL.
Configuring the Agent: OpenCode
OpenCode acts as the “brain” that can actually manipulate files and run commands. To point it to your local model:
- Open OpenCode settings.
- Add a custom provider.
- Set the Base URL to your local LM Studio endpoint.
- Crucial: Ensure the
model-idmatches the exact string shown in LM Studio (e.g.,openai/gpt-oss-20b).
Once configured, the agent will begin using your local GPU for every request. You’ll see the active usage logs in the LM Studio console.
IDE Integration: Continue in VS Code
For inline edits and chat within the editor, Continue is the best open-source choice. It allows you to swap providers easily via a config.json file.
Open your Continue config and add the following entry to your models array:
name: Local Config
version: 1.0.0
schema: v1
models:
- name: GPT OSS
provider: lmstudio
apiBase: http://localhost:1234/v1
model: openai/gpt-oss-20b
roles:
- chat
- edit
- apply
name: Local Config
version: 1.0.0
schema: v1
models:
- name: GPT OSS
provider: lmstudio
apiBase: http://localhost:1234/v1
model: openai/gpt-oss-20b
roles:
- chat
- edit
- apply
Now, when you highlight code and hit Cmd+I, your local machine, not a server in eu-west-1, is doing the heavy lifting.
Realistic Expectations
We have to be honest: Local models, especially those small enough to fit on a laptop, aren’t “Claude Opus 4.6 killers” yet. You will notice more hallucinations in complex logic and a shorter “memory” for large-scale refactors.
However, for 80% of daily tasks — unit tests, boilerplate, documentation, and simple debugging — this stack is more than sufficient. The privacy and the “forever free” nature of the setup make it a mandatory tool for any serious engineer’s belt.
The open-source community is moving fast. Today it’s 20B models; tomorrow, we might be running 70B models comfortably on our laps.
Stay local.

