Installation

Quick Install (Recommended)

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

Node.js

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

Homebrew (macOS/Linux)

brew install anomalyco/tap/opencode
Tip: Use the OpenCode tap for the most up-to-date releases.

Arch Linux

sudo pacman -S opencode # Stable
paru -S opencode-bin # Latest from AUR

Windows

# Chocolatey
choco install opencode
# Scoop
scoop install opencode
# Docker
docker run -it --rm ghcr.io/anomalyco/opencode
# Mise
mise use -g github:anomalyco/opencode
Recommended: Use WSL for the best experience on Windows.

Getting Started

1. Connect a Provider

/connect

Run this command, select a provider, and follow the prompts to add your API key.

Recommended: Use OpenCode Zen for curated, verified models.

2. Initialize a Project

cd /path/to/project
opencode
/init

The /init command analyzes your project and creates an AGENTS.md file.

Tip: Commit AGENTS.md to Git so OpenCode understands your project structure.

3. Start Coding!

Now you're ready to work with OpenCode. Ask questions, add features, or make changes.

Core Commands

All built-in commands start with / and are executed in the TUI.

Command Description
/init Initialize project - analyzes codebase and creates AGENTS.md
/undo Undo the last set of changes made by OpenCode
/redo Redo previously undone changes
/share Create a shareable link to the current session
/connect Connect or manage LLM providers
/help Show help and available commands
Note: You can create custom commands to override built-in ones.

Interaction Modes

Plan Mode vs Build Mode

OpenCode has two modes:

Plan Mode

  • Disabled from making changes
  • Shows implementation plan
  • Safe for discussing ideas
  • Use for: complex features, architecture

Build Mode

  • Can make file changes
  • Executes code modifications
  • Default mode
  • Use for: implementing features

Toggle Mode

Tab Toggle between Plan and Build mode
Tip: Switch to Plan mode first when working on big changes. Review the plan, then switch to Build mode to execute.

File References

Reference specific files in your prompts to give OpenCode context.

Basic Syntax

@filename.ts

Use the @ key to fuzzy search for files in your project.

Examples

How is authentication handled in @packages/functions/src/api/index.ts
 
We need to add auth to @src/settings.ts
Look at @src/notes.ts for the pattern

Images

Drag and drop images into the terminal to have OpenCode analyze them.

Tip: Useful for referencing UI designs or architecture diagrams.

Keyboard Shortcuts

Leader Key: OpenCode uses Ctrl+x as the leader key by default. Most shortcuts require pressing the leader key first, then the shortcut.

Leader Key Concept

To execute a shortcut like <leader>n (new session):

  1. Press and hold Ctrl
  2. Press x (leader)
  3. Release both
  4. Press n

Or: Press Ctrl+x then n

Session Controls

<leader>n New session
<leader>l List sessions
<leader>g Session timeline
<leader>x Export session
<leader>f Fork session
Escape Interrupt running response
<leader>c Compact session
<leader>down Go to first child (subagent)
Right / Left Cycle through child sessions
Up Go to parent session

Message Navigation

PageUp / PageDown Page up/down through messages
Ctrl+Home / Ctrl+End Jump to first/last message
<leader>y Copy message
<leader>u Undo message edit
<leader>r Redo message edit

Input / Editor

Ctrl+a Move to start of line
Ctrl+e Move to end of line
Ctrl+b / Left Move back one character
Ctrl+f / Right Move forward one character
Alt+b / Alt+Left Move back one word
Alt+f / Alt+Right Move forward one word
Ctrl+k Kill to end of line
Ctrl+u Kill to start of line
Ctrl+w Kill previous word
Alt+d Kill next word
Ctrl+d / Delete Delete character
Ctrl+h / Backspace Backspace
Ctrl+t Transpose characters
Up / Down History navigation
Shift+Enter New line in input

Model & Agent

<leader>m List models
F2 / Shift+F2 Cycle recent models
Ctrl+t Cycle model variant
<leader>a List agents
Tab / Shift+Tab Cycle agents
Tab Toggle Plan/Build mode

UI Controls

<leader>b Toggle sidebar
<leader>t List themes
<leader>s Status view
Ctrl+p Command list
Ctrl+g Cancel / abort
Ctrl+c Clear input
<leader>h Toggle tips

Disabling Keybinds

Set a keybind to "none" in tui.json to disable it:

{
  "keybinds": {
    "session_compact": "none"
  }
}

Custom Commands

Create reusable prompts for repetitive tasks.

Command File Location

  • Global: ~/.config/opencode/commands/
  • Project: .opencode/commands/

Creating a Command

Create a markdown file with frontmatter:

---
description: Run tests with coverage
agent: build
model: anthropic/claude-3-5-sonnet-20241022
---

Run the full test suite with coverage report and show any failures.
Focus on the failing tests and suggest fixes.

File: test.md → Command: /test

Arguments

Pass arguments using placeholders:

# All arguments
$ARGUMENTS
# Positional arguments
$1 # First argument
$2 # Second argument
$3 # Third argument

Example command component.md:

---
description: Create a new component
---

Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.

Usage: /component Button

Shell Output

Inject command output using !:

---
description: Analyze test coverage
---

Here are the current test results:
!`npm test`

Based on these results, suggest improvements to increase coverage.

Commands run in the project root directory.

File References in Commands

Include files using @:

---
description: Review component
---

Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.

Frontmatter Options

Option Description
description Shown in TUI command list
agent Which agent to use (e.g., "build", "plan")
model Override default model
subtask Force subagent invocation (true/false)

JSON Configuration

Also possible via opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "command": {
    "test": {
      "template": "Run the full test suite with coverage report.",
      "description": "Run tests with coverage",
      "agent": "build"
    }
  }
}

Configuration

Config Files

File Location Purpose
opencode.json Project root or ~/.config/opencode/ Main configuration
tui.json ~/.config/opencode/ Keybinds
AGENTS.md Project root Project-specific instructions
rules/ .opencode/ Additional rules
agents/ .opencode/ Custom agents
commands/ .opencode/ Custom commands

AGENTS.md

Created by /init. Contains project-specific context:

  • Project structure overview
  • Coding patterns and conventions
  • Tech stack information
  • Build/test commands
Best Practice: Commit AGENTS.md to version control so all team members get the same context.

Providers

OpenCode Zen (Recommended)

Curated, benchmarked models specifically tested for coding agents. No need to worry about inconsistent performance.

/connect

Select "opencode" and sign in at opencode.ai/auth

Other Providers

Provider Models
Anthropic Claude (Claude 3.5 Sonnet, etc.)
OpenAI GPT-4, GPT-4o, o1, etc.
Google Gemini Pro/Ultra
Models.dev 75+ providers, local models
GitHub Copilot

Tips & Best Practices

Use Plan Mode

For complex features, switch to Plan mode first. Review the implementation plan before letting OpenCode make changes.

Be Detailed

Give OpenCode plenty of context. Treat it like a junior developer on your team - the more details, the better.

Use File References

Always reference relevant files with @filename to give precise context.

Commit AGENTS.md

Include your project's AGENTS.md in version control so OpenCode understands your codebase from day one.

Share Sessions

Use /share to create links to sessions for debugging or team collaboration.

Undo Freely

Don't like the changes? Use /undo to revert. You can run it multiple times to undo multiple changes.

Use Custom Commands

Create commands for repetitive tasks like running tests, builds, or code reviews.

Drag & Drop

Drag images into the terminal to have OpenCode analyze designs or diagrams.