Skip to content
>_devvkit
$devvkit learn --librarie opencode-guide

OpenCode Guide

[ai][cli][agent][vibe-coding]
AI / LLM Tools
Install
curl -fsSL https://opencode.ai/install | bash
# Or:
npm install -g @opencode/opencode
# Requires: API key (or use free models via Zen)

OpenCode is an open-source AI coding agent by Anomaly. With 160K+ GitHub stars and 900+ contributors, it is one of the most popular AI coding tools. It works as a terminal CLI, desktop app, or IDE extension.

OpenCode is LSP-aware — it automatically loads the right language servers so the LLM understands your project's type system, symbols, and imports. Start a session with `opencode` and describe your task in natural language. OpenCode reads and writes files, runs commands, and makes git commits.

A key feature is multi-session support — run multiple agents in parallel on the same project. OpenCode also integrates with GitHub Copilot and ChatGPT Plus/Pro accounts, so you can use existing subscriptions. For privacy, OpenCode does not store your code or context.

Setup

Start a sessionLaunch OpenCode in your project.
# Install:
curl -fsSL https://opencode.ai/install | bash

# Start interactive session:
opencode

# One-shot prompt:
opencode "Add input validation to all API routes"

# Desktop app (beta):
# Download from opencode.ai/download

Basic Workflows

File operationsRead, write, edit files.
# OpenCode works at the filesystem level:
"Read src/lib/auth.ts and explain the auth flow"
"Create a Prisma schema for a blog"
"Refactor the database layer to use transactions"
"Add error handling to all async functions"

# OpenCode shows diffs before applying.
# Approve or reject each change.

Multi-session

Multi-sessionRun parallel agents.
# Open multiple agents on the same project:
# Terminal 1:
opencode -s "frontend" "Create the login page component"

# Terminal 2:
opencode -s "backend" "Add the login API route"

# Each session is independent.
# Sessions can share context via project files.

Configuration

ConfigurationSet up project rules.
# ~/.config/opencode/config.json
{
  "model": "claude-sonnet-4-20250514",
  "temperature": 0.3,
  "maxTokens": 64000
}

# Log in with GitHub Copilot:
# Uses your existing Copilot subscription

# Log in with ChatGPT Plus/Pro:
# Uses your OpenAI subscription

# Or use Zen for validated free models:
# opencode zen
Project rules fileSet AI context per project.
# Place OPENCODE.md at project root
# OpenCode reads this for project context

## Tech Stack
- Runtime: Node.js 22, TypeScript 5.5
- Framework: Next.js 14 (App Router)
- Database: PostgreSQL via Prisma

## Conventions
- Use server actions for mutations
- Components: PascalCase, utils: camelCase
- No `any` types — prefer `unknown`

## Guidelines
- Add error handling to every async function
- Follow existing patterns in the codebase

Tips

Tips for better resultsPrompting best practices.
# DO: Scope each prompt to specific files
"Edit only src/routes/auth.ts — add rate limiting"

# DO: Reference existing patterns
"Follow the error handling pattern in src/lib/errors.ts"

# DO: Specify exclusions
"Refactor the payment module. Do NOT touch billing code."

# DO: One task per prompt
# Sequential focused prompts > one giant prompt

# Use share links for collaboration:
# opencode generates a shareable session URL