OpenCode — AI Coding Agent
Complete guide to OpenCode 2, the open-source coding agent with a shared background service, Code Mode, background subagents, and 75+ providers. Covers setup, configuration, and best practices.
OpenCode — AI Coding Agent
OpenCode is an open-source AI coding agent. OpenCode 2 runs the agent as a shared background service, with clients for the terminal, web, and desktop. It reads your codebase, writes and edits files, executes terminal commands, and can drive multi-step engineering tasks.
Its defining difference is provider freedom. Where most agents lock you into one vendor's model, OpenCode supports 75+ LLM providers and lets you switch models mid-session, so you can use the best (or cheapest) model for each part of a task — and run entirely on local models if you want.
How OpenCode Works
OpenCode is built around the same agent loop as other modern coding agents, but emphasizes configurability:
- Shared background service — One server owns sessions, configuration, permissions, and tool execution. The TUI, web client, and desktop app attach to it, so work started in one client is visible in another.
- Interactive terminal UI — A TUI session where you steer the agent, see its plan, review diffs, and continue iterating.
- AGENTS.md conventions — Project-level instruction files that define how OpenCode behaves in your repo: architecture, style, commands to use or avoid.
- Provider flexibility — Bring your own API keys for Anthropic, OpenAI, Google, DeepSeek, and dozens more, or point it at Ollama, LM Studio, or vLLM.
- Code Mode — MCP servers and OpenAPI endpoints are exposed as JavaScript functions inside a sandboxed interpreter, so the agent can compose tools in one step instead of one round trip per call.
- Skills system — Reusable instruction bundles that load on demand for specialized tasks.
- MCP support — Full Model Context Protocol integration for external tools and servers.
- Background work — Subagents and shell commands can run in the background while the primary agent continues.
Because it's open source and provider-agnostic, OpenCode is a strong choice when you want the power of a terminal agent without vendor lock-in, model markup, or closed-source telemetry.
Core Features
- Provider flexibility — 75+ LLM providers; switch models mid-session (e.g., Gemini for planning, DeepSeek for cost-sensitive edits).
- Code Mode — MCP and OpenAPI tools become composable functions; large MCP catalogs no longer bloat the provider tool list.
- Background subagents — Delegate review or test runs without blocking the main session; press
Ctrl+Bto demote running work. - Skills system — Package specialized workflows for reuse across sessions.
- Custom rules —
AGENTS.mdconventions for project-specific instructions. - Local models — Run entirely offline with Ollama, LM Studio, or vLLM.
- Interactive TUI — Review plans, diffs, and command execution live before approving.
- SDK and API —
@opencode/sdkembeds the agent in your own application;@opencode/clienttalks to a running server. - Open source — MIT licensed and self-hostable.
Quick Start
# Install globally
npm install -g @opencode/cli
# Or use the install script
curl -fsSL https://opencode.ai/v2/install | bash
# Run in your project directory
opencode
On first launch, OpenCode asks which provider and model to use. Then:
- Run
opencodein your project root. - Connect a provider with
/connectand pick a model with/models. - Describe a task — OpenCode will read the repo, plan, and start working.
- Review its approach and approve commands as it executes.
- Switch providers mid-session if you want a different model for a subtask.
For a full walkthrough, see Getting Started with OpenCode.
Writing Effective Prompts
The same prompt discipline that works for other agents applies to OpenCode:
- Give it a goal and a definition of done — "Add a
/searchendpoint with tests and docs" beats "implement search." - Reference your repo — Point it at existing patterns: "Mirror the auth middleware in
src/middleware.ts." - Keep
AGENTS.mdcurrent — Put stable conventions there so the agent doesn't re-derive them each session. - Use skills for repeatable work — If you run the same review or scaffolding task often, package it as a skill.
- Push long work into the background — Ask for a review subagent or a background test run instead of waiting serially.
Skills are where that last bullet pays off: the skills collection lists installable packs per tool, and find-skills is the meta-skill for discovering ones you have not installed yet.
For conventions, slash commands, and provider guidance, see Prompt Engineering in OpenCode. For the full reference on opencode.jsonc, skills, plugins, and MCP, see Configuration Reference.
OpenCode vs Claude Code vs Copilot
| Feature | OpenCode | Claude Code | GitHub Copilot |
|---|---|---|---|
| Open source | ✓ | ✗ | ✗ |
| Terminal agent | ✓ | ✓ | CLI only |
| Provider choice | 75+ / local | Anthropic | GitHub-hosted |
| Switch models mid-task | ✓ | ✗ | ✗ |
| Local models | ✓ | ✗ | ✗ |
| Custom rules | AGENTS.md | CLAUDE.md | copilot-instructions.md |
| Skills system | ✓ | Partial (subagents) | ✗ |
| MCP support | ✓ | ✓ | ✓ |
Claude Code is the most polished terminal agent for Anthropic models; OpenCode is the most flexible — open source, model-agnostic, local-first, and scriptable through its SDK. Copilot remains the best choice for teams deeply embedded in the GitHub ecosystem.
Pricing
OpenCode is free to use with your own API keys — you pay the model provider directly. Optional paid tiers run through the OpenCode Console:
| Plan | Price | What it adds |
|---|---|---|
| Free | $0 | Bring your own key, local models, community skills |
| Console | Pay-as-you-go | Managed inference, usage tracking, team workspaces, policies |
| Go | $10/mo | Monthly usage limits on open coding models |
| Go Plus | $40/mo | Higher limits on the same models |
| Go Teams | $20/member/mo | Per-member limits in a workspace |
Frequently Asked Questions
Related Resources
- Getting Started — install, configure, and begin your first session
- Prompt Engineering — AGENTS.md conventions, slash commands, and prompt patterns
- Configuration Reference —
opencode.jsonc, skills, plugins, and permission rules - Session History — query the local SQLite database
Related Articles & Guides
Pi — Terminal AI Coding Agent
Complete guide to pi, Mario Zechner's minimal terminal coding agent. Covers installation, prompt engineering, context files, skills, and the lean-harness philosophy.
Jcode — AI Coding Agent
Complete guide to jcode, the RAM-efficient open-source AI coding agent in Rust. Covers installation, prompt engineering, configuration, memory, swarms, and advanced workflows.
OpenCode — Getting Started
Install and configure OpenCode 2, the multi-provider AI coding agent. Covers V2 installation, provider setup, Console and Go pricing, and the first session.