Getting Started
Install
Install the V2 beta from the next distribution tag:
npm install -g @opencode-ai/cli@next
Or with Bun:
bun install -g --trust @opencode-ai/cli@next
Tip: OpenCode 2 installs and runs as
opencode2. It does not replace V1’sopencodebinary, so you can keep both versions installed side by side.
Prerequisites
- A modern terminal emulator (Ghostty, WezTerm, Alacritty, or Kitty)
- 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:
opencode2
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):
~/.config/opencode/opencode.json(c)- global<project-root>/opencode.json(c)- project root<current-dir>/opencode.json(c)- current directory.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:
opencode2 serve --hostname 127.0.0.1 --port 4096
Connect with the TypeScript client:
import { OpenCode } from "@opencode-ai/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" })