OpenCode CLI reference - CLI flags
OpenCode command-line flags
OpenCode documents 82 CLI flags, including --continue, --session and --fork. You pass these to opencode on the command line. Each row gives the docs' description, accepted values and an example where one is documented.
Last verified 1 official pageFull OpenCode reference
| Flag | Description | Example |
|---|---|---|
--continue | Continue the last session (opencode tui). Short: -c. Docs: --continue | -no example |
--session | Session ID to continue (opencode tui). Short: -s. Docs: --session | -no example |
--fork | Fork the session when continuing (use with --continue or --session) (opencode tui). Docs: --fork | -no example |
--prompt | Prompt to use (opencode tui). Docs: --prompt | -no example |
--model | Model to use in the form of provider/model (opencode tui). Short: -m. Docs: --model | -no example |
--agent | Agent to use (opencode tui). Docs: --agent | -no example |
--auto | Auto-approve permissions that are not explicitly denied (opencode tui). Docs: --auto | opencode --auto |
--port | Port to listen on (opencode tui). Docs: --port | -no example |
--hostname | Hostname to listen on (opencode tui). Docs: --hostname | -no example |
--mdns | Enable mDNS discovery (opencode tui). Docs: --mdns | -no example |
--mdns-domain | Custom mDNS domain name (opencode tui). Docs: --mdns-domain | -no example |
--cors | Additional browser origin(s) to allow CORS (opencode tui). Docs: --cors | -no example |
--path | Directory to write the agent file to (opencode agent create). Defaults to global or .opencode/agent based on the prompt. Docs: --path | -no example |
--description | What the agent should do (opencode agent create). Docs: --description | -no example |
--mode | Agent mode (opencode agent create). all, primary, or subagent Docs: --mode | -no example |
--permissions | Comma-separated list of tool permissions to allow; anything omitted is denied (opencode agent create). Default: all. Includes bash, read, edit, glob, grep, task, lsp, skill and others. Alias: --tools Docs: --permissions | -no example |
--model | Model to use, in provider/model format (opencode agent create). Short: -m. Docs: --model | -no example |
--dir | Working directory to start TUI in (opencode attach). Docs: --dir | -no example |
--continue | Continue the last session (opencode attach). Short: -c. Docs: --continue | -no example |
--session | Session ID to continue (opencode attach). Short: -s. Docs: --session | -no example |
--fork | Fork the session when continuing (use with --continue or --session) (opencode attach). Docs: --fork | -no example |
--password | Basic auth password (opencode attach). Short: -p. Defaults to OPENCODE_SERVER_PASSWORD Docs: --password | -no example |
--username | Basic auth username (opencode attach). Short: -u. Defaults to OPENCODE_SERVER_USERNAME or opencode Docs: --username | -no example |
--provider | Provider ID or name to log in to (opencode auth login). Short: -p. Docs: --provider | -no example |
--method | Login method label to use, skipping method selection (opencode auth login). Short: -m. Docs: --method | -no example |
--event | GitHub mock event to run the agent for (opencode github run). Docs: --event | -no example |
--token | GitHub personal access token (opencode github run). Docs: --token | -no example |
--refresh | Refresh the models cache from models.dev (opencode models). Docs: --refresh | opencode models --refresh |
--verbose | Use more verbose model output (includes metadata like costs) (opencode models). Docs: --verbose | -no example |
--command | The command to run, use message for args (opencode run). Docs: --command | -no example |
--continue | Continue the last session (opencode run). Short: -c. Docs: --continue | -no example |
--session | Session ID to continue (opencode run). Short: -s. Docs: --session | -no example |
--fork | Fork the session when continuing (use with --continue or --session) (opencode run). Docs: --fork | -no example |
--model | Model to use in the form of provider/model (opencode run). Short: -m. Docs: --model | -no example |
--agent | Agent to use (opencode run). Docs: --agent | -no example |
--file | File(s) to attach to message (opencode run). Short: -f. Docs: --file | -no example |
--format | Output format (opencode run). default (formatted) or json (raw JSON events) Docs: --format | -no example |
--title | Title for the session (opencode run). Uses truncated prompt if no value provided Docs: --title | -no example |
--attach | Attach to a running opencode server (e.g., http://localhost:4096) (opencode run). Docs: --attach | opencode run --attach http://localhost:4096 "Explain async/await in JavaScript" |
--password | Basic auth password (opencode run). Short: -p. Defaults to OPENCODE_SERVER_PASSWORD Docs: --password | -no example |
--username | Basic auth username (opencode run). Short: -u. Defaults to OPENCODE_SERVER_USERNAME or opencode Docs: --username | -no example |
--dir | Directory to run in, or path on the remote server when attaching (opencode run). Docs: --dir | -no example |
--port | Port for the local server (opencode run). Defaults to random port Docs: --port | -no example |
--variant | Model variant (provider-specific reasoning effort) (opencode run). Docs: --variant | -no example |
--thinking | Show thinking blocks (opencode run). Docs: --thinking | -no example |
--auto | Auto-approve permissions that are not explicitly denied (opencode run). Docs: --auto | opencode run --auto "Refactor this module" |
--port | Port to listen on (opencode serve). Default: 4096 (server docs) Docs: --port | -no example |
--hostname | Hostname to listen on (opencode serve). Default: 127.0.0.1 (server docs) Docs: --hostname | -no example |
--mdns | Enable mDNS discovery (opencode serve). Default: false (server docs) Docs: --mdns | -no example |
--mdns-domain | Custom mDNS domain name (opencode serve). Default: opencode.local (server docs) Docs: --mdns-domain | -no example |
--cors | Additional browser origin(s) to allow CORS (opencode serve). Default: [] ; can be passed multiple times (server docs) Docs: --cors | opencode serve --cors http://localhost:5173 --cors https://app.example.com |
--port | Port to listen on (opencode web). Docs: --port | opencode web --port 4096 |
--hostname | Hostname to listen on (opencode web). Docs: --hostname | opencode web --hostname 0.0.0.0 |
--mdns | Enable mDNS discovery (opencode web). Docs: --mdns | opencode web --mdns |
--mdns-domain | Custom mDNS domain name (opencode web). Docs: --mdns-domain | opencode web --mdns --mdns-domain myproject.local |
--cors | Additional browser origin(s) to allow CORS (opencode web). Docs: --cors | opencode web --cors https://example.com |
--cwd | Working directory (opencode acp). Docs: --cwd | -no example |
--port | Port to listen on (opencode acp). Docs: --port | -no example |
--hostname | Hostname to listen on (opencode acp). Docs: --hostname | -no example |
--mdns | Enable mDNS discovery (opencode acp). Docs: --mdns | -no example |
--mdns-domain | Custom mDNS domain name (opencode acp). Docs: --mdns-domain | -no example |
--cors | Additional browser origin(s) to allow CORS (opencode acp). Docs: --cors | -no example |
--max-count | Limit to N most recent sessions (opencode session list). Short: -n. Docs: --max-count | -no example |
--format | Output format (opencode session list). table or json (default table) Docs: --format | -no example |
--days | Show stats for the last N days (opencode stats). Default: all time Docs: --days | -no example |
--tools | Number of tools to show (opencode stats). Default: all Docs: --tools | -no example |
--models | Show model usage breakdown (hidden by default); pass a number to show top N (opencode stats). Docs: --models | -no example |
--project | Filter by project (opencode stats). Default: all projects; empty string: current project Docs: --project | -no example |
--sanitize | Redact sensitive transcript/file data (opencode export). Docs: --sanitize | -no example |
--global | Install in global config (opencode plugin). Short: -g. Docs: --global | -no example |
--force | Replace existing plugin version (opencode plugin). Short: -f. Docs: --force | -no example |
--format | Output format (opencode db). json or tsv Docs: --format | -no example |
--keep-config | Keep configuration files (opencode uninstall). Short: -c. Docs: --keep-config | -no example |
--keep-data | Keep session data and snapshots (opencode uninstall). Short: -d. Docs: --keep-data | -no example |
--dry-run | Show what would be removed without removing (opencode uninstall). Docs: --dry-run | -no example |
--force | Skip confirmation prompts (opencode uninstall). Short: -f. Docs: --force | -no example |
--method | The installation method that was used (opencode upgrade). Short: -m. curl, npm, pnpm, bun, brew Docs: --method | -no example |
--help | Global flag: Display help. Short: -h. Docs: --help | -no example |
--version | Global flag: Print version number. Short: -v. Docs: --version | -no example |
--print-logs | Global flag: Print logs to stderr. Docs: --print-logs | -no example |
--log-level | Global flag: Log level. DEBUG, INFO, WARN, ERROR Docs: --log-level | opencode --log-level DEBUG |
--pure | Global flag: Run without external plugins. Docs: --pure | -no example |
The rest of the OpenCode reference
FAQ
How many CLI flags does OpenCode have?
The official OpenCode docs list 82 CLI flags, including --continue, --session and --fork. All of them are in the table above, in the docs' order.
What does --continue do in OpenCode?
Continue the last session (opencode tui). Values: Short: -c.
Where are OpenCode CLI flags 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/82 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.