Commands
Every command accepts --help for its full flag list, for example opencode run --help. Some server-backed commands accept --standalone to run a private server or --server <url> to target a specific one; check the command’s help for its supported flags.
Sends a message and prints the reply without opening the interactive interface.
$ opencode run "Explain this repository"In CI, pass a provider API key as a secret and use standalone mode so the private server receives it. For example, this GitHub Actions job reviews the checked-out repository:
name: OpenCode review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install --global @opencode/cli
- run: opencode run --standalone --model anthropic/claude-sonnet-5-5 "Review this repository for correctness and summarize any issues."
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}Choose a model.
$ opencode run --model anthropic/claude-sonnet-5-5 "Refactor parseToken"Continue the last session.
$ opencode run --continue "Now handle the expired case"Emit newline-delimited JSON for scripts.
$ opencode run --format json "List the TODO comments"Attach files to the message.
$ opencode run --file src/server.ts --file src/client.ts "Review these for bugs"Run with a specific agent.
$ opencode run --agent build "Fix the failing test"Continue a specific session.
$ opencode run --session ses_4f2a1c "Check edge cases"Auto-approve permissions that are not explicitly denied.
$ opencode run --auto "Fix the failing test"Create the session archived so scripted or CI runs stay out of session lists and the inbox. The session still exists: opencode session list includes it, and you can open it by ID.
$ opencode run --archived "Review this diff"View all subcommands and flags.
$ opencode run --helpStarts the minimal interactive interface instead of the full-screen TUI.
$ opencode miniContinue the last session.
$ opencode mini --continueStart with a model and an initial prompt.
$ opencode mini --model anthropic/claude-sonnet-5-5 --prompt "Summarize this repository"Continue a specific session.
$ opencode mini --session ses_4f2a1cView all subcommands and flags.
$ opencode mini --helpManages sessions.
$ opencode session listLimit the list and print JSON.
$ opencode session list --max-count 20 --format jsonDelete a session and its child sessions.
$ opencode session delete ses_9c1b08Export session data as JSON.
$ opencode session export ses_4f2a1cRedact sensitive transcript and file data when exporting.
$ opencode session export ses_4f2a1c --sanitizeImport session data from a JSON file or URL.
$ opencode session import session.jsonImport into a specific directory.
$ opencode session import session.json --directory ~/code/projectView all subcommands and flags.
$ opencode session --helpManages AI providers and credentials.
$ opencode auth listList them as JSON.
$ opencode auth list --format jsonLog in to a provider.
$ opencode auth login anthropicLog in with a specific authentication method.
$ opencode auth login anthropic --method keyLog out of a saved account.
$ opencode auth logout anthropic workSwitch the active account for an integration.
$ opencode auth switch anthropic workExport saved credentials and import them on another machine. The file contains secrets.
$ opencode auth export anthropic > credentials.json
$ opencode auth import credentials.jsonView all subcommands and flags.
$ opencode auth --helpLists every available model.
$ opencode modelsView all subcommands and flags.
$ opencode models --helpManages MCP (Model Context Protocol) servers.
$ opencode mcp listAdd a remote server.
$ opencode mcp add context7 --url https://mcp.context7.com/mcpAdd a local server to the global config.
$ opencode mcp add everything --global -- npx -y @modelcontextprotocol/server-everythingAdd a local server with an environment variable.
$ opencode mcp add everything --env LOG_LEVEL=debug -- npx -y @modelcontextprotocol/server-everythingAdd a remote server with a header.
$ opencode mcp add context7 --url https://mcp.context7.com/mcp --header CONTEXT7_API_KEY=secretAuthenticate with an OAuth-capable remote server.
$ opencode mcp auth sentryRemove stored OAuth credentials for a server.
$ opencode mcp logout sentryView all subcommands and flags.
$ opencode mcp --helpManages plugins.
$ opencode plugin listInclude built-in server plugins.
$ opencode plugin list --builtinInstall a plugin and add it to the global configuration.
$ opencode plugin add @example/opencode-tuiCheck package plugins for updates.
$ opencode plugin checkUpdate package plugins.
$ opencode plugin updateRemove a plugin from global configuration.
$ opencode plugin remove @example/opencode-tuiView all subcommands and flags.
$ opencode plugin --helpShows shareable usage statistics.
$ opencode statsShow the last 7 days.
$ opencode stats --days 7Show model usage.
$ opencode stats --modelsShow cost and token details.
$ opencode stats --costPrint JSON instead of a report.
$ opencode stats --jsonShow only the current project.
$ opencode stats --project .View all subcommands and flags.
$ opencode stats --helpStarts the API and web server. See Web.
$ opencode serveBind to all interfaces on a fixed port.
$ opencode serve --hostname 0.0.0.0 --port 4096Allow a browser client from another origin.
$ opencode serve --cors https://app.example.comView all subcommands and flags.
$ opencode serve --helpPrints one-time links, plus a QR code of the first one, that sign a browser or app in to the server. Links expire after 5 minutes and work once.
$ opencode pairUse an external URL in the links.
$ opencode pair --url https://dev.example.comPair from anywhere through an OpenTunnel remote address. This exposes the server to the internet, so the first time it enables remote access it explains this and asks you to accept. See Remote access.
$ opencode pair --remoteAccept without a prompt, for example in a script without a terminal.
$ opencode pair --remote --yesView all subcommands and flags.
$ opencode pair --helpManages the background server. See Web.
$ opencode service startRestart it.
$ opencode service restartShow its status.
$ opencode service statusStop it.
$ opencode service stopRead a setting.
$ opencode service get hostnameSet a setting.
$ opencode service set hostname 0.0.0.0Allow an extra CORS origin.
$ opencode service set cors https://app.example.comPass an environment variable to the server process.
$ opencode service set env OPENCODE_LOG_LEVEL DEBUGReset a setting to its default.
$ opencode service unset hostnameView all subcommands and flags.
$ opencode service --helpReloads configuration without restarting the server. Running sessions continue with fresh services at the next step boundary.
$ opencode reloadMakes a request to the running server.
$ opencode api GET /api/sessionCall an operation ID with a query parameter.
$ opencode api session.list --param limit=10Send a JSON body.
$ opencode api session.create --data '{"title": "New session"}'Add a request header.
$ opencode api GET /api/session -H "accept: application/json"View all subcommands and flags.
$ opencode api --helpStarts an Agent Client Protocol server over stdin and stdout for editor integrations. It runs until the client closes the connection.
$ opencode acpView all subcommands and flags.
$ opencode acp --helpProvides debugging and troubleshooting tools.
$ opencode debug agentsList configuration sources.
$ opencode debug configWrite a heap snapshot of the running background server and print its path.
$ opencode debug heap-dumpWrite the snapshot into a directory of your choice.
$ opencode debug heap-dump --directory ./snapshotsShow global paths.
$ opencode debug pathsPrint a single path.
$ opencode debug paths dbView all subcommands and flags.
$ opencode debug --helpUpgrades OpenCode to the latest or a specific version. Alias: update.
$ opencode upgradeUpgrade to a specific version with a specific package manager.
$ opencode upgrade 2.0.21 --method bunView all subcommands and flags.
$ opencode upgrade --helpStops background services, removes the global cache, and uninstalls OpenCode. Session data, configuration, and state are not removed.
$ opencode uninstallPreview what would be removed.
$ opencode uninstall --dry-runView all subcommands and flags.
$ opencode uninstall --help