Run OpenCode with a Local Model on Your Mac

OpenCode is an open-source coding agent for the terminal. Give it a model served on your own Mac and it reads, edits and runs code with no API key, no bill and no network.

OpenCode is a terminal coding agent in the same family as Claude Code: you describe a change, it reads your files, calls tools and edits the code. It talks to models through OpenAI-compatible providers, which is exactly what Rapid-MLX serves on your Mac.

The result is an agent whose model runs on your laptop: prompts and code go to localhost instead of a cloud API, and there's no per-token bill.

The whole thing

  1. Install Rapid-MLX and serve a model.
  2. rapid-mlx agents opencode --setup writes OpenCode's provider config.
  3. opencode in your project.

1 · Install Rapid-MLX and OpenCode

curl -fsSL https://rapidmlx.com/install.sh | bash
npm install -g opencode-ai

Rapid-MLX is also in Homebrew core: brew install rapid-mlx.

2 · Serve a model

rapid-mlx serve qwen3.5-4b-4bit

This is the engine's pick for a 16 GB Mac, and the model we verified this guide with. On a bigger Mac, rapid-mlx recipe prints a stronger pick for your memory; Best local LLMs by Mac shows how fast each one runs on your exact chip. Leave the server running in its own terminal.

3 · Point OpenCode at it

In a second terminal:

rapid-mlx agents opencode --setup

It shows the change, asks before writing, and backs up any existing file. The result in ~/.config/opencode/opencode.json is a provider called rapid-mlx that uses OpenCode's @ai-sdk/openai-compatible adapter with http://localhost:8000/v1 as its base URL, and the served model as the default:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "rapid-mlx": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Rapid-MLX",
      "options": { "baseURL": "http://localhost:8000/v1", "apiKey": "not-needed" },
      "models": { "qwen3.5-4b-4bit": {} }
    }
  },
  "model": "rapid-mlx/qwen3.5-4b-4bit"
}

4 · Run it

Open your project and start OpenCode, or hand it one task from the shell:

# inside your project folder
opencode run "Add a function add(a, b) to hello.py that returns a + b. Edit the file."

This is the output from our run, trimmed:

← Edit hello.py
@@ -1,2 +1,5 @@
 def greet(name):
     return "Hello, " + name
+
+def add(a, b):
+    return a + b

Added the `add(a, b)` function that returns `a + b`.

Verified on 2026-10-06 with rapid-mlx 0.15.6, OpenCode 1.18.34 and qwen3.5-4b-4bit on a Mac mini (M2 Pro, 32 GB): setup as above, then the opencode run task edited the file through OpenCode's own edit tool in about 30 seconds, model already loaded.

What to expect

A small local model is good at focused edits, explaining code and small features. For long multi-file refactors, use the biggest model your Mac fits: qwen3.8-27b-4bit on 32 GB, or qwen3.6-35b-4bit on 48 GB for speed. If OpenCode asks for an Anthropic key on first launch, skip it: the model comes from the rapid-mlx provider.

Frequently asked questions

Can OpenCode use a local model?

Yes. OpenCode accepts any OpenAI-compatible provider. Serve a model with Rapid-MLX, run rapid-mlx agents opencode --setup, and OpenCode's default model becomes the one on your Mac at http://localhost:8000/v1.

Does OpenCode send my code anywhere with a local model?

Model requests go from OpenCode to localhost, so prompts and code stay on your Mac. Rapid-MLX itself sends anonymous usage counts by default, never prompts or code; rapid-mlx telemetry off turns that off (details).

Which local model is best for OpenCode on a Mac?

Run rapid-mlx recipe: it prints the engine's pick for your memory. Tool calling matters most for an agent, so prefer the largest pick that fits, such as qwen3.8-27b-4bit on 32 GB or more.

Where to go next


Run this yourself. Rapid-MLX is an open-source, OpenAI- and Anthropic-compatible inference server for Apple Silicon. One command installs it, then rapid-mlx serve <alias> serves any model on localhost:8000/v1.
curl -fsSL https://rapidmlx.com/install.sh | bash

New models and speedups, in your inbox

A short note whenever Rapid-MLX gets faster or adds models worth running on your Mac. No spam — unsubscribe anytime.