CLI
The OpenCode CLI provides command-line access to OpenCode functionality. By default, running opencode starts the terminal user interface (TUI).
opencodePass commands for programmatic interaction:
opencode run "Explain how closures work in JavaScript"TUI Flags
| Flag | Short | Purpose |
|---|---|---|
--continue | -c | Resume previous session |
--session | -s | Specify session ID |
--prompt | — | Provide initial prompt |
--model | -m | Set model (provider/model) |
--agent | — | Select agent |
Commands
run
Execute OpenCode in non-interactive mode:
opencode run [message..]Flags:
--continue,-c: Resume last session--model,-m: Set model--file,-f: Attach file(s)--format: Output asdefaultorjson
auth
Manage credentials:
opencode auth login # Configure API keys
opencode auth list # Display providers
opencode auth logout # Remove credentialsmodels
List available models:
opencode models [provider]
opencode models --refresh # Update cached list
opencode models --verbose # Show costssession
Manage sessions:
opencode session list
opencode session list --format jsonserve
Start headless HTTP server:
opencode serve --port 4096web
Start server with web interface:
opencode web --port 4096agent
Manage agents:
opencode agent create # Create custom agent
opencode agent list # List agentsmcp
Manage MCP servers:
opencode mcp add # Add server
opencode mcp list # Show servers
opencode mcp auth # Authenticate
opencode mcp debug # Troubleshootstats
Display usage statistics:
opencode stats --days 30
opencode stats --modelsupgrade
Update OpenCode:
opencode upgrade # Latest version
opencode upgrade v0.1.48 # Specific versionGlobal Flags
| Flag | Short | Purpose |
|---|---|---|
--help | -h | Display help |
--version | -v | Print version |
--print-logs | — | Output logs to stderr |
--log-level | — | Set level (DEBUG, INFO, WARN, ERROR) |
Environment Variables
Core Configuration
| Variable | Purpose |
|---|---|
OPENCODE_CONFIG | Config file path |
OPENCODE_CONFIG_DIR | Config directory |
OPENCODE_CONFIG_CONTENT | Inline JSON config |
Features
| Variable | Purpose |
|---|---|
OPENCODE_DISABLE_AUTOUPDATE | Disable updates |
OPENCODE_ENABLE_EXPERIMENTAL_MODELS | Enable experimental models |
OPENCODE_DISABLE_AUTOCOMPACT | Disable compaction |