---
title: CLI
---

Once installed you can run the OpenCode CLI.

```bash
opencode
```

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

```bash
opencode -d
```

Or start with a specific working directory.

```bash
opencode -c /path/to/project
```

## Flags 

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.

```bash "-p"
opencode -p "Explain the use of context in Go"
```

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

```bash "-q"
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.

  ```bash "--allowedTools"
  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.

  ```bash "--excludedTools"
  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`.

```bash "-f json"
opencode -p "Explain the use of context in Go" -f json
```

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