文档
English Docs
Introduction

Introduction

OpenCode is an open source AI coding agent available as a terminal interface, desktop application, or IDE extension. It enables developers to interact with AI for code-related tasks.

Prerequisites

Before using OpenCode in your terminal, you'll need:

  1. Modern Terminal Emulator - Options include:

    • WezTerm (cross-platform)
    • Alacritty (cross-platform)
    • Ghostty (Linux and macOS)
    • Kitty (Linux and macOS)
  2. API Keys - Credentials for your chosen LLM providers

Installation

Universal Installation

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

Node.js Package Managers

# npm
npm install -g opencode-ai
 
# Bun
bun install -g opencode-ai
 
# pnpm
pnpm install -g opencode-ai
 
# Yarn
yarn global add opencode-ai

System Package Managers

# Homebrew (macOS/Linux)
brew install anomalyco/tap/opencode
 
# Paru (Arch Linux)
paru -S opencode-bin
 
# Chocolatey (Windows)
choco install opencode
 
# Scoop (Windows)
scoop bucket add extras && scoop install extras/opencode
 
# Docker
docker run -it --rm ghcr.io/anomalyco/opencode

Configuration

  1. Execute the /connect command within the terminal interface
  2. Select your preferred provider
  3. Authenticate at opencode.ai/auth
  4. Configure billing information
  5. Retrieve and input your API key

We recommend OpenCode Zen as a curated, tested model collection for newcomers.

Project Initialization

Navigate to your project directory and launch:

cd /path/to/project
opencode

Initialize the project with:

/init

This generates an AGENTS.md file in your project root, which should be committed to version control.

Core Usage Patterns

Questioning the Codebase

Use @ to search project files:

How is authentication handled in @packages/functions/src/api/index.ts

Feature Development

  1. Plan Mode (Tab key) - AI suggests implementation approaches without making changes
  2. Iteration - Refine plans with feedback and visual references
  3. Build Mode (Tab key) - Execute the approved changes

Reverting Changes

  • Undo command: /undo
  • Redo command: /redo
  • Multiple undos are supported

Collaboration

Share conversations via:

/share

This generates a shareable link copied to the clipboard.

Personalization

Customize your experience:

  • Theme selection
  • Keyboard bindings
  • Code formatters
  • Custom commands
  • Configuration settings