OpenCode AI coding agent: install, models, config and safe setup (2026)

OpenCode AI coding agent: install, models, config and safe setup (2026)

OpenCode is a free, MIT-licensed AI coding agent that runs in your terminal, a desktop app or your IDE, and works with 75+ model providers, including local models. This guide covers installing it (and the OpenCode 1 vs 2 split), connecting a model, configuring opencode.json, tightening its permissive defaults, and how it compares with Claude Code and Codex.

In shortTL;DR
  • OpenCode is open source (MIT) and free; you pay only for the model you connect, whether an API key, a ChatGPT or Copilot sign-in, OpenCode's own pay-as-you-go models, or a local model.
  • As of November 2026 there are two release lines: opencode.ai/install and npm opencode-ai install OpenCode 1, while opencode.ai/v2/install and npm @opencode/cli install OpenCode 2.
  • Run /connect to add a provider, /init to generate AGENTS.md, and press Tab to switch between the Build and Plan agents.
  • OpenCode 1 allows edits and shell commands without asking by default; add permission rules in opencode.json before you let it touch a real repository.
  • OpenCode has no OS-level sandbox in its docs, so run unattended or --auto sessions inside a container, VM or separate server.

What is the OpenCode AI coding agent?

OpenCode is an open-source AI coding agent: you describe a task, and it reads your code, edits files and runs commands until the task is done. It runs as a terminal interface (TUI), a desktop app or an IDE extension, and it is not tied to one AI company, so you can drive it with Claude, GPT, Gemini, open-weight models or a model running on your own machine.

The project is built by Anomaly and lives at anomalyco/opencode on GitHub under the MIT license.

223,813GitHub stars on 1 November 2026
75+LLM providers supported
$10a month for the optional OpenCode Go plan
Sources: GitHub API for anomalyco/opencode, OpenCode docs (Providers, Go), November 2026

What sets OpenCode apart from Claude Code or Codex:

  • Any model. It uses the AI SDK and Models.dev, which the providers docs put at 75+ providers plus local models.
  • Open source. You can read the code, fork it and run it without an account with OpenCode.
  • Client and server. opencode serve runs a headless API and opencode attach connects a terminal UI to it, so the agent can run on one machine while you drive it from another.

How do you install OpenCode in 2026?

Install OpenCode with one command, then run opencode inside a project folder. As of November 2026 there are two release lines that both use the opencode command and cannot be installed side by side under it, so pick one first.

OpenCode 1OpenCode 2
Install scriptopencode.ai/installopencode.ai/v2/install
npm packageopencode-ai@opencode/cli
Homebrewbrew install anomalyco/tap/opencodebrew install anomalyco/tap/opencode-v2
Docsopencode.ai/docsopencode.ai/v2/docs
WindowsChocolatey, Scoop, Mise, npm; WSL recommendedWindows package managers not supported
Latest release (Nov 2026)v1.19.5 (28 October)v2.2.5 (30 October)

The GitHub README now leads with OpenCode 2, while the main docs site, the Ollama integration and most tutorials still describe OpenCode 1. The config examples in this guide follow the OpenCode 1 docs, and the permissions section shows where OpenCode 2 differs.

terminal
# OpenCode 1curl -fsSL https://opencode.ai/install | bash# or OpenCode 2curl -fsSL https://opencode.ai/v2/install | bashopencode --version

The OpenCode 2 install script puts the binary in $HOME/.opencode/bin. The docs ask for a modern terminal emulator such as WezTerm, Alacritty, Ghostty or Kitty. There is also a desktop app (beta) for macOS, Windows and Linux at opencode.ai/download, and a Docker image: docker run -it --rm ghcr.io/anomalyco/opencode.

How do you connect a model provider to OpenCode?

Run /connect inside OpenCode, pick a provider and paste a key or sign in. OpenCode stores credentials in ~/.local/share/opencode/auth.json, and opencode auth list shows which providers are set up.

OptionHow you payNotes
Anthropic, OpenAI, Google and other API keysPer token, billed by the providerCreate the key in the provider's console
ChatGPT Plus or ProYour existing ChatGPT plan/connect, OpenAI, then "ChatGPT Plus/Pro"
GitHub CopilotYour Copilot planDevice-code login; some models need Copilot Pro+
OpenCode pay-as-you-go modelsPrepaid credits, per token4.6% + $0.31 fee on each credit purchase; some models free for a limited time
OpenCode Go$10, $40 or $20 per member a monthOpen coding models with monthly and 5-hour usage caps
Ollama or LM StudioFree, runs on your hardwareNeeds a model that supports tool calls

Prices are as of November 2026; check the Go page before you subscribe.

One limit to know: you cannot use a Claude Pro or Max subscription in OpenCode. The providers docs say Anthropic explicitly prohibits it, and OpenCode stopped bundling the plugins that did it in version 1.3.0. For Claude models, use an API key. If you want Claude on your subscription, use Claude Code; our Codex vs Claude Code comparison covers how those two plans differ.

Switch models at any time with /models (or ctrl+x m). Model IDs use the provider/model form, for example anthropic/claude-sonnet-5-5, and opencode models lists every model you can reach.

How do you run OpenCode with local models through Ollama?

The fastest route is Ollama's own launcher, which configures OpenCode for you:

terminal
ollama launch opencode

To set it up by hand, add Ollama as an OpenAI-compatible provider. Replace the model ID with a model you have pulled:

opencode.json
{  "$schema": "https://opencode.ai/config.json",  "provider": {    "ollama": {      "npm": "@ai-sdk/openai-compatible",      "name": "Ollama (local)",      "options": { "baseURL": "http://localhost:11434/v1" },      "models": {        "qwen3.5": { "name": "Qwen 3.5" }      }    }  }}

The Ollama integration docs say OpenCode needs a context window of at least 64k tokens and a model that supports tools. If tool calls fail, the OpenCode docs suggest raising Ollama's num_ctx. Our guide to running an LLM locally covers hardware and model choice.

How do you start your first OpenCode session?

Open your project, start OpenCode, connect a model and let it write an AGENTS.md before the first real task. The whole setup takes a few minutes.

  1. Make sure the project is a Git repository and commit your current work, because /undo relies on Git.
  2. cd into the project and run opencode.
  3. Run /connect and add a provider, then pick a model with /models.
  4. Run /init. OpenCode scans the repository and creates AGENTS.md in the project root (or improves the one you have). Edit it down to build commands, test commands and rules the agent can't infer, then commit it.
  5. Press Tab to switch to the Plan agent and describe the task. Plan can't edit project files, so you get a proposal first.
  6. Read the plan, correct it, press Tab again to return to Build, and tell it to implement.
  7. Review the diff with git diff, run the tests, and use /undo if the change went wrong.

A first prompt that works well in Plan mode:

prompt
Read @src/api/users.ts and its tests. Plan how to add pagination to GET /users(limit and cursor query params, default limit 20, max 100). List the files youwould change and the tests you would add. Don't write code yet.

The @ key fuzzy-searches files to attach, and a message that starts with ! runs a shell command and adds its output to the conversation, for example !npm test.

Which OpenCode commands should you know?

The leader key is ctrl+x by default, so most commands have a two-step shortcut.

CommandShortcutWhat it does
/connectAdd a provider and key
/initCreate or update AGENTS.md
/modelsctrl+x mSwitch model
/newctrl+x nStart a fresh session (alias /clear)
/sessionsctrl+x lList and resume sessions
/compactctrl+x cSummarize a long session to free context
/undo / /redoctrl+x u / ctrl+x rRevert or reapply the last turn and its file changes
/exportctrl+x xSave the conversation as Markdown
/editorctrl+x eWrite the prompt in your $EDITOR
A developer typing on a laptop with code on the screen
OpenCode works in any modern terminal; commit before each task so /undo and git can take you back.

How do you configure OpenCode with opencode.json and AGENTS.md?

OpenCode reads JSON or JSONC config from opencode.json in the project root and ~/.config/opencode/opencode.json globally, and merges them, with project values winning on conflicts. Instructions for the agent go in AGENTS.md, not in the config.

A starting project config that sets the model and pulls in existing team docs as instructions:

opencode.json
{  "$schema": "https://opencode.ai/config.json",  "model": "anthropic/claude-sonnet-5-5",  "instructions": ["CONTRIBUTING.md", "docs/guidelines.md"]}

A separate small_model key sets a cheaper model for light jobs such as session titles. The $schema line gives you autocomplete in most editors. Global rules that apply to every project go in ~/.config/opencode/AGENTS.md.

Coming from Claude Code? OpenCode reads a project CLAUDE.md when no AGENTS.md exists, reads ~/.claude/CLAUDE.md when you have no global OpenCode rules file, and loads skills from ~/.claude/skills/. Set OPENCODE_DISABLE_CLAUDE_CODE=1 to turn that off. The rules docs list the precedence.

How do you add MCP servers to OpenCode?

MCP servers go under the mcp key, as local (a command OpenCode starts) or remote (a URL):

opencode.json
{  "$schema": "https://opencode.ai/config.json",  "mcp": {    "playwright": {      "type": "local",      "command": ["npx", "-y", "@playwright/mcp@latest"]    },    "docs": {      "type": "remote",      "url": "https://mcp.example.com/mcp",      "headers": { "Authorization": "Bearer {env:DOCS_MCP_TOKEN}" }    }  }}

Remote servers that need OAuth start the login flow on their own; opencode mcp auth <name> and opencode mcp list manage it. The MCP docs warn that every server adds to your context, and some, such as the GitHub MCP server, add enough tokens to hit the limit, so enable only what a project needs. Our explainer on what MCP is covers the protocol itself.

How do OpenCode permissions work, and how do you make it safer?

Every tool call resolves to allow, ask or deny. In OpenCode 1 almost everything defaults to allow: the agent can edit files and run shell commands without asking. Only reading .env files, touching paths outside the project (external_directory) and repeating the same tool call three times in a row (doom_loop) ask first.

That default suits a throwaway container, not your main laptop. A safer OpenCode 1 config:

opencode.json (OpenCode 1)
{  "$schema": "https://opencode.ai/config.json",  "permission": {    "edit": "ask",    "bash": {      "*": "ask",      "git status *": "allow",      "git diff *": "allow",      "npm test *": "allow",      "rm *": "deny",      "git push *": "deny"    },    "webfetch": "ask"  }}

The last matching rule wins, so put the catch-all "*" first. Write "git diff *" rather than "git diff", because a pattern without * doesn't match the command with arguments.

OpenCode 2 changed the format. Permissions become an ordered permissions array of rules with action, resource and effect, bash is renamed shell, and task is renamed subagent:

opencode.jsonc (OpenCode 2)
{  "$schema": "https://opencode.ai/config.json",  "permissions": [    { "action": "shell", "resource": "*", "effect": "ask" },    { "action": "shell", "resource": "git diff *", "effect": "allow" },    { "action": "shell", "resource": "git push *", "effect": "deny" }  ]}
Warning

Permission rules are pattern matching inside the agent, and OpenCode's docs describe no operating-system sandbox. Claude Code, by comparison, has a /sandbox mode that uses Seatbelt on macOS and bubblewrap on Linux. For opencode run --auto or any session you don't watch, put OpenCode in a container, VM or separate server with no secrets you care about. Our guide to sandboxing AI coding agents shows practical setups.

How do agents and subagents work in OpenCode?

OpenCode ships two primary agents you switch between with Tab, Build (full access, the default) and Plan (no edits to project files), plus two subagents the main agent can call: General for multi-step research and Explore for fast read-only code search. Mention one directly with @general or @explore in a message.

You can add your own agents as Markdown files in .opencode/agents/ (project) or ~/.config/opencode/agents/ (global). The file name becomes the agent name, the front matter holds settings and the body is the system prompt. A read-only reviewer in OpenCode 1 format:

.opencode/agents/review.md
---description: Reviews the current diff for bugs, security issues and missing testsmode: subagentpermission:  edit: deny  bash:    "*": ask    "git diff *": allow    "git log *": allow---Review the uncommitted changes. Report bugs, security problems and missingtests, most serious first, with file and line. Do not modify files.

Ask for it with @review check my changes. opencode agent create builds one interactively, and opencode agent list shows what loaded. Write descriptions carefully: the primary agent decides when to call a subagent from its description.

OpenCode vs Claude Code vs Codex: which should you use?

Pick OpenCode when you want model choice, local models or an open codebase; pick Claude Code or Codex when you already pay for Claude or ChatGPT and want the vendor's tuned agent with its sandbox. All three read your repo, edit files, run commands and support MCP.

OpenCodeClaude CodeCodex CLI
MakerAnomalyAnthropicOpenAI
LicenseMITProprietaryApache-2.0
Models75+ providers and localClaude modelsOpenAI models
Subscription useChatGPT Plus/Pro, Copilot, OpenCode GoClaude Pro ($20), Max (from $100), TeamChatGPT Free, Go, Plus, Pro, Business
Instructions fileAGENTS.md (falls back to CLAUDE.md)CLAUDE.md (can read AGENTS.md)AGENTS.md
OS sandboxNot in docsOptional, /sandboxOn by default
Default edit approvalAllowed (OpenCode 1)AsksDepends on sandbox and approval mode
Headlessopencode runclaude -pcodex exec

Plan prices are monthly list prices from the Claude and Codex pricing pages as of November 2026.

The model behind the agent decides most of the quality: OpenCode with a strong model handles multi-file changes, while a small local model will struggle with them. Nothing stops you from keeping two agents installed and using OpenCode for the providers your main tool doesn't offer. The Codex CLI guide covers the sandbox modes mentioned in the table.

How do you run OpenCode in scripts and unattended?

opencode run "<prompt>" runs one task without the interface, which makes OpenCode usable from scripts, cron and CI. Add --format json for machine-readable events, --model and --agent to pin the setup, and --continue to pick up the last session.

terminal
opencode run --agent plan --format json \  "List every TODO in src/ with file, line and a one-line summary"

--auto approves every permission request that isn't explicitly denied, so only use it with deny rules in place and inside an isolated environment. For a long-running setup, opencode serve starts a headless HTTP server (set OPENCODE_SERVER_PASSWORD to require a password) and opencode attach http://host:4096 connects your terminal to it. opencode github install sets up a GitHub Action that responds to /opencode or /oc in issue and pull request comments.

Unattended agents need a machine that stays on. If you mainly run Claude Code or Codex, Orkio rents an always-on, isolated cloud box where those agents keep working after you close your laptop, and you review the pull requests from your phone or the web.

OpenCode setup checklist

Work through this once and most first-week problems go away:

  1. Choose OpenCode 1 or 2 and install it with one method only.
  2. Commit your work; confirm the project is a Git repository.
  3. Run /connect and pick a model you trust with multi-file edits.
  4. Run /init, trim AGENTS.md to commands and rules, commit it.
  5. Add permission rules: bash on ask, allow your test and git read commands, deny rm and git push.
  6. Add only the MCP servers this project needs.
  7. Start every non-trivial task in Plan mode, then switch to Build.
  8. Review each diff and run the tests before you commit.
  9. Keep --auto and unattended runs inside a container or a separate server.

Frequently asked questions

Is OpenCode free?

The OpenCode software is free and MIT-licensed. You pay for the model behind it: your own API key, an existing ChatGPT Plus/Pro or GitHub Copilot subscription, OpenCode's pay-as-you-go model catalog, or the OpenCode Go subscription from $10 a month as of November 2026. Local models through Ollama cost nothing beyond your hardware.

Can I use my Claude Pro or Max subscription with OpenCode?

Not in a supported way. OpenCode's provider docs say Anthropic explicitly prohibits using Claude Pro or Max through third-party plugins, and OpenCode stopped bundling such plugins in version 1.3.0. To use Claude models in OpenCode, connect an Anthropic API key from the Anthropic Console.

Does OpenCode read CLAUDE.md files?

Yes, as a fallback. OpenCode reads AGENTS.md first and uses a project CLAUDE.md only when no AGENTS.md exists, and it reads ~/.claude/CLAUDE.md when you have no global ~/.config/opencode/AGENTS.md. You can turn this off with the OPENCODE_DISABLE_CLAUDE_CODE environment variable.

Does OpenCode work on Windows?

OpenCode 1 installs on Windows through Chocolatey, Scoop, Mise or npm, and its docs recommend running it inside WSL for the best experience. The OpenCode 2 docs say Windows package managers are not supported, so on Windows use WSL or follow the v2 install page.

Can OpenCode undo its changes?

Yes. The /undo command removes your last message, the responses after it and the related file changes, and /redo puts them back. Both rely on Git, so the project must be a Git repository, and committing before large tasks is still the safer habit.

Is OpenCode safe to run on my laptop?

It is as safe as the permissions you give it. OpenCode 1 lets the agent edit files and run shell commands without approval by default, and the docs describe no OS sandbox. Set bash to ask, deny destructive commands, keep secrets out of the project, and run unattended sessions in a container or separate machine.

SOURCES

  1. OpenCode docs: Intro and install
  2. OpenCode docs: Permissions
  3. OpenCode docs: Providers
  4. OpenCode v2 docs
  5. OpenCode on GitHub (anomalyco/opencode)
  6. OpenCode docs: Go subscription
  7. Ollama docs: OpenCode integration
  8. Claude Code docs: Sandboxing
  • #opencode
  • #ai coding
  • #open source
  • #terminal
Orkio team

The team building Orkio. We write about putting AI to work: coding agents that run overnight, always-on boxes and pull requests ready by morning.

Keep reading

All posts

07:06 · YOU MERGED #128

Go to sleep. Wake up to pull requests.

Start for $19 a month
© 2026 Orkio · Hosted in Europe TürkçeStatus