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:
opencode
You can also run commands programmatically:
opencode run "Explain how closures work in JavaScript"

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:
opencode [project]

Options

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

Examples

# Start in current directory
opencode

# Continue last session
opencode --continue

# Use specific model
opencode --model anthropic/claude-4.5-sonnet

# Fork previous session
opencode --session abc123 --fork

Run Mode

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

Global Flags

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

Environment Variables

OpenCode can be configured using environment variables:
VariableTypeDescription
OPENCODE_AUTO_SHAREbooleanAutomatically share sessions
OPENCODE_CONFIGstringPath to config file
OPENCODE_CONFIG_DIRstringPath to config directory
OPENCODE_CONFIG_CONTENTstringInline JSON config content
OPENCODE_DISABLE_AUTOUPDATEbooleanDisable automatic update checks
OPENCODE_DISABLE_PRUNEbooleanDisable pruning of old data
OPENCODE_DISABLE_TERMINAL_TITLEbooleanDisable automatic terminal title updates
OPENCODE_SERVER_PASSWORDstringEnable basic auth for serve/web
OPENCODE_SERVER_USERNAMEstringOverride basic auth username (default: opencode)
OPENCODE_CLIENTstringClient 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