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.

October 20, 2026
opencodeai-codingterminal-agentsetupprompt-engineering

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+B to demote running work.
  • Skills system — Package specialized workflows for reuse across sessions.
  • Custom rules — AGENTS.md conventions 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/sdk embeds the agent in your own application; @opencode/client talks 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:

  1. Run opencode in your project root.
  2. Connect a provider with /connect and pick a model with /models.
  3. Describe a task — OpenCode will read the repo, plan, and start working.
  4. Review its approach and approve commands as it executes.
  5. 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 /search endpoint 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.md current — 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

FeatureOpenCodeClaude CodeGitHub Copilot
Open source✓✗✗
Terminal agent✓✓CLI only
Provider choice75+ / localAnthropicGitHub-hosted
Switch models mid-task✓✗✗
Local models✓✗✗
Custom rulesAGENTS.mdCLAUDE.mdcopilot-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:

PlanPriceWhat it adds
Free$0Bring your own key, local models, community skills
ConsolePay-as-you-goManaged inference, usage tracking, team workspaces, policies
Go$10/moMonthly usage limits on open coding models
Go Plus$40/moHigher limits on the same models
Go Teams$20/member/moPer-member limits in a workspace

Frequently Asked Questions