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": {
"praxen": {
"type": "remote",
"url": "https://mcp.getpraxen.app/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 Praxen Inc.’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 Praxen Inc..
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)
About the author
Founder of Praxen Inc.
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
- How to correlate incidents with deploys using evidence Learn how to correlate incidents with deploys using release markers, metrics, logs and verified GitHub, Vercel, Cloudflare and Kubernetes change events.
- What is change intelligence? A production safety guide What is change intelligence? Learn how deploys, config, flags, infrastructure and dependency changes connect to incidents, using tools you already have.
- Turn your app into a context graph Agents that run software need a context graph of the app: every resource, what it connects to, the repository that deploys it and the team that owns it. How we built one on Durable Objects, keep it fresh across every provider without polling AWS, decide what counts as a change, and delete from it safely.
- How to use Claude Code to debug production issues Debug production issues with Claude Code: get logs and traces into the session, test hypotheses against evidence, stay read-only and ship a verified fix.
- Is it safe to give an AI SRE read access to production? Read access for an AI SRE is a sound first step if you scope it. The risks are secrets, customer data and exfiltration. Here are the controls and a checklist.