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 | -p | Provider ID or name to log in to |
--method | -m | Login method label to use, skipping method selection |
list
Lists all the authenticated providers as stored in the credentials file.
opencode auth listOr the short version.
opencode auth lslogout
Logs you out of a provider by clearing it from the credentials file.
opencode auth logoutgithub
Manage the GitHub agent for repository automation.
opencode github [command]install
Install the GitHub agent in your repository.
opencode github installThis sets up the necessary GitHub Actions workflow and guides you through the configuration process. Learn more.
run
Run the GitHub agent. This is typically used in GitHub Actions.
opencode github runFlags
| Flag | Description |
|---|---|
--event | GitHub mock event to run the agent for |
--token | GitHub personal access token |
mcp
Manage Model Context Protocol servers.
opencode mcp [command]add
Add an MCP server to your configuration.
opencode mcp addThis command will guide you through adding either a local or remote MCP server.
list
List all configured MCP servers and their connection status.
opencode mcp listOr use the short version.
opencode mcp lsauth
Authenticate with an OAuth-enabled MCP server.
opencode mcp auth [name]If you don’t provide a server name, you’ll be prompted to select from available OAuth-capable servers.
You can also list OAuth-capable servers and their authentication status.
opencode mcp auth listOr use the short version.
opencode mcp auth lslogout
Remove OAuth credentials for an MCP server.
opencode mcp logout [name]debug
Debug OAuth connection issues for an MCP server.