CLI
OpenCode CLI options and commands.
The OpenCode CLI by default starts the TUI when run without any arguments.
opencodeBut it also accepts commands as documented on this page. This allows you to interact with OpenCode programmatically.
opencode run "Explain how closures work in JavaScript"tui
Start the OpenCode terminal user interface.
opencode [project]Flags
| Flag | Short | Description |
|---|---|---|
--continue | -c | Continue the last session |
--session | -s | Session ID to continue |
--fork | Fork the session when continuing (use with --continue or --session) | |
--prompt | Prompt to use | |
--model | -m | Model to use in the form of provider/model |
--agent | Agent to use | |
--auto | Auto-approve permissions that are not explicitly denied | |
--port | Port to listen on | |
--hostname | Hostname to listen on | |
--mdns | Enable mDNS discovery | |
--mdns-domain | Custom mDNS domain name | |
--cors | Additional browser origin(s) to allow CORS |
Commands
The OpenCode CLI also has the following commands.
agent
Manage agents for OpenCode.
opencode agent [command]create
Create a new agent with custom configuration.
opencode agent createThis command will guide you through creating a new agent with a custom system prompt and permission configuration. Anything you don’t allow is denied in the generated agent’s frontmatter.
Flags
| Flag | Short | Description |
|---|---|---|
--path | Directory to write the agent file to (defaults to global or .opencode/agent based on the prompt) | |
--description | What the agent should do | |
--mode | Agent mode: all, primary, or subagent | |
--permissions | Comma-separated list of permissions to allow (default: all). Available: bash, read, edit, glob, grep, webfetch, task, todowrite, websearch, lsp, skill. Anything omitted is denied. Alias: --tools | |
--model | -m | Model to use, in provider/model format |
Passing all of --path, --description, --mode, and --permissions runs the command non-interactively.
list
List all available agents.
opencode agent listattach
Attach a terminal to an already running OpenCode backend server started via serve or web commands.
opencode attach [url]This allows using the TUI with a remote OpenCode backend. For example:
# Start the backend server for web/mobile accessopencode web --port 4096 --hostname 0.0.0.0
# In another terminal, attach the TUI to the running backendopencode attach http://10.20.30.40:4096Flags
| Flag | Short | Description |
|---|---|---|
--dir | Working directory to start TUI in | |
--continue | -c | Continue the last session |
--session | -s | Session ID to continue |
--fork | Fork the session when continuing (use with --continue or --session) | |
--password | -p | Basic auth password (defaults to OPENCODE_SERVER_PASSWORD) |
--username | -u | Basic auth username (defaults to OPENCODE_SERVER_USERNAME or opencode) |
auth
Command to manage credentials and login for providers.
opencode auth [command]login
OpenCode is powered by the provider list at Models.dev, so you can use opencode auth login to configure API keys for any provider you’d like to use. This is stored in ~/.local/share/opencode/auth.json.
opencode auth loginWhen OpenCode starts up it loads the providers from the credentials file. And if there are any keys defined in your environments or a .env file in your project.
Flags
| Flag | Short | Description |
|---|---|---|
--provider |