Skip to content

CLI

Once installed you can run the OpenCode CLI.

Terminal window
opencode

Or pass in flags. For example, to start with debug logging:

Terminal window
opencode -d

Or start with a specific working directory.

Terminal window
opencode -c /path/to/project

Flags

The OpenCode CLI takes the following flags.

FlagShortDescription
--help-hDisplay help
--debug-dEnable debug mode
--cwd-cSet current working directory
--prompt-pRun a single prompt in non-interactive mode
--output-format-fOutput format for non-interactive mode, text or json
--quiet-qHide spinner in non-interactive mode
--verboseDisplay logs to stderr in non-interactive mode
--allowedToolsRestrict the agent to only use specified tools
--excludedToolsPrevent 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.

Terminal window
opencode -p "Explain the use of context in Go"

If you want to run without showing the spinner, use -q.

Terminal window
opencode -p "Explain the use of context in Go" -q

In 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.

  • --allowedTools

    A 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
  • --excludedTools

    Comma-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.

Terminal window
opencode -p "Explain the use of context in Go" -f json

By default, this is set to text, to return plain text.