What it is

A command is a predefined prompt template triggered by a slash command in the TUI (e.g., /review, /deploy). Commands wrap a prompt with optional parameters, file references, and shell output injection to streamline repetitive tasks.

What it is in real OpenCode terms

In OpenCode, commands let you create reusable workflows. Instead of typing a long prompt every time you need to review a PR or generate tests, you define a command once and trigger it with /command-name. Built-in commands include /init, /undo, /redo, /share, and /help.

Why it exists

Coding workflows repeat. You run the same review prompts, the same deployment checks, the same documentation generation. Commands eliminate copy-paste by encoding these patterns into named, shareable shortcuts with smart parameter support.

Anatomy / main elements

  • Template: The prompt sent to the LLM (required)
  • Description: Human-readable help text
  • Agent: Which agent handles this command
  • Subtask: Whether to run as a subtask
  • Model: Override the model for this command
  • Parameters: $ARGUMENTS (all args), $1, $2, etc. (positional)
  • Shell injection: !`command` runs bash and injects output
  • File references: @filename includes file content

Where it lives

Commands are defined in two ways:

  1. In opencode.json under the "command" key
  2. As Markdown files in .opencode/commands/ or ~/.config/opencode/commands/

Markdown files are named after the command: .opencode/commands/review.md becomes /review.

How to create one

Option 1: opencode.json

{
  "command": {
    "review": {
      "template": "Review the changes in $1 for bugs, style issues, and potential improvements. Be specific.",
      "description": "Review a file or PR for issues",
      "agent": "code"
    }
  }
}

Option 2: Markdown file

# .opencode/commands/review.md
---
description: Review a file or PR for issues
agent: code
---

Review the changes in $1 for bugs, style issues, and potential improvements. Be specific about line numbers and suggest fixes.

Minimal example

# .opencode/commands/test.md
---
description: Generate tests for a file
---

Write comprehensive unit tests for @{{ $1 }}. Cover edge cases and error handling. Use the existing test patterns in the project.

Usage in TUI: /test src/auth.ts

With shell injection:

# .opencode/commands/deploy-check.md
---
description: Check deployment readiness
---

Run the following checks and report results:
1. Lint: !`npm run lint`
2. Tests: !`npm test`
3. Build: !`npm run build`

Summarize pass/fail status.

Common confusion

Command vs Tool: Commands are prompt templates with parameters. Tools are functions the LLM calls. Commands use tools internally.
Custom vs Built-in: Custom commands can override built-in ones (/init, /undo, etc.). Use this carefully.
Markdown vs JSON: Both work. Markdown is easier for multi-line templates. JSON is better for programmatic configs.
$ARGUMENTS vs $1: $ARGUMENTS captures everything. $1, $2 capture positional parameters split by spaces.