Getting Started
By default, OpenCode starts the TUI when run without arguments:Available Commands
serve
Start a headless OpenCode server for API access
web
Start server with web interface
attach
Attach terminal to running backend server
models
List all available models from providers
auth
Manage provider credentials and login
agent
Manage custom agents
upgrade
Update to latest or specific version
TUI Mode
Start the OpenCode terminal user interface:Options
Continue the last session. Short form:
-cSession ID to continue. Short form:
-sFork the session when continuing (use with
--continue or --session)Initial prompt to use
Model to use in the form of
provider/model. Short form: -mAgent to use
Port to listen on
Hostname to listen on
Examples
Run Mode
Run OpenCode non-interactively with a direct message:Global Flags
These flags work with any command:Display help information. Short form:
-hPrint version number. Short form:
-vPrint logs to stderr
Set log level:
DEBUG, INFO, WARN, or ERROREnvironment Variables
OpenCode can be configured using environment variables:| Variable | Type | Description |
|---|---|---|
OPENCODE_AUTO_SHARE | boolean | Automatically share sessions |
OPENCODE_CONFIG | string | Path to config file |
OPENCODE_CONFIG_DIR | string | Path to config directory |
OPENCODE_CONFIG_CONTENT | string | Inline JSON config content |
OPENCODE_DISABLE_AUTOUPDATE | boolean | Disable automatic update checks |
OPENCODE_DISABLE_PRUNE | boolean | Disable pruning of old data |
OPENCODE_DISABLE_TERMINAL_TITLE | boolean | Disable automatic terminal title updates |
OPENCODE_SERVER_PASSWORD | string | Enable basic auth for serve/web |
OPENCODE_SERVER_USERNAME | string | Override basic auth username (default: opencode) |
OPENCODE_CLIENT | string | Client identifier (defaults to cli) |
For a complete list of environment variables including experimental features, see the source documentation.
Next Steps
In-Session Commands
Learn about commands you can use during a session
Configuration
Customize OpenCode to your needs