|
|
@@ -15,10 +15,62 @@ opencode -d
|
|
|
opencode -c /path/to/project
|
|
|
```
|
|
|
|
|
|
+## Non-interactive Prompt Mode
|
|
|
+
|
|
|
+You can 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.
|
|
|
+
|
|
|
+```bash
|
|
|
+# Run a single prompt and print the AI's response to the terminal
|
|
|
+opencode -p "Explain the use of context in Go"
|
|
|
+
|
|
|
+# Get response in JSON format
|
|
|
+opencode -p "Explain the use of context in Go" -f json
|
|
|
+
|
|
|
+# Run without showing the spinner
|
|
|
+opencode -p "Explain the use of context in Go" -q
|
|
|
+
|
|
|
+# Enable verbose logging to stderr
|
|
|
+opencode -p "Explain the use of context in Go" --verbose
|
|
|
+
|
|
|
+# Restrict the agent to only use specific tools
|
|
|
+opencode -p "Explain the use of context in Go" --allowedTools=view,ls,glob
|
|
|
+
|
|
|
+# Prevent the agent from using specific tools
|
|
|
+opencode -p "Explain the use of context in Go" --excludedTools=bash,edit
|
|
|
+```
|
|
|
+
|
|
|
+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`: Comma-separated list of tools that the agent is allowed to use. Only these tools will be available.
|
|
|
+- `--excludedTools`: Comma-separated list of tools that the agent is not allowed to use. All other tools will be available.
|
|
|
+
|
|
|
+These flags are mutually exclusive - you can use either `--allowedTools` or `--excludedTools`, but not both at the same time.
|
|
|
+
|
|
|
+### Output Formats
|
|
|
+
|
|
|
+OpenCode supports the following output formats in non-interactive mode:
|
|
|
+
|
|
|
+| Format | Description |
|
|
|
+| ------ | -------------------------------------- |
|
|
|
+| `text` | Plain text output (default) |
|
|
|
+| `json` | Output wrapped in a JSON object |
|
|
|
+
|
|
|
+The output format is implemented as a strongly-typed `OutputFormat` in the codebase, ensuring type safety and validation when processing outputs.
|
|
|
+
|
|
|
## Command-line Flags
|
|
|
|
|
|
-| Flag | Short | Description |
|
|
|
-| --------- | ----- | ----------------------------- |
|
|
|
-| `--help` | `-h` | Display help information |
|
|
|
-| `--debug` | `-d` | Enable debug mode |
|
|
|
-| `--cwd` | `-c` | Set current working directory |
|
|
|
+| Flag | Short | Description |
|
|
|
+| ----------------- | ----- | ---------------------------------------------------------- |
|
|
|
+| `--help` | `-h` | Display help information |
|
|
|
+| `--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, 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 |
|