OpenCode CLI reference - Subcommands
OpenCode commands and subcommands
OpenCode documents 36 subcommands, including opencode [project], agent and agent create. These run as opencode <command> from your shell. Each row gives the docs' description, accepted values and an example where one is documented.
Last verified 1 official pageFull OpenCode reference
| Command | Description | Example |
|---|---|---|
opencode [project] | Starts the OpenCode terminal user interface (TUI), optionally for a given project directory; this is the default when run with no arguments. Docs: opencode [project] | opencode /path/to/project |
agent | Manage agents for OpenCode. Docs: agent | opencode agent [command] |
agent create | Creates a new agent with a custom system prompt and permission configuration; anything not allowed is denied in the generated agent frontmatter. Passing all of --path, --description, --mode and --permissions runs it non-interactively. Docs: agent create | opencode agent create |
agent list | Lists all available agents. Docs: agent list | opencode agent list |
attach | Attaches a terminal TUI to an already running OpenCode backend server started via serve or web. Docs: attach | opencode attach http://10.20.30.40:4096 |
auth | Manages credentials and login for providers. Docs: auth | opencode auth [command] |
auth login | Configures API keys for any provider from Models.dev; credentials are stored in ~/.local/share/opencode/auth.json. Docs: auth login | opencode auth login |
auth list | Lists all authenticated providers stored in the credentials file. Alias: auth ls. Docs: auth list | opencode auth ls |
auth logout | Logs out of a provider by clearing it from the credentials file. Docs: auth logout | opencode auth logout |
github | Manages the GitHub agent for repository automation. Docs: github | opencode github [command] |
github install | Installs the GitHub agent in a repository, setting up the GitHub Actions workflow and guiding configuration. Docs: github install | opencode github install |
github run | Runs the GitHub agent; typically used in GitHub Actions. Docs: github run | opencode github run |
mcp | Manages Model Context Protocol servers. Docs: mcp | opencode mcp [command] |
mcp add | Interactively adds a local or remote MCP server to the configuration. Docs: mcp add | opencode mcp add |
mcp list | Lists configured MCP servers and their connection status. Alias: mcp ls. Docs: mcp list | opencode mcp ls |
mcp auth | Authenticates with an OAuth-enabled MCP server; prompts for a server if no name is given. | opencode mcp auth list |
mcp logout | Removes OAuth credentials for an MCP server. Docs: mcp logout | opencode mcp logout [name] |
mcp debug | Debugs OAuth connection issues for an MCP server: shows auth status, tests HTTP connectivity and attempts OAuth discovery. Docs: mcp debug | opencode mcp debug <name> |
models | Lists all models available from configured providers in provider/model format, optionally filtered by provider ID. Docs: models | opencode models anthropic |
run | Runs OpenCode non-interactively by passing a prompt directly; useful for scripting and automation, and can attach to a running serve instance. Docs: run | opencode run Explain the use of context in Go |
serve | Starts a headless OpenCode HTTP server for API access without the TUI. Set OPENCODE_SERVER_PASSWORD to enable HTTP basic auth. Docs: serve | opencode serve |
session | Manages OpenCode sessions. Docs: session | opencode session [command] |
session list | Lists all OpenCode sessions. Docs: session list | opencode session list |
session delete | Deletes an OpenCode session. Docs: session delete | opencode session delete <sessionID> |
stats | Shows token usage and cost statistics for OpenCode sessions. Docs: stats | opencode stats |
export | Exports session data as JSON; prompts for a session if no ID is given. Docs: export | opencode export [sessionID] |
import | Imports session data from a JSON file. Docs: import | opencode import session.json |
web | Starts a headless OpenCode server with a web interface and opens a browser. Set OPENCODE_SERVER_PASSWORD to enable HTTP basic auth. Docs: web | opencode web |
acp | Starts an ACP (Agent Client Protocol) server that communicates via stdin/stdout using nd-JSON. Docs: acp | opencode acp |
plugin | Installs a plugin and updates your config. Alias: plug. Docs: plugin | opencode plug <module> |
pr | Fetches and checks out a GitHub PR branch, then runs OpenCode. Docs: pr | opencode pr <number> |
db | Database tools; optionally runs a query. Docs: db | opencode db [query] |
db path | Prints the database path. Docs: db path | opencode db path |
debug | Debugging and troubleshooting tools. | opencode debug [command] |
uninstall | Uninstalls OpenCode and removes all related files. Docs: uninstall | opencode uninstall |
upgrade | Updates opencode to the latest version or a specific version. Docs: upgrade | opencode upgrade v0.1.48 |
The rest of the OpenCode reference
FAQ
How many subcommands does OpenCode have?
The official OpenCode docs list 36 subcommands, including opencode [project], agent and agent create. All of them are in the table above, in the docs' order.
What does opencode [project] do in OpenCode?
Starts the OpenCode terminal user interface (TUI), optionally for a given project directory; this is the default when run with no arguments. Example: opencode /path/to/project
Where are OpenCode subcommands documented?
On 1 official docs page at opencode.ai, last read on October 17, 2026. Every row in the table links the exact section it came from.
More on OpenCode
- OpenCode in the tools directoryWhat it is, who makes it and how it fits next to other coding agents.
- OpenCode errors and fixes17 error messages, quoted verbatim, with the documented fix for each.
Use other models in OpenCode
Setup guides from the model-in-tool directory, each with the env vars and base URL from official docs.
Sources
Last verified . Names and examples are copied verbatim from the official page below, and every row above links the exact section it came from.
- opencode.ai/docs/cli/36 items
Newsletter
Know when your tools change
One email per week. New coding agent releases, the flags and commands they add, and what they mean for how you work.