CandidDevelopers
cd ../setup-guides
$catopencode-setup.md

// OpenCode

Lightweight, open-source terminal AI coding assistant. Minimal setup, TUI interface, and full compatibility with any OpenAI-compatible API for a clean, distraction-free coding experience.

v1.0|6 sections|terminal|free

01# Overview

OpenCode is an open-source terminal-based AI coding assistant with a built-in TUI (Terminal User Interface). It's lightweight, fast, and supports OpenAI-compatible endpoints out of the box — making it perfect for connecting to your API provider.

Terminal UI (TUI)

Rich interactive interface right in your terminal

Multi-provider support

OpenAI, Anthropic, and custom endpoints

Session management

Save and resume coding sessions

File operations

Read, write, and edit files with approval

02# Installation

Install OpenCode using Go or download a pre-built binary:

bash
# Install with Go (1.21+):
go install github.com/opencode-ai/opencode@latest

# Or via Homebrew (macOS/Linux):
brew install opencode

# Verify installation:
opencode --version
📌Alternative: Download Binary
If you don't have Go installed, download the latest release binary from the GitHub releases page.

03# Configure API Key

Option A: Environment Variables

Set your API provider endpoint and key:

.zshrc
bash
# Add to your shell profile ($HOME/.zshrc or $HOME/.bashrc):
export OPENAI_API_KEY="<your-api-key>"
export OPENAI_BASE_URL="<your-api-base-url>"

# Apply changes:
source $HOME/.zshrc

Option B: Configuration File

For persistent, project-level configuration:

config.toml
toml
[providers.api_provider]
api_key = "<your-api-key>"
base_url = "<your-api-base-url>"

[models.default]
provider = "api_provider"
model = "<your-model-id>"
⚠️Get Your Credentials
Contact your team lead or check the #dev-tools channel for approved providers, API keys, and model IDs.

04# Usage

Navigate to your project directory and launch OpenCode:

bash
cd /path/to/your-project
opencode

The TUI will launch with a chat interface. Type your requests naturally:

text
> Explain the project structure

> Add error handling to the database queries

> Create a middleware for rate limiting

> Fix the failing tests in auth.test.ts

For quick one-off tasks, pass a prompt directly:

bash
opencode "Add TypeScript types to the utils.js file"

05# Features

TUI Interface

OpenCode runs a rich terminal UI with multiple panes:

Chat paneMain conversation area
File viewerSee files being read/modified
Diff viewReview changes before accepting
Session listSwitch between saved sessions

Keyboard Shortcuts

Ctrl+NNew session
Ctrl+LClear current conversation
Ctrl+OOpen session list
Ctrl+KToggle compact mode
Ctrl+CCancel current generation
Ctrl+DExit OpenCode

06# Best Practices

Use the config file for defaults

Set your model and endpoint in config.toml so you don't need to set environment variables every session.

Review diffs before accepting

OpenCode shows file diffs before applying changes. Always review them to catch unintended modifications.

Save sessions for complex tasks

Use session management (Ctrl+O) to save progress on complex refactoring tasks you can resume later.

Be specific with file paths

When asking OpenCode to modify files, mention the exact file path for better accuracy.

Commit before starting

Always make a git commit before starting an OpenCode session. This gives you a clean rollback point.

07# Terminal Compatibility

💡Works alongside Claude Code & Codex
OpenCode runs in the terminal, so you can run Claude Code or Codex CLI in separate terminal sessions alongside it — giving you multiple AI coding engines on the same project. This does not break any terms of service; each tool runs independently in its own shell. Check our Claude Code and Codex setup guides to get started.