# How to use OpenCode: install, plan and build, MCP

> How to use OpenCode: install it, connect a provider, write an AGENTS.md with /init, switch between Plan and Build, undo changes and add MCP servers.

Part 4 of [Using coding agents: Claude Code, Cursor, Codex and more](https://polylane.com/series/using-coding-agents/)
By Boris Tane, Founder of Polylane · Published October 17, 2026 · 3 min read
Canonical: https://polylane.com/learn/coding-agents/how-to-use-opencode/

To use OpenCode, install it with the install script, run opencode in your project and use /connect to add a model provider. Run /init to create an AGENTS.md, press Tab to switch between the Plan and Build agents, and use /undo to revert a change. Add MCP servers under mcp in opencode.json.

To use OpenCode, **install it, connect a model provider with `/connect`, run `/init` to create an AGENTS.md, and switch between the Plan and Build agents with Tab.** Undo anything you don't like with `/undo`, and add MCP servers in `opencode.json` to give it tools beyond your repository.

OpenCode is an open-source coding agent for the terminal. The steps below follow [OpenCode's documentation](https://opencode.ai/docs/).

## 1. Install OpenCode

The install script is the quickest route:

```bash
curl -fsSL https://opencode.ai/install | bash
```

It is also on npm (`npm install -g opencode-ai`) and Homebrew (`brew install anomalyco/tap/opencode`), with Chocolatey, Scoop and Docker options for Windows.

## 2. Connect a model provider

Start OpenCode in your project:

```bash
cd ~/code/my-app
opencode
```

Then run `/connect` in the interface, pick the provider, sign in and paste the API key it gives you.

## 3. Create an AGENTS.md

```text
/init
```

`/init` analyses your project and creates an AGENTS.md in the project root. Read it, cut anything vague, add the commands to build and test, and commit it: OpenCode's docs recommend checking it into Git so everyone on the project shares it.

## 4. Plan first, then build

OpenCode has two primary agents, and Tab switches between them:

- **Plan** blocks changes and suggests how to implement what you asked.
- **Build** makes the changes.

For anything bigger than a small fix, start in Plan, read and correct the plan, then press Tab and let Build do it.

## 5. Undo and redo

`/undo` reverts the most recent changes and restores the prompt that caused them, so you can rephrase and try again. Run it several times to step further back. `/redo` puts an undone change back.

## 6. Add MCP servers

OpenCode reads MCP servers from the `mcp` object in `opencode.json`. A remote server needs its `url`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "polylane": {
      "type": "remote",
      "url": "https://mcp.polylane.com/mcp",
      "enabled": true
    }
  }
}
```

A local server gives the `command` as an array, with any `environment` it needs:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "context7": {
      "type": "local",
      "command": ["npx", "-y", "@upstash/context7-mcp"],
      "enabled": true
    }
  }
}
```

For a remote server that needs sign-in, OpenCode starts the OAuth flow when the server answers with a 401, using dynamic client registration when the server supports it. `opencode mcp list` shows your servers, and `opencode mcp auth <name>` runs the sign-in by hand.

The remote server in the first example is Polylane's. [It brings production into OpenCode](/for/opencode/): logs, traces and deploys from every provider you connect, behind one sign-in.

Using OpenCode? See [how to give OpenCode production context with Polylane](https://polylane.com/for/opencode/).

## Common questions

**How do I install OpenCode?**

Run curl -fsSL https://opencode.ai/install | bash, or install it with npm (npm install -g opencode-ai) or Homebrew (brew install anomalyco/tap/opencode).

**What is the difference between Plan and Build in OpenCode?**

Plan blocks changes and suggests how to implement what you asked. Build makes the changes. Press Tab to switch between them.

**How do I undo a change OpenCode made?**

Run /undo. It reverts the most recent changes and restores your original prompt, and you can run it more than once. /redo puts an undone change back.

**Should I commit AGENTS.md?**

Yes. OpenCode's docs recommend committing the AGENTS.md that /init creates, so everyone on the project starts from the same instructions.

**How does OpenCode sign in to a remote MCP server?**

For a server that needs it, OpenCode detects the 401 response and starts the OAuth flow on its own, using dynamic client registration when the server supports it. opencode mcp auth with the server's name runs it by hand.

## Sources

- [Intro (OpenCode docs)](https://opencode.ai/docs/)
- [MCP servers (OpenCode docs)](https://opencode.ai/docs/mcp-servers/)

## About the author

Boris Tane is the founder of Polylane. He previously founded Baselime, observability for the future of the cloud, which Cloudflare acquired. At Cloudflare he built and led the Workers observability team.

## More in this series

[Using coding agents: Claude Code, Cursor, Codex and more](https://polylane.com/series/using-coding-agents/)

1. [How to use Claude Code: a practical guide](https://polylane.com/learn/coding-agents/how-to-use-claude-code/)
2. [How to add MCP servers to Cursor](https://polylane.com/learn/coding-agents/how-to-add-mcp-servers-to-cursor/)
3. [How to use Codex CLI: install, AGENTS.md, MCP and exec](https://polylane.com/learn/coding-agents/how-to-use-codex-cli/)
4. [How to use OpenCode: install, plan and build, MCP](https://polylane.com/learn/coding-agents/how-to-use-opencode/)
5. [How to add MCP servers to GitHub Copilot in VS Code](https://polylane.com/learn/coding-agents/how-to-add-mcp-servers-to-github-copilot/)
6. [How to use the Pi coding agent](https://polylane.com/learn/coding-agents/how-to-use-the-pi-coding-agent/)

Previous: [How to use Codex CLI: install, AGENTS.md, MCP and exec](https://polylane.com/learn/coding-agents/how-to-use-codex-cli/)
Next: [How to add MCP servers to GitHub Copilot in VS Code](https://polylane.com/learn/coding-agents/how-to-add-mcp-servers-to-github-copilot/)

Get started with one command: `curl -fsSL https://polylane.com/setup | bash` installs the CLI, connects your coding agents, and creates the account.
