You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
248
+
You can run OpenCode in non-interactive mode by passing a prompt directly as a command-line argument or by piping text into the command. This is useful for scripting, automation, or when you want a quick answer without launching the full TUI.
249
249
250
250
```bash
251
251
# Run a single prompt and print the AI's response to the terminal
252
252
opencode -p "Explain the use of context in Go"
253
253
254
+
# Pipe input to OpenCode (equivalent to using -p flag)
255
+
echo"Explain the use of context in Go"| opencode
256
+
254
257
# Get response in JSON format
255
258
opencode -p "Explain the use of context in Go" -f json
259
+
# Or with piped input
260
+
echo"Explain the use of context in Go"| opencode -f json
256
261
257
262
# Run without showing the spinner
258
263
opencode -p "Explain the use of context in Go" -q
264
+
# Or with piped input
265
+
echo"Explain the use of context in Go"| opencode -q
259
266
260
267
# Enable verbose logging to stderr
261
268
opencode -p "Explain the use of context in Go" --verbose
269
+
# Or with piped input
270
+
echo"Explain the use of context in Go"| opencode --verbose
262
271
263
272
# Restrict the agent to only use specific tools
264
273
opencode -p "Explain the use of context in Go" --allowedTools=view,ls,glob
274
+
# Or with piped input
275
+
echo"Explain the use of context in Go"| opencode --allowedTools=view,ls,glob
265
276
266
277
# Prevent the agent from using specific tools
267
278
opencode -p "Explain the use of context in Go" --excludedTools=bash,edit
279
+
# Or with piped input
280
+
echo"Explain the use of context in Go"| opencode --excludedTools=bash,edit
268
281
```
269
282
270
283
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.
0 commit comments