Getting Started

Install

Install OpenCode (2.x is the mainline distribution). The curl installer is the reliable path - on npm, the opencode-ai package’s latest tag still served V1 1.18.34 as of October 2026:

npm install -g opencode-ai@next  # verify the version after install: opencode --version

Or with Bun:

bun install -g --trust opencode-ai

Tip: The curl installer (https://opencode.ai/install) is the recommended path on Linux/macOS. The opencode binary name survives as a legacy alias from the beta side-by-side period; use opencode.

Prerequisites

  1. A modern terminal emulator (Ghostty, WezTerm, Alacritty, or Kitty)
  2. API keys for LLM providers you want to use

Connect a Provider

Run /connect in the TUI and select your provider:

/connect

Or configure providers in opencode.jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "providers": {
    "anthropic": {
      "settings": {
        "apiKey": "{env:ANTHROPIC_API_KEY}"
      }
    }
  }
}

Use /models to browse available providers and models.

Start Coding

Launch the TUI in your project:

opencode

Common workflows:

How is authentication handled in @packages/functions/src/api/index.ts
When a user deletes a note, flag it as deleted in the database.
Create a screen that shows recently deleted notes.
/undo

Tip: Use @ to fuzzy search for files in the project. Give OpenCode plenty of context and examples for best results.

Config Locations

OpenCode loads config from these locations (lowest to highest precedence):

  1. ~/.config/opencode/opencode.json(c) - global
  2. <project-root>/opencode.json(c) - project root
  3. <current-dir>/opencode.json(c) - current directory
  4. .opencode/opencode.json(c) in any of the above - overrides direct configs
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "default_agent": "build"
}

Run as a Server

OpenCode can run as a server, allowing custom clients to connect:

opencode serve --hostname 127.0.0.1 --port 4096

Connect with the TypeScript client:

import { OpenCode } from "@opencode/client"

const client = OpenCode.make({ baseUrl: "http://localhost:4096" })
const session = await client.session.create({
  location: { directory: "/workspace" },
})
await client.session.prompt({ sessionID: session.id, text: "Review changes" })