Basic usage
Use the-p or --prompt flag to run a prompt without launching the TUI:
Output formats
Control the output format using the-f or --output-format flag:
Text format (default)
Plain text output is the default format:JSON format
Wrap the output in a JSON object for easier parsing:Quiet mode
By default, OpenCode displays a spinner animation while processing your query. Suppress the spinner with the-q or --quiet flag:
Quiet mode is particularly useful when piping output to other commands or running in automated environments where terminal animations may cause issues.
Combining flags
You can combine multiple flags for maximum control:Permissions in non-interactive mode
All permissions are automatically approved when running in non-interactive mode:- The AI can run commands without asking
- File edits are applied automatically
- URLs are fetched without confirmation
Session management
Each non-interactive run creates a new session:- The session title includes “Non-interactive:” followed by the prompt (truncated to 100 characters)
- The session is saved to the database like any other session
- You can view non-interactive sessions later in interactive mode using
Ctrl+S
Use cases
Quick code explanations
Get instant explanations without launching the full TUI:Automated code review
Integrate OpenCode into CI/CD pipelines:Script integration
Use OpenCode as part of larger automation workflows:Git hooks
Add AI assistance to your git workflow:Error handling
Non-interactive mode returns appropriate exit codes:0: Success1: Error occurred (configuration issue, network error, etc.)
Limitations
For complex tasks requiring back-and-forth conversation, use interactive mode instead:Configuration
Non-interactive mode respects your configuration file (~/.opencode.json):
- Uses configured AI model and provider
- Applies shell configuration
- Respects LSP settings
- Uses configured data directory