How to use OpenCode: install, plan and build, MCP
Explore with AI
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.
1. Install OpenCode
The install script is the quickest route:
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:
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
/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:
{
"$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:
{
"$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: logs, traces and deploys from every provider you connect, behind one sign-in.
Using OpenCode? See how to give OpenCode production context with Polylane.
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 (2)
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
- 1 How to use Claude Code: a practical guide
- 2 How to add MCP servers to Cursor
- 3 How to use Codex CLI: install, AGENTS.md, MCP and exec
- 4 How to use OpenCode: install, plan and build, MCP
- 5 How to add MCP servers to GitHub Copilot in VS Code
- 6 How to use the Pi coding agent
Related
- Railway activity feed filters and cron jobs in the CLI Railway's 16 October 2026 update: filter the activity feed by service, list and trigger cron runs with railway cron, and migrate railway.json to IaC.
- Cloudflare Tunnel: 50,000 routes and Tunnels for Platforms Cloudflare raised Tunnel routes to 50,000 per account on 16 October 2026 and launched Tunnels for Platforms at $4.50 a tunnel. Limits, setup and gotchas.
- How to deploy Vite apps to Cloudflare with Void Void, announced by Cloudflare on 15 October 2026, deploys Vite apps to Workers in one command. Setup steps, secrets, migrations, CI and the gotchas.
- CloudWatch log centralisation: GovCloud and 13 new Regions AWS added CloudWatch log centralisation to GovCloud (US) and 13 commercial Regions on 16 October 2026. Setup steps, pricing, limits and gotchas.
- How to Monitor a Next.js App on Render Monitor a Next.js app on Render: a health route that checks the database, JSON logs with Rndr-Id, onRequestError, OpenTelemetry traces, streams and alerts.