We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

OpenCode Run

The opencode command opens the full-screen TUI, which is how I use OpenCode 90% of the time. However, sometimes you don't want to chat, you just need a single response. For example, scripts and one-off prompts don't need the interactive UI.

opencode run sends a prompt to the agent and returns its response directly:

opencode run "Explain how our auth middleware works"

In this mode, the agent can still read files, run tools, and use the project's configuration, but it won't open the TUI.

Any permission requests that need an interactive approval will be rejected in this mode.

Standard Output

Assistant messages go to stdout, while progress and tool activity go to stderr, making shell redirection useful:

opencode run "Summarize this project" > project-summary.md

You can also use --format json if another program needs structured events instead of plain text.

Sometimes I like to have one model do an "adversarial review" of another model's work before I look at it. I just instruct my agent to use opencode run --model <model> to run a different model when it's done for a second opinion.

Assignment

Use opencode run to add a SlopLang example that prints the result of 1 + 2 * 3.

  1. opencode run --model "<provider/model>" "Read docs/spec.md and examples/hello.slop. Create a new examples/arithmetic.slop file that prints the result of 1 + 2 * 3. Change only that example. Run it, confirm it prints 7, and run uv run pytest tests/test_examples.py -q."
    
  2. opencode run --continue "Describe the correction here"
    

Tell OpenCode to run and submit the CLI tests from the project root.

In SlopLang, the hallucinate function is the same as Python's print function, and the ✨ emoji is the statement terminator (like a semi-colon in C).