Skip to main content
Non-interactive mode allows you to run OpenCode with a single prompt from the command line, making it ideal for scripting, automation, and quick one-off queries.

Basic usage

Use the -p or --prompt flag to run a prompt without launching the TUI:
The AI’s response is printed to standard output, and OpenCode exits when complete.

Output formats

Control the output format using the -f or --output-format flag:

Text format (default)

Plain text output is the default format:
Output:

JSON format

Wrap the output in a JSON object for easier parsing:
Output:
Use JSON format when integrating OpenCode into scripts or CI/CD pipelines where you need to parse the output programmatically.

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
Be cautious when running OpenCode in non-interactive mode with prompts that could modify your system or access external resources. Review the prompt carefully before execution.

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:
Combine non-interactive mode with shell functions or aliases for frequently used commands:

Error handling

Non-interactive mode returns appropriate exit codes:
  • 0: Success
  • 1: Error occurred (configuration issue, network error, etc.)

Limitations

Non-interactive mode has some limitations compared to interactive mode:
  • No session continuity (each run is independent)
  • Cannot ask follow-up questions
  • No manual permission review
  • Limited visibility into AI reasoning process
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

Examples

Generate commit messages

Code refactoring suggestions

Documentation generation

Security analysis