OpenCode: Comprehensive Reference & Cheat Sheet
This document serves as a high-density, comprehensive reference guide for OpenCode. It is intended for users who are familiar with the basic workflow and need a quick reference for specific commands, configuration details, advanced features, and provider-specific information.
Core Commands
These are the most common commands you will use when interacting with the OpenCode TUI.
| Command | Description |
|---|---|
opencode | Starts the interactive TUI session in the current directory. |
opencode [prompt] | Executes a prompt in non-interactive "one-shot" mode and prints the result. |
opencode auth login | Initiates the authentication flow to add or update provider API keys. |
opencode config | Manages the local OpenCode configuration. |
opencode help | Displays help information for commands and flags. |
opencode --version | Shows the installed version of the OpenCode CLI. |
In-Session Commands
These commands are used within the interactive TUI session.
| Command | Description |
|---|---|
/plan [prompt] | Describes a change you want to make. The AI will propose a plan. |
/build | Executes the approved plan and applies the code changes. |
/undo | Reverts the last set of changes made by the agent. |
/redo | Re-applies the last set of changes that were undone. |
/share | Generates a shareable link to the current conversation. |
/clear | Clears the current conversation history. |
/exit | Exits the OpenCode TUI. |
Configuration
OpenCode can be configured using the opencode config command.
- Set a configuration value:
opencode config set [key] [value]- Example:
opencode config set default.model openai/gpt-4o
- Get a configuration value:
opencode config get [key]- Example:
opencode config get default.model
- List all configuration values:
opencode config list
Authentication
Manage API keys for different providers.
- Login to a provider:
opencode auth login -p [provider]- Example:
opencode auth login -p anthropic
- List authenticated providers:
opencode auth list
Installation Methods
| Platform | Command |
|---|---|
| macOS (Homebrew) | brew tap charmbracelet/tap && brew install opencode |
| Linux / macOS | `curl -fsSL https://opencode.ai/install.sh |
| npm | npm install -g @opencode/cli |
| Arch Linux (Paru) | paru -S opencode-bin |
| Windows | Manual binary download from the releases page. |
This reference covers the core functionalities and advanced features of OpenCode. For the most up-to-date information, always refer to the official documentation or use the opencode help command.