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.
- 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/installand npmopencode-aiinstall OpenCode 1, whileopencode.ai/v2/installand npm@opencode/cliinstall OpenCode 2. - Run
/connectto add a provider,/initto generateAGENTS.md, and press Tab to switch between the Build and Plan agents. - OpenCode 1 allows edits and shell commands without asking by default; add
permissionrules inopencode.jsonbefore you let it touch a real repository. - OpenCode has no OS-level sandbox in its docs, so run unattended or
--autosessions 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.
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 serveruns a headless API andopencode attachconnects 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 1 | OpenCode 2 | |
|---|---|---|
| Install script | opencode.ai/install | opencode.ai/v2/install |
| npm package | opencode-ai | @opencode/cli |
| Homebrew | brew install anomalyco/tap/opencode | brew install anomalyco/tap/opencode-v2 |
| Docs | opencode.ai/docs | opencode.ai/v2/docs |
| Windows | Chocolatey, Scoop, Mise, npm; WSL recommended | Windows 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.
# OpenCode 1curl -fsSL https://opencode.ai/install | bash# or OpenCode 2curl -fsSL https://opencode.ai/v2/install | bashopencode --versionThe 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.
| Option | How you pay | Notes |
|---|---|---|
| Anthropic, OpenAI, Google and other API keys | Per token, billed by the provider | Create the key in the provider's console |
| ChatGPT Plus or Pro | Your existing ChatGPT plan | /connect, OpenAI, then "ChatGPT Plus/Pro" |
| GitHub Copilot | Your Copilot plan | Device-code login; some models need Copilot Pro+ |
| OpenCode pay-as-you-go models | Prepaid credits, per token | 4.6% + $0.31 fee on each credit purchase; some models free for a limited time |
| OpenCode Go | $10, $40 or $20 per member a month | Open coding models with monthly and 5-hour usage caps |
| Ollama or LM Studio | Free, runs on your hardware | Needs 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:
ollama launch opencodeTo set it up by hand, add Ollama as an OpenAI-compatible provider. Replace the model ID with a model you have pulled:
{ "$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.
- Make sure the project is a Git repository and commit your current work, because
/undorelies on Git. cdinto the project and runopencode.- Run
/connectand add a provider, then pick a model with/models. - Run
/init. OpenCode scans the repository and createsAGENTS.mdin 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. - Press Tab to switch to the Plan agent and describe the task. Plan can't edit project files, so you get a proposal first.
- Read the plan, correct it, press Tab again to return to Build, and tell it to implement.
- Review the diff with
git diff, run the tests, and use/undoif the change went wrong.
A first prompt that works well in Plan mode:
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.
| Command | Shortcut | What it does |
|---|---|---|
/connect | Add a provider and key | |
/init | Create or update AGENTS.md | |
/models | ctrl+x m | Switch model |
/new | ctrl+x n | Start a fresh session (alias /clear) |
/sessions | ctrl+x l | List and resume sessions |
/compact | ctrl+x c | Summarize a long session to free context |
/undo / /redo | ctrl+x u / ctrl+x r | Revert or reapply the last turn and its file changes |
/export | ctrl+x x | Save the conversation as Markdown |
/editor | ctrl+x e | Write the prompt in your $EDITOR |

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:
{ "$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):
{ "$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:
{ "$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:
{ "$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" } ]}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:
---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.
| OpenCode | Claude Code | Codex CLI | |
|---|---|---|---|
| Maker | Anomaly | Anthropic | OpenAI |
| License | MIT | Proprietary | Apache-2.0 |
| Models | 75+ providers and local | Claude models | OpenAI models |
| Subscription use | ChatGPT Plus/Pro, Copilot, OpenCode Go | Claude Pro ($20), Max (from $100), Team | ChatGPT Free, Go, Plus, Pro, Business |
| Instructions file | AGENTS.md (falls back to CLAUDE.md) | CLAUDE.md (can read AGENTS.md) | AGENTS.md |
| OS sandbox | Not in docs | Optional, /sandbox | On by default |
| Default edit approval | Allowed (OpenCode 1) | Asks | Depends on sandbox and approval mode |
| Headless | opencode run | claude -p | codex 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.
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:
- Choose OpenCode 1 or 2 and install it with one method only.
- Commit your work; confirm the project is a Git repository.
- Run
/connectand pick a model you trust with multi-file edits. - Run
/init, trimAGENTS.mdto commands and rules, commit it. - Add
permissionrules:bashon ask, allow your test and git read commands, denyrmandgit push. - Add only the MCP servers this project needs.
- Start every non-trivial task in Plan mode, then switch to Build.
- Review each diff and run the tests before you commit.
- Keep
--autoand 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.



