OpenCode — Getting Started

Install and configure OpenCode, the multi-provider AI coding agent. Covers installation, LLM provider setup, Zen/Go pricing, and first session walkthrough.

opencodeterminal-agentmulti-providersetup

OpenCode — Getting Started

OpenCode is a terminal-based AI coding agent that works with 75+ LLM providers. Unlike Claude Code (Anthropic-only) or Gemini CLI (Google-only), OpenCode lets you choose your model, pay what you want, and customize every aspect of the agent.

Installation

# Via npm
npm install -g @opencode-ai/cli

# Via Homebrew
brew install opencode/tap/cli

# Verify
opencode --version

Provider Setup

OpenCode Provider Map

OpenCode supports any OpenAI-compatible endpoint. Choose your provider:

Quick Setup — Common Providers

# Anthropic (via API key)
export ANTHROPIC_API_KEY="sk-ant-..."

# OpenAI
export OPENAI_API_KEY="sk-..."

# Google Gemini
export GOOGLE_API_KEY="..."

# DeepSeek (95% cheaper than Anthropic for coding)
export DEEPSEEK_API_KEY="sk-..."

# OpenRouter (300+ models, one API key)
export OPENROUTER_API_KEY="sk-or-..."

Configure in ~/.config/opencode/opencode.json or opencode.json (project root):

{
  "provider": "anthropic",
  "model": "claude-sonnet-4-20250514",
  "providers": {
    "anthropic": {
      "apiKey": "${ANTHROPIC_API_KEY}",
      "baseUrl": "https://api.anthropic.com/v1"
    },
    "openai": {
      "apiKey": "${OPENAI_API_KEY}"
    },
    "deepseek": {
      "apiKey": "${DEEPSEEK_API_KEY}",
      "baseUrl": "https://api.deepseek.com/v1"
    }
  }
}

Pricing Plans

TierPriceWhat You Get
Free$0Bring your own API key, 30+ providers, community skills
Zen$10/moPriority support, provider management, feedback loop
Go$20/moSOC2 compliance, audit logs, custom model training

First Session

cd my-project
opencode

On first run, OpenCode asks which provider and model to use:

⚡ Welcome to OpenCode!

  Choose a provider:
  > 1. Anthropic (recommended for complex coding)
    2. OpenAI
    3. DeepSeek (budget-friendly)
    4. Google Gemini (1M context)
    5. OpenRouter (300+ models)
    
  1. Anthropic
  
  Choose a model:
  > 1. claude-sonnet-4-20250514 ($3/M tokens)
    2. claude-opus-4-20250514 ($15/M tokens)
    
>

Essential Slash Commands

CommandWhat it does
/helpShow all slash commands
/provider <name>Switch LLM provider mid-session
/model <name>Switch model mid-session
/skill <name>Load a skill into context
/planEnter plan mode (scoped analysis)
/clearClear conversation history
/costShow token usage and cost for this session
/exportExport conversation to a markdown file

Project Configuration: AGENTS.md

Like Claude Code's CLAUDE.md, OpenCode reads AGENTS.md every session. Create it at your project root:

# AGENTS.md

## Commands
- `npm run dev` — Start development server at localhost:3000
- `npm run build` — Production build with type checking
- `npx vitest run` — Run all tests
- `npx eslint .` — Lint check

## Project Architecture
- Next.js 14 with App Router and React Server Components
- TypeScript strict mode with path alias @/
- SQLite via better-sqlite3 — no ORM, raw SQL
- Zero API dependencies for now

## Code Style
- Use async/await in server components for data fetching
- Extract business logic from components into lib/ immediately
- Tests go next to the file they test (co-location)

Provider Selection Strategy

If you need...Use...
Best reasoning for complex tasksAnthropic (Claude Sonnet/Opus)
Budget coding (95% cheaper)DeepSeek V4
Massive context (1M+ tokens)Google Gemini
Flexibility (300+ models)OpenRouter
Self-hosted / air-gappedOllama (local)

OpenCode's key advantage: switch providers mid-session with /provider. Debug with Sonnet, then switch to DeepSeek for less demanding work.