Global flags
These flags are available for all OpenCode commands.Display help information about OpenCode and its usage.Short form:
-hPrint the current version of OpenCode and exit.Short form:
-vEnable debug mode with verbose logging output. Useful for troubleshooting issues or understanding OpenCode’s internal operations.Short form:
-dWhen enabled:- Log level is set to debug
- Detailed information about operations is displayed
- Helpful for debugging configuration or integration issues
Set the current working directory for OpenCode. The application will change to this directory before starting and use it as the root for all file operations.Short form:
-cUse cases:- Work with a specific project directory
- Run OpenCode from anywhere while targeting a specific location
- Useful in scripts where the working directory may vary
Non-interactive mode flags
These flags control OpenCode’s behavior in non-interactive mode.Run a single prompt in non-interactive mode. When this flag is provided, OpenCode:
- Processes the prompt immediately
- Prints the AI response to stdout
- Exits after completion
- Auto-approves all permissions for the session
- Does not launch the TUI
-pThis mode is ideal for:- Scripting and automation
- Quick queries without launching the full interface
- CI/CD pipelines
- Testing prompts
Multi-line prompts can be provided using shell quoting:
Specify the output format for non-interactive mode. Only applies when used with
The JSON format is useful for:
--prompt.Short form: -fSupported formats:| Format | Description | Example |
|---|---|---|
text | Plain text output (default) | The answer is... |
json | Response wrapped in JSON object | {"response": "The answer is..."} |
- Parsing responses programmatically
- Integration with other tools
- Structured data processing
- API-like usage
Hide the spinner animation in non-interactive mode. Only applies when used with
--prompt.Short form: -qBy default, OpenCode displays a spinner while processing your prompt. Use this flag to suppress the spinner when:- Running from scripts
- Piping output to other commands
- Using in automated workflows
- Logging output to files
- The spinner interferes with other terminal output
Flag combinations
Flags can be combined to achieve different behaviors:Flag precedence
When multiple configuration sources are present, OpenCode follows this precedence order:- Command-line flags (highest priority)
- Environment variables
- Local config file (
.opencode.jsonin working directory) - Global config file (
~/.opencode.jsonor~/.config/opencode/.opencode.json) - Default values (lowest priority)
debug is set in both the config file and via the -d flag, the flag takes precedence.
Boolean flags
Boolean flags like--debug, --quiet, and --help can be specified in multiple ways: