explainx.ainewsletter3.5k
TrendingNewsPathwaysSkills
Pricing
explainx.ai

Upskill in AI — 16 free pathways, live workshops & bootcamps, and 50+ courses from practitioners. Plus the skills, tools, and MCP servers to practice on.

follow us

corporate training

[email protected]

get started

Find your pathTake Free Evaluation

learn

pathways — start freeworkshopsbootcampscoursescertificationsmock testsexplainx universitycorporate traininglearn skills & mcp

discover

skillsmcp serversexplainx mcptoolsagentsllmsdesignsagi trackerranks

company

aboutvisionmissionteaminstructorscommunityhackathonscareers

content

daily AI newsstate of AI — live resultsblogreleasespromptsgeneratorsresource libraryfor LLMsexplainx.ai kids

solutions

all solutionsdeveloper upskillingmarketing upskillingproduct manager upskillingleadership upskilling

newsletter · weekly

Get AI news, tools, and insights in your inbox.

supportprivacytermsdata rightshow we create contentsubmission guidelines

© 2026 AISOLO Technologies Pvt Ltd

On this page

  • TL;DR — the full local + OpenCode path
  • Architecture — three layers
  • Step 1 — Install OpenCode
  • Step 2 — Pick an inference runtime
  • Step 3 — Start the local server
  • Step 4 — Configure OpenCode (opencode.jsonc)
  • Step 5 — Cloud + local in one config (recommended)
  • Model picks for local OpenCode (July 2026)
  • Hardware reality check
  • First session checklist
  • Troubleshooting
  • OpenCode vs other local harnesses
  • Related on explainx.ai
← Back to blog

explainx / blog

How to Run Open Source Models Locally and Wire Them Into OpenCode (2026)

Step-by-step: Ollama, llama.cpp, LM Studio, or vLLM → OpenAI-compatible API → OpenCode opencode.jsonc. Model picks (Qwen 3.6, GLM, Gemma), hardware tiers, multi-model routing, and troubleshooting.

Jul 1, 2026·6 min read·Yash Thakker
OpenCodeLocal LLMOpen Source AIllama.cppOllamaAgent Harness
go deep
How to Run Open Source Models Locally and Wire Them Into OpenCode (2026)

July 1, 2026: With Fable 5 still offline, GLM-5.2 and Qwen 3.6 27B proving local coding is practical, the missing piece for many developers is not which model — it is how to wire inference into a harness.

OpenCode is the open-source agent loop that accepts any OpenAI-compatible API. Run weights on your CPU/GPU, expose http://127.0.0.1:…/v1, point ~/.config/opencode/opencode.jsonc at it, and you have a local coding agent — same tools, LSP, and /init AGENTS.md flow as cloud setups, without sending repo context to a third party.

This is explainx.ai's end-to-end stack guide: pick a model → start a server → configure OpenCode → tier local vs cloud.

Weekly digest3.5k readers

Catch up on AI

Curated AI updates on agents, skills, and MCP — delivered to your inbox. Unsubscribe anytime.


TL;DR — the full local + OpenCode path

StepWhat to doDeep dive
1. Hardware32GB+ for Q4 7B–27B; 48GB+ for Q8 27BMac vs GPU guide
2. ModelQwen 3.6 27B coding default; GLM-5.2 if you have GPU headroomQwen local guide · GLM Unsloth
3. Runtimellama.cpp (control) or Ollama (ease)What is llama.cpp? · Personal AI system
4. ServerOpenAI-compatible /v1 on localhostSections below
5. OpenCodeopencode.jsonc provider + opencode in repoOpenCode harness guide
6. Verify/init, small coding task, check tok/sQuantization guide

Architecture — three layers

text
┌─────────────────────────────────────┐
│  OpenCode (agent harness)           │
│  tools · LSP · AGENTS.md · sessions │
└──────────────┬──────────────────────┘
               │ OpenAI-compatible HTTP
┌──────────────▼──────────────────────┐
│  Inference server                   │
│  llama.cpp · Ollama · LM Studio · vLLM│
└──────────────┬──────────────────────┘
               │ GGUF / safetensors
┌──────────────▼──────────────────────┐
│  Open-weight model on your disk/GPU │
│  Qwen · GLM · Gemma · DeepSeek · …  │
└─────────────────────────────────────┘

OpenCode never loads weights itself — it only talks HTTP. That separation is why one config file can swap Ollama today and llama.cpp tomorrow.


Step 1 — Install OpenCode

bash
curl -fsSL https://opencode.ai/install | bash
# or: npm install -g opencode-ai
# or: brew install anomalyco/tap/opencode
bash
cd your-project
opencode

First-run inside TUI:

  1. /connect — for cloud providers (Z.AI, OpenRouter, Copilot OAuth)
  2. /init — generate AGENTS.md project memory
  3. /models — pick active model after providers exist

Slash reference: OpenCode commands. Harness concepts: What is an agent harness?.


Step 2 — Pick an inference runtime

RuntimeBest forOpenAI API defaultOpenCode fit
llama.cppMax control, MTP, Apple Siliconhttp://127.0.0.1:8080/v1Recommended for serious local coding
OllamaOne-command pull/servehttp://127.0.0.1:11434/v1Fastest onboarding
LM StudioGUI + local server togglehttp://127.0.0.1:1234/v1Non-terminal users
vLLMMulti-user / production GPU boxcustom port /v1Team LAN server

Codex users: same local servers work in Codex OSS mode — different harness, identical inference layer.


Step 3 — Start the local server

Option A — llama.cpp (Qwen 3.6 27B example)

From the Qwen 3.6 local benchmark post:

bash
llama-server -hf unsloth/Qwen3.6-27B-MTP-GGUF:Q8_0 \
    --spec-type draft-mtp -ngl 999 -fa on -c 65536 --port 8080

Smoke test: open http://127.0.0.1:8080 or curl http://127.0.0.1:8080/v1/models.

Option B — Ollama

bash
ollama pull qwen3.6:27b        # verify tag on ollama.com/library
ollama serve                   # usually auto-starts on 11434

Other coding pulls teams use: glm-5.2, deepseek-coder-v2, gemma4:12b — check VRAM before pulling 70B-class tags.

Option C — LM Studio

  1. Download model in GUI
  2. Local Server tab → Start Server (default 1234)
  3. Enable OpenAI compatible API

Option D — vLLM (Linux GPU server)

bash
python -m vllm.entrypoints.openai.api_server \
  --model Qwen/Qwen3.6-27B-Instruct \
  --port 8000

Point OpenCode at http://127.0.0.1:8000/v1 or your LAN IP for a shared team box.


Step 4 — Configure OpenCode (opencode.jsonc)

Config path: ~/.config/opencode/opencode.jsonc (user-wide) or project-local per OpenCode docs.

llama.cpp provider block

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "llama": {
      "name": "llama.cpp (local)",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:8080/v1",
        "apiKey": "local"
      },
      "models": {
        "qwen3.6-27b": { "name": "Qwen3.6-27B Q8 +MTP" }
      }
    }
  },
  "model": "llama/qwen3.6-27b"
}

Ollama provider block

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "name": "Ollama (local)",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1",
        "apiKey": "ollama"
      },
      "models": {
        "qwen3.6-27b": { "name": "qwen3.6:27b" }
      }
    }
  },
  "model": "ollama/qwen3.6-27b"
}

LM Studio provider block

jsonc
"options": {
  "baseURL": "http://127.0.0.1:1234/v1",
  "apiKey": "lm-studio"
}

Restart OpenCode after editing config, or run opencode fresh from the project directory.


Step 5 — Cloud + local in one config (recommended)

Post-Fable tiering:

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "llama": {
      "name": "Local Qwen",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:8080/v1",
        "apiKey": "local"
      },
      "models": {
        "qwen3.6-27b": { "name": "Qwen3.6-27B local" }
      }
    },
    "zai": {
      "name": "GLM Coding Plan",
      "options": {
        "baseURL": "https://api.z.ai/api/coding/paas/v4"
      }
    }
  },
  "model": "llama/qwen3.6-27b"
}
WorkloadSwitch to
Private repo, offline flightllama/qwen3.6-27b
Hard refactor, long agent/models → GLM-5.2 (harness guide)
Cheap volume APICline $9.99 open weights or OpenRouter

Connect Z.AI via /connect inside TUI if you prefer not to store API keys in jsonc.


Model picks for local OpenCode (July 2026)

ModelLocal fitOpenCode notes
Qwen 3.6 27B denseBest balance 48GB Mac / 24GB+ NvidiaBeats MoE 35B A3B on instruction following
Gemma 4 12B/31BMultimodal + Apache 2.0Slower than Qwen for pure code
GLM-5.2 UnslothWorkstation / multi-GPUClosest to frontier local
DeepSeek V4 Flash (quant)High tok/s if RAM allowsAggressive quants trade quality
Kimi K2.7Usually API — too large for most localsUse API via OpenCode /connect

Alibaba cloud line: Qwen 3.7-Max for when local is not enough.


Hardware reality check

MachineRealistic local model
32GB Apple SiliconQ4 27B or Q8 7B–14B
48–64GB Apple SiliconQ8 Qwen 3.6 27B (~32 tok/s MTP)
24GB Nvidia (4090/5090)Q6 27B; Q4 70B tight
64GB+ VRAM / dual GPUGLM-5.2 class, vLLM team server

Full economics: Mac vs dedicated GPU · closed vs open cost table.


First session checklist

  1. Server running — curl -s http://127.0.0.1:8080/v1/models (or Ollama 11434)
  2. Config saved — ~/.config/opencode/opencode.jsonc
  3. opencode in git repo
  4. /init — creates AGENTS.md
  5. Smoke prompt — "Create a pnpm package with a hexagonal minesweeper" (same test as Quesma Qwen post)
  6. Verify model — ask "What model are you?" — should not hallucinate Claude/GPT

Add verification loops from explainx.ai loops — e.g. ci-until-green.


Troubleshooting

SymptomFix
Connection refusedInference server not running or wrong port in baseURL
Empty / garbage outputQuant too low — bump Q4→Q6/Q8 (quant guide)
Slow first tokenModel loading; MTP helps decode — see llama.cpp --spec-type draft-mtp
Ignores package.json / structureTry dense over MoE; shorten context if RAM swapping
Tool calls failModel may lack reliable function-calling — switch to GLM API or GPT-class for agent-heavy runs
Wrong providerecho config path; /models list; check model string matches provider/id

OpenCode vs other local harnesses

HarnessLocal OSS modelsNotes
OpenCodeYes — 75+ providers + custom localDefault open multi-surface
PiYes — provider pluginsMinimal, ownable
Codex OSSYes — --oss + OllamaOpenAI-native tool schema
Claude CodeIndirect — /config remote to desktopNot weight-local
Kilo CodeYes — BYOK + OllamaVS Code extension

OpenCode wins when you want one harness, terminal + desktop, and swap local/cloud without reinstalling.


Related on explainx.ai

  • OpenCode Desktop tabs — Jul 15, 2026
  • Qwen 3.6 27B — llama.cpp + OpenCode deep dive
  • OpenCode harness guide
  • OpenCode slash commands
  • GLM-5.2 in OpenCode (cloud API path)
  • Build personal local AI system
  • Codex + Ollama OSS mode
  • Mac vs GPU local LLM economics
  • What is llama.cpp? — install, GGUF, llama-server
  • LM Studio Bionic — open-model agent app (Jul 17)
  • Kimi K3 local desktop prep — open weights July 27
  • Kimi K3 API guide — cloud K3 until weights drop
  • Kimi K2.7 Code — open weights on localhost today
  • Fable enterprise open alternatives
  • Top Chinese AI companies — Qwen/DeepSeek/Kimi

Official: OpenCode · OpenCode config schema · llama.cpp · Ollama

Runtime ports, model tags, and OpenCode provider schema reflect July 2026 docs — verify before production. Last updated: July 17, 2026.

Spotted something out of date? Let us know.
Yash Thakker

Written by

Yash Thakker

Yash is an AI expert with over 300K learners. Join his workshops →

Related posts

Jun 29, 2026

Qwen 3.6 27B Local Dev Guide: llama.cpp, OpenCode, and Why Dense Beats MoE

After HN front-page hype, hands-on tests say Qwen 3.6 27B dense is the local sweet spot — better code than the 35B MoE, runnable at Q8 on 48GB RAM. Full llama.cpp + OpenCode config inside.

Jul 17, 2026

LM Studio Bionic: Open-Model Agent for Code and Work Projects

LM Studio shipped Bionic on July 16, 2026 — a dedicated agent app (not LM Studio itself) for code repos and work projects over local models, LM Link, or Secure Cloud with zero data retention. This guide covers what works, HN rough edges, closed-source trade-offs, and how it compares to OpenCode and Unsloth Studio.

Jul 2, 2026

What Is llama.cpp? Install, Run GGUF Models, and Serve OpenAI-Compatible APIs

If you run open weights on your own hardware in 2026, you are almost certainly touching llama.cpp — directly or through Ollama and LM Studio. This guide explains what it is, how GGUF fits in, copy-paste install and run commands, and how to expose a local API for coding agents.