Skip to main content
The OpenCode CLI provides both interactive and non-interactive modes for working with AI-powered coding assistance.

Getting Started

By default, OpenCode starts the TUI when run without arguments:
You can also run commands programmatically:

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

flag
Continue the last session. Short form: -c
string
Session ID to continue. Short form: -s
flag
Fork the session when continuing (use with --continue or --session)
string
Initial prompt to use
string
Model to use in the form of provider/model. Short form: -m
string
Agent to use
number
Port to listen on
string
Hostname to listen on

Examples

Run Mode

Run OpenCode non-interactively with a direct message:
See the full run command documentation for details.

Global Flags

These flags work with any command:
flag
Display help information. Short form: -h
flag
Print version number. Short form: -v
flag
Print logs to stderr
string
Set log level: DEBUG, INFO, WARN, or ERROR

Environment Variables

OpenCode can be configured using environment variables:
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