Run a Free Local Coding Agent with OpenCode 2.0
Run a Free Local Coding Agent with OpenCode 2.0
Most coding agents ask for your credit card before you type your first prompt. OpenCode is different. It is MIT-licensed, has passed 213,000 stars on GitHub, and version 2.0 shipped in October 2026 with a shared background service, parallel subagents, and a Code Mode that chains tools in one sandboxed JavaScript program.
You can run it today for zero dollars. Point it at a built-in free model or a local model through Ollama, and nothing leaves your machine. This article is a copy-pasteable setup guide.
Why this matters now
AI coding tools have moved from "occasionally useful autocomplete" to "the agent reads your repository, runs commands, and edits files." The bottleneck is no longer the model itself — it is cost and trust. OpenCode 2.0 attacks both: the software is free, and you can point it at models that cost nothing to run.
v1 vs v2: what changed
| Area | OpenCode 1.x | OpenCode 2.0 | |---|---|---| | Architecture | Every interface ran its own engine | One shared background service; every interface is a client | | Subagents | Not available | Background subagents run in parallel | | Tool chaining | Context-heavy round trips | Code Mode: one sandboxed JavaScript program | | Sessions | Terminal only | Terminal and browser share state and permissions |
Step 1: Install OpenCode 2.0
# Fresh install (one-liner)
curl -fsSL https://opencode.ai/v2/install | bash
# Or via npm
npm install -g @opencode/cli
# Launch inside your project
cd my-project
opencode
If you are on v1, run opencode upgrade --major. Note that v1 and v2 cannot share the default opencode command name.
Step 2: Point it at a free model
Open the model picker inside a session with /models.
Option A — built-in free models
OpenCode ships hosted free models that require no API key. Select one and the whole session costs nothing. If your organization or a plugin hides them, check that OPENCODE_DISABLE_FREE_MODELS is unset.
Option B — a local model via Ollama
Nothing leaves your machine and nothing hits a billing meter:
ollama pull gemma3:4b
Create ~/.opencode/config.json:
{
"$schema": "https://opencode.ai/config.json",
"model": "ollama/gemma3:4b"
}
OpenCode auto-discovers local models from Ollama, LM Studio, and vLLM at their default local addresses.
Step 3: Run a real task
Open a terminal session, then open the same session in the browser. It is the same state, same permissions, same running tools — one shared brain.
Try this first task: "List the files changed in the last pull request and flag potential regressions." OpenCode reads your codebase, writes and edits files, runs commands, and asks permission before risky steps.
In Code Mode, the agent chains tools inside one sandboxed JavaScript program instead of burning context on round trips.
Step 4: Add an MCP server (optional)
OpenCode supports Model Context Protocol servers. To let the agent read your local files, add a filesystem server:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed"]
}
}
}
The same pattern works for databases, browsers, and search tools.
Honest limitations
OpenCode 2.0 is young, and it shows. Start with read-only tasks. Review every file edit before you accept it. Treat the agent as a junior pair programmer: fast, eager, and still in need of verification.
This post was written with AI assistance. The author is responsible for its content.