CLI
Once installed you can run the OpenCode CLI.
opencodeOr pass in flags. For example, to start with debug logging:
opencode -dOr start with a specific working directory.
opencode -c /path/to/projectFlags
The OpenCode CLI takes the following flags.
| Flag | Short | Description |
|---|---|---|
--help | -h | Display help |
--debug | -d | Enable debug mode |
--cwd | -c | Set current working directory |
--prompt | -p | Run a single prompt in non-interactive mode |
--output-format | -f | Output format for non-interactive mode, text or json |
--quiet | -q | Hide spinner in non-interactive mode |
--verbose | Display logs to stderr in non-interactive mode | |
--allowedTools | Restrict the agent to only use specified tools | |
--excludedTools | Prevent the agent from using specified tools |
Non-interactive
By default, OpenCode runs in interactive mode.
But you can also run OpenCode in non-interactive mode by passing a prompt directly as a command-line argument. This is useful for scripting, automation, or when you want a quick answer without launching the full TUI.
For example, to run a single prompt use the -p flag.
opencode -p "Explain the use of context in Go"If you want to run without showing the spinner, use -q.
opencode -p "Explain the use of context in Go" -qIn this mode, OpenCode will process your prompt, print the result to standard output, and then exit. All permissions are auto-approved for the session.
Tool restrictions
You can control which tools the AI assistant has access to in non-interactive mode.
-
--allowedToolsA comma-separated list of tools that the agent is allowed to use. Only these tools will be available.
Terminal window opencode -p "Explain the use of context in Go" --allowedTools=view,ls,glob -
--excludedToolsComma-separated list of tools that the agent is not allowed to use. All other tools will be available.
Terminal window opencode -p "Explain the use of context in Go" --excludedTools=bash,edit
These flags are mutually exclusive. So you can either use --allowedTools or --excludedTools, but not both.
Output formats
In non-interactive mode, you can also set the CLI to return as JSON using -f.
opencode -p "Explain the use of context in Go" -f jsonBy default, this is set to text, to return plain text.