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