Introduction

Get started with OpenCode.

OpenCode is an open source AI coding agent. It provides terminal interface, desktop app, and IDE extensions.

OpenCode TUI with opencode theme

Let's get started.


Prerequisites

To use OpenCode in the terminal, you need:

  1. A modern terminal emulator, such as:

  2. An API key for the LLM provider you want to use.


Quick Start

The easiest way to install OpenCode is via the installation script:

curl -fsSL https://opencode.ai/install | bash

After installation, run opencode to start.


Features

Installation

Multiple ways to install OpenCode.

Using curl

curl -fsSL https://opencode.ai/install | bash

This will install the OpenCode CLI.

Using npm

npm i -g opencode-ai

Using bun

bun add -g opencode-ai

Using brew

brew install anomalyco/tap/opencode

Using paru (Arch Linux)

paru -S opencode

Desktop App

You can also download the desktop app:

Install Desktop App with brew

brew install --cask opencode-desktop

IDE Extensions

OpenCode provides the following IDE extensions:


Verify Installation

After installation, run the following command to verify:

opencode --version

If it displays the version number, the installation was successful.

Configuration

Customize OpenCode's behavior.

Configuration File

OpenCode uses JSON configuration files. You can create an opencode.json file in your project root directory to configure it.

Basic Configuration

{
  "provider": "anthropic",
  "model": "claude-3-5-sonnet-20241022",
  "apiKey": "your-api-key"
}

Configuration File Locations


Model Configuration

You can configure different models for different tasks:

{
  "models": {
    "default": "claude-3-5-sonnet-20241022",
    "fast": "gpt-3.5-turbo",
    "code": "claude-3-5-sonnet-20241022"
  }
}

Tools Configuration

OpenCode has built-in tools that you can enable or disable as needed:

{
  "tools": {
    "fileOperations": true,
    "terminal": true,
    "codeSearch": true,
    "webSearch": false
  }
}

Rules Configuration

You can customize OpenCode's behavior through rules files:

# .opencode/rules.md
- Always use TypeScript
- Follow ESLint rules
- Use functional components
- Prefer const over let

Theme Configuration

OpenCode supports custom themes. You can specify it in the configuration file:

{
  "theme": "opencode"
}

Available themes include: opencode, dark, light, monokai, etc.


Keybinding Configuration

You can customize keybindings:

{
  "keybindings": {
    "submit": "Enter",
    "newLine": "Shift+Enter",
    "clear": "Ctrl+L"
  }
}

Usage

Multiple ways to use OpenCode.

Terminal Usage

Run OpenCode in the terminal:

opencode

This will start the interactive TUI interface.

Basic Commands

TUI Shortcuts


Desktop App

The desktop app provides a graphical interface, suitable for developers who prefer visual operations. After downloading and installing, you can:


IDE Extensions

Use OpenCode in your IDE:

VS Code

  1. Open VS Code Extensions marketplace
  2. Search for "OpenCode"
  3. Click Install
  4. Use Ctrl+Shift+P to open the command palette, type "OpenCode"

Cursor

Cursor has built-in OpenCode support, no additional installation required.


Web Interface

OpenCode also provides a web interface that you can use in your browser:

opencode web

This will start a local web server, default address is http://localhost:3000.


Usage Tips

Providers

Configure different AI providers.

Supported Providers

OpenCode supports 75+ LLM providers, including:

Anthropic (Claude)

{
  "provider": "anthropic",
  "model": "claude-3-5-sonnet-20241022",
  "apiKey": "sk-ant-..."
}

Available models: claude-3-5-sonnet-20241022, claude-3-opus-20240229, claude-3-haiku-20240307

OpenAI (GPT)

{
  "provider": "openai",
  "model": "gpt-4",
  "apiKey": "sk-..."
}

Available models: gpt-4, gpt-4-turbo, gpt-3.5-turbo

Google (Gemini)

{
  "provider": "google",
  "model": "gemini-pro",
  "apiKey": "AIza..."
}

GitHub Copilot

{
  "provider": "github",
  "model": "copilot"
}

Requires authorization first with opencode auth github.

ChatGPT

{
  "provider": "chatgpt",
  "model": "gpt-4"
}

Requires authorization first with opencode auth openai.


Local Models

You can use tools like Ollama to run local models:

{
  "provider": "ollama",
  "model": "codellama",
  "baseUrl": "http://localhost:11434"
}

Custom Providers

You can add custom providers:

{
  "providers": {
    "custom": {
      "name": "Custom Provider",
      "baseUrl": "https://api.example.com/v1",
      "apiKeyHeader": "Authorization"
    }
  }
}

Advanced Features

Explore OpenCode's advanced features.

LSP Support

OpenCode supports Language Server Protocol (LSP), which can provide more accurate code context for LLM:

Configure LSP

{
  "lsp": {
    "typescript": {
      "command": "typescript-language-server",
      "args": ["--stdio"]
    },
    "python": {
      "command": "pyright-langserver",
      "args": ["--stdio"]
    }
  }
}

MCP Servers

Model Context Protocol (MCP) allows OpenCode to connect to external tools and services:

{
  "mcp": {
    "servers": {
      "filesystem": {
        "command": "mcp-server-filesystem",
        "args": ["/path/to/dir"]
      },
      "database": {
        "command": "mcp-server-database",
        "args": ["--connection-string", "..."]
      }
    }
  }
}

Agent Skills

OpenCode supports custom skills to extend the agent's functionality:

# .opencode/skills/deploy.md
---
name: deploy
description: Deploy project to production
---

Execute the following steps:
1. Run tests
2. Build the project
3. Deploy to server

SDK

OpenCode provides an SDK to integrate AI coding capabilities into your own tools:

JavaScript/TypeScript

import { OpenCode } from 'opencode-sdk';

const client = new OpenCode({
  provider: 'anthropic',
  apiKey: 'your-api-key'
});

const response = await client.chat('Explain this code');
console.log(response);

Python

from opencode import OpenCode

client = OpenCode(
    provider='anthropic',
    api_key='your-api-key'
)

response = client.chat('Explain this code')
print(response)

Plugin System

OpenCode supports plugin extensions:

{
  "plugins": [
    "opencode-plugin-eslint",
    "opencode-plugin-prettier"
  ]
}

API Reference

Complete API reference documentation: