31 tools· updated nov 2026

opencode run: one prompt without the TUI, any model, and what happens to permission asks

Marek.

  • opencode
  • coding-agents
  • agent-ops

opencode run "your prompt" is the non-interactive mode of opencode. It sends one message, prints the reply and exits. No TUI opens. This post is for people who script opencode or come from claude -p. --model picks the model, local ones included. --auto approves permission asks. I do not run opencode. It is not installed on my machine. Everything here comes from the docs and the source at tags v1.19.5 and v2.2.5, read on 6 November 2026.

opencode run "Explain this repository"
git diff | opencode run "write a commit message"
opencode run --model anthropic/claude-sonnet-5-5 --format json "List the TODO comments"
opencode run --auto "Fix the failing test"
  • Non-interactive. opencode run prints the answer and exits. Piped stdin is added after the message.
  • Model. --model provider/model, short -m. opencode 2 adds #variant to the same string.
  • Local models. opencode 2 finds Ollama, LM Studio and vLLM by itself. opencode 1 needs a provider block.
  • Permissions. Most tools are allowed by default. A request that would ask gets rejected unless you pass --auto.
  • How I know. Docs and code only. No run of my own.

The Claude Code side is in my claude -p post. The Gemini CLI side is in Gemini CLI headless. This is the opencode side.

What does opencode run do?

opencode run runs opencode without the terminal UI. The opencode 1 CLI page says it will "Run opencode in non-interactive mode by passing a prompt directly." The opencode 2 commands page says it "Sends a message and prints the reply without opening the interactive interface."

The message is every word after run. In both versions the source joins piped stdin to it, message first. With no message and no stdin, opencode 1 exits with "You must provide a message or a command". opencode 2.2.5 says "You must provide a message". Errors set exit code 1. In opencode 2.2.5 a run you interrupt yourself exits with 130.

opencode 2 has one twist. Per its CLI page, clients connect to "one shared background server for your user account". --standalone gives the run a private server. The CI example on the commands page uses it so the private server gets the API key.

How do I choose a model with opencode run?

Pass --model, short -m, as provider/model. The opencode 2 models page says it chooses "a model for one command-line run without changing the configured default". Run opencode models to see the exact IDs. Without the flag, a new session takes the model key from opencode.json.

Reasoning effort works differently in each version. opencode 1 has a separate --variant flag. In opencode 2.2.5 the flag help reads "Model to use in the format provider/model#variant". The docs example is openai/gpt-6.1-sol#high. In opencode 1 the source splits the string at the first slash. The provider ID comes before it. Everything after it is the model ID.

Can opencode run use a local model?

Yes. A local model is a provider like any other, so --model takes it the same way. The opencode 2 models page says opencode "automatically discovers models from Ollama, LM Studio, and vLLM at their default local addresses". For Ollama that is http://127.0.0.1:11434. The model string looks like ollama/gemma3:4b.

opencode 1 needs a provider entry first. The providers page shows an ollama block with the @ai-sdk/openai-compatible package and http://localhost:11434/v1 as baseURL. The model you list there becomes ollama/<id>. Its tip for Ollama: if tool calls fail, raise num_ctx, starting "around 16k - 32k".

opencode run -m ollama/gemma3:4b "Summarize README.md"

How do I run opencode with all permissions?

Add --auto. The permissions page says it approves "permission requests that are not explicitly denied". Explicit deny rules still apply. --yolo and --dangerously-skip-permissions are hidden aliases in both versions. What each one covers is in opencode --dangerously-skip-permissions.

Without --auto nobody can answer a prompt. In opencode 1.19.5, run.ts prints permission requested: ...; auto-rejecting and replies reject. It also creates new sessions with question, plan_enter and plan_exit denied. opencode 2.2.5 rejects with a message to the model: "This non-interactive run cannot ask the user for permission, so the request was rejected. Continue without this action." Questions get cancelled the same way.

The defaults matter more than the flag. Per the docs, opencode 1 allows most tools and asks for doom_loop, external_directory and .env reads. The opencode 2 base policy allows everything and asks only for .env files. So a plain opencode run already edits files and runs commands. --auto mostly clears the few asks left.

Can opencode run a shell command from a script?

Yes. A prompt that needs a command makes the model call the shell tool, and that tool is allowed by default. The opencode 2 permissions page warns that "shell runs with the host user's filesystem, process, and network authority". Narrow it with permission rules. A check written in code is in my opencode hooks post.

opencode 1 also has --command. It runs a command such as one of your custom commands, with the message as its arguments. Per the commands page, a command file can inject output with !`git log --oneline -10`. The !ls prefix from the TUI page is a TUI feature. I found no --command flag on run in the opencode 2.2.5 command spec.

What does opencode run --format json print?

Newline-delimited JSON events. Each line has type, timestamp and sessionID. In both versions the source emits text, tool_use, step_start, step_finish and error. reasoning lines appear with --thinking. Use the sessionID for a follow-up with --session. The rules for that are in opencode resume.

The v2 commands page also lists --archived for CI runs. That flag is not in the 2.2.5 spec, only on the dev branch on 6 November 2026. Check opencode run --help on your build.

How does opencode run compare with claude -p and gemini -p?

All three run one prompt and exit. They differ on the prompt nobody answers. The Claude Code and Gemini CLI columns come from my earlier posts.

Jobopencode runclaude -pgemini -p
Machine output--format json--output-format json, stream-json-o json, -o stream-json
Model-m provider/model--model-m
Continue-c, -s <id>--continue, --resume <id>-r latest, -r <id>
Unanswered askRejected, unless --autoDenied without a permission hostDenied
Skip all asks--auto--dangerously-skip-permissions--approval-mode yolo

Frequently asked questions

Does opencode run open the TUI?

No. Both docs describe opencode run as a run without the interactive interface. opencode 2 has a separate opencode mini for a small interactive UI.

Does opencode run work with a local model?

Yes. Pass it to --model, for example ollama/gemma3:4b. opencode 2 discovers Ollama, LM Studio and vLLM on their default ports. opencode 1 needs a provider block in opencode.json.

Why did opencode run skip a step?

I think a rejected permission ask is the first suspect. Without --auto, the run rejects every ask. opencode 2.2.5 tells the model to continue without the action, so the reply can look complete. Check the files and the permission requested line.

Did you test this?

No. opencode is not installed on my machine. This post reads the docs and the source at tags v1.19.5 and v2.2.5 on 6 November 2026.

The verdict

opencode run is a usable script entry point. Pin the model with -m. Read the defaults first. A plain run already allows edits and shell commands. Write deny rules before you add --auto. I would run it in a container or a throwaway checkout.

Sources, read on 6 November 2026. opencode 1 pages: CLI, permissions, providers, commands and TUI. opencode 2 pages: CLI, commands, models and permissions. Code from anomalyco/opencode at tag v1.19.5 (packages/opencode/src/cli/cmd/run.ts) and tag v2.2.5 (packages/cli/src/commands/commands.ts, commands/handlers/run.ts, run/run.ts, run/noninteractive.ts), plus commands.ts on dev at commit 0e655ff.