On this pageWhat changed in version 2
OpenCode is an MIT-licensed coding agent from Anomaly. It reads a repository, edits files and runs commands with whichever model you connect. Version 2.0 left public beta in October 2026 and rebuilt the tool around one background service per user, shared by the terminal, web and desktop clients. On a server, that changes how you install the agent, lock it down and reach it. If you are still choosing between agents, start with the coding agent comparison.
What changed in version 2
Many snippets online still show 1.x syntax. What changed:
- One shared service. OpenCode finds or starts a background server for your user account. That service owns sessions, permissions and plugins, and every client attaches to it.
- Renamed configuration. Models live under
providers, custom agents underagents, and permissions underpermissionsas an ordered list of rules. Thebashpermission is nowshell, andtaskis nowsubagent. - Breaking changes. Plugins written for 1.x do not load, and the server API was redesigned, so scripts that called the old API need work.
- New abilities. Subagents can work in the background while the main agent continues, shell commands can run without blocking the session, and Code Mode lets the agent write one script that chains several MCP or OpenAPI calls.
Install it for a dedicated user
Run the agent as an ordinary account with no sudo rights. Everything it does, it does with that account's permissions, so the account is your outer fence.
sudo adduser --disabled-password --gecos "" coder
sudo -iu coder
curl -fsSL https://opencode.ai/v2/install | bash # installs into ~/.opencode/bin
export PATH="$HOME/.opencode/bin:$PATH"
git clone https://example.com/your/repo.git ~/src/app && cd ~/src/app
opencode # first run starts the shared service
Inside the terminal UI, /connect adds a provider, /models picks the model, /sessions lists earlier work, and Shift+Tab cycles between the primary agents. From another shell, opencode service status shows where the service listens, and its log sits in ~/.local/share/opencode/log/opencode.log.
Connect a model
The configuration has the same shape for hosted and self-hosted models: a provider entry, then a default model written as provider/model, or a choice made with /models.
Hosted providers
Built-in providers include OpenAI, Anthropic, Google, Amazon Bedrock, Azure, OpenRouter, xAI and GitHub Copilot. On a headless server, an API key is the least fiddly route: run /connect, pick the provider and paste the key. Create a separate key for the agent with a spending limit set at the provider, so a runaway session cannot drain the account you use for everything else.
Your own model
OpenCode also ships entries for Ollama, LM Studio and vLLM, which discover their models on their own. You only point them at the machine that serves the model. If that is a GPU server on a private network, keep the endpoint off the public internet and use its private name or address:
// ~/.config/opencode/opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"vllm": {
"settings": { "baseURL": "http://gpu-host:8000/v1" },
},
},
}
A local model keeps your source code on hardware you control. The trade is capability: open-weight models differ widely at multi-step tool use, and a model that chats well can still fumble a refactor that spans ten files. Try one real task from your backlog before you commit to it.
Write permissions as ordered rules
Out of the box, every agent starts from a policy that allows all actions and asks only before reading .env files. Nothing asks before the agent reads or writes outside the project. That suits a laptop where you watch the screen. On a server where sessions run in the background, tighten it.
Rules are checked in order and the last match wins, so broad rules go first and exceptions after them. When one operation touches several resources, any deny blocks it.
{
"$schema": "https://opencode.ai/config.json",
"permissions": [
{ "action": "shell", "resource": "*", "effect": "ask" },
{ "action": "shell", "resource": "git status *", "effect": "allow" },
{ "action": "shell", "resource": "git diff *", "effect": "allow" },
{ "action": "shell", "resource": "npm test *", "effect": "allow" },
{ "action": "shell", "resource": "git push *", "effect": "deny" },
{ "action": "shell", "resource": "rm *", "effect": "deny" },
{ "action": "external_directory", "resource": "*", "effect": "ask" },
{ "action": "webfetch", "resource": "*", "effect": "ask" },
],
}
A shell pattern that ends in a space and * also matches the bare command, so git status * covers plain git status. The shell scanner splits compound commands, checks each part against the rules, and refuses to run a command it cannot analyze. When a rule asks, you can approve once, approve always (saved for that project) or reject. A saved approval never overrides a configured deny.
Two limits are worth knowing. Agent-level rules are appended after the global ones, so a custom agent can loosen what you set at the top; for a ban that nothing below can override, the documentation provides a separate top-level policies list. And permissions are a seatbelt, not a sandbox: the docs state plainly that shell commands run with the full authority of the host user. The real boundary is the Unix account, on a server that holds nothing you could not rebuild.
Agents: build, plan and your own
Two primary agents ship with OpenCode. build is the default coding agent. plan explores and proposes changes without editing project files, which makes it the right first stop in an unfamiliar repository. Two subagents run in child sessions: general for multi-step research and explore for read-only searches.
Adding your own takes a few lines. This reviewer can read everything and edit nothing:
{
"agents": {
"reviewer": {
"description": "Reviews the current changes without editing files",
"mode": "subagent",
"system": "List correctness bugs first, then security issues, then style. Cite file and line.",
"permissions": [
{ "action": "edit", "resource": "*", "effect": "deny" },
],
},
},
}
The same agent can live in .opencode/agents/reviewer.md, with the options in front matter and the prompt as the file body. Ask the build agent to use the reviewer on your changes and it runs in the background, then reports when it finishes. The description matters more than it looks: the main agent reads it to decide which subagent fits a job.
Reach it from your laptop
The shared service listens only on localhost (port 49374 on Linux) and protects itself with a generated password. Keep both defaults and tunnel in:
# on the server, as the agent's user
opencode service set password "a-long-random-secret"
opencode service start # any "service set" change stops the service
opencode pair # prints a sign-in link that works once, for 5 minutes
# on your laptop
ssh -L 49374:127.0.0.1:49374 coder@203.0.113.10
Open the printed link in your local browser. It sets a session cookie that lasts 30 days, and changing the password signs every session out. Scripts and other HTTP clients authenticate with Basic auth and the username opencode.
Two other routes exist, and both deserve caution. opencode service set hostname 0.0.0.0 makes the service listen on every interface, which puts a password-protected command runner on the internet; if you go that way, restrict the port to your own address with a firewall and add TLS in front. opencode pair --remote publishes the server through an OpenTunnel address, encrypted end to end and still behind the password, after a confirmation prompt.
The caution has a history. CVE-2026-22812, published in January 2026, showed that OpenCode releases before 1.0.216 ran an HTTP server with no authentication and permissive CORS, so a local process or a web page could run shell commands as the user. Version 2 binds to localhost and requires a password by default. Leave both in place and keep the agent updated.
Run it from scripts
For CI jobs, cron or a systemd timer, opencode run sends one prompt and prints the result:
cd ~/src/app && opencode run "Run the test suite, fix failing tests, then summarize the diff"
Point unattended jobs at a branch or a separate git worktree. Nobody is there to approve an ask, so replace ask rules with an explicit list of what the job may do. The unattended agents guide covers timers, time limits and spending caps.
OpenCode also reads AGENTS.md files from the working directory upward, plus a global ~/.config/opencode/AGENTS.md. In a directory without one, it falls back to CLAUDE.md, so a repository already set up for Claude Code works unchanged. The context files guide explains what belongs in them.
Where it sits next to Claude Code and OpenClaw
The three do different jobs. Claude Code is Anthropic's proprietary agent, built around Claude models; it takes less setup when you already pay for a Claude plan, while OpenCode is open source and accepts any provider, including a local model. OpenClaw is a personal assistant you message from Telegram, WhatsApp, Slack and other chat apps, not a repository tool; the self-hosted agents comparison covers that side.
On CloudSat, the OpenCode one-click app installs the agent when the server is deployed; the agent itself needs little, so size the server for your builds and test suite.
FAQ
Does OpenCode send my code anywhere?
It sends prompts to the model provider you connect, and every file the agent reads becomes part of a prompt. With a model on your own server, that traffic stays on your network. Sessions are kept by the service on the machine where it runs; opencode debug paths lists the locations.
Can I keep my OpenCode 1.x configuration?
Partly. Rename the keys listed above and port or drop 1.x plugins, which version 2 does not load. Try the new configuration on a scratch repository before pointing it at real work.
Do I need a GPU for OpenCode?
Not for the agent. You need one only if you also host the model. A common split is a small server for the agent and a GPU server for the model, linked over a private address or an SSH tunnel.
Can several developers share one server?
Yes, with one Unix account each. The service runs per user, so sessions, credentials and permissions stay separate, and each agent can reach only what its own account can.
Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.




