Skip to content

CLI

OpenCode CLI options and commands.

The OpenCode CLI by default starts the TUI when run without any arguments.

Terminal window
opencode

But it also accepts commands as documented on this page. This allows you to interact with OpenCode programmatically.

Terminal window
opencode run "Explain how closures work in JavaScript"

tui

Start the OpenCode terminal user interface.

Terminal window
opencode [project]

Flags

FlagShortDescription
--continue-cContinue the last session
--session-sSession ID to continue
--forkFork the session when continuing (use with --continue or --session)
--promptPrompt to use
--model-mModel to use in the form of provider/model
--agentAgent to use
--autoAuto-approve permissions that are not explicitly denied
--portPort to listen on
--hostnameHostname to listen on
--mdnsEnable mDNS discovery
--mdns-domainCustom mDNS domain name
--corsAdditional browser origin(s) to allow CORS

Commands

The OpenCode CLI also has the following commands.


agent

Manage agents for OpenCode.

Terminal window
opencode agent [command]

create

Create a new agent with custom configuration.

Terminal window
opencode agent create

This 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

FlagShortDescription
--pathDirectory to write the agent file to (defaults to global or .opencode/agent based on the prompt)
--descriptionWhat the agent should do
--modeAgent mode: all, primary, or subagent
--permissionsComma-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-mModel to use, in provider/model format

Passing all of --path, --description, --mode, and --permissions runs the command non-interactively.


list

List all available agents.

Terminal window
opencode agent list

attach

Attach a terminal to an already running OpenCode backend server started via serve or web commands.

Terminal window
opencode attach [url]

This allows using the TUI with a remote OpenCode backend. For example:

Terminal window
# Start the backend server for web/mobile access
opencode web --port 4096 --hostname 0.0.0.0
# In another terminal, attach the TUI to the running backend
opencode attach http://10.20.30.40:4096

Flags

FlagShortDescription
--dirWorking directory to start TUI in
--continue-cContinue the last session
--session-sSession ID to continue
--forkFork the session when continuing (use with --continue or --session)
--password-pBasic auth password (defaults to OPENCODE_SERVER_PASSWORD)
--username-uBasic auth username (defaults to OPENCODE_SERVER_USERNAME or opencode)

auth

Command to manage credentials and login for providers.

Terminal window
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.

Terminal window
opencode auth login

When 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
FlagShortDescription
--provider-pProvider ID or name to log in to
--method-mLogin method label to use, skipping method selection

list

Lists all the authenticated providers as stored in the credentials file.

Terminal window
opencode auth list

Or the short version.

Terminal window
opencode auth ls

logout

Logs you out of a provider by clearing it from the credentials file.

Terminal window
opencode auth logout

github

Manage the GitHub agent for repository automation.

Terminal window
opencode github [command]

install

Install the GitHub agent in your repository.

Terminal window
opencode github install

This 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.

Terminal window
opencode github run
Flags
FlagDescription
--eventGitHub mock event to run the agent for
--tokenGitHub personal access token

mcp

Manage Model Context Protocol servers.

Terminal window
opencode mcp [command]

add

Add an MCP server to your configuration.

Terminal window
opencode mcp add

This command will guide you through adding either a local or remote MCP server.


list

List all configured MCP servers and their connection status.

Terminal window
opencode mcp list

Or use the short version.

Terminal window
opencode mcp ls

auth

Authenticate with an OAuth-enabled MCP server.

Terminal window
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.

Terminal window
opencode mcp auth list

Or use the short version.

Terminal window
opencode mcp auth ls

logout

Remove OAuth credentials for an MCP server.

Terminal window
opencode mcp logout [name]

debug

Debug OAuth connection issues for an MCP server.