Configure with Markdown
OpenCode discovers.md command files in commands/ directories:
.opencode/commands/team/review.md defines
/team/review. Files with other extensions, including .mdx, are not
discovered.
.opencode/commands/review.md
Configure with JSON
Add commands under thecommands key in any OpenCode JSON or JSONC
configuration file. Each entry’s key is the command name and
template is required.
opencode.jsonc
Fields
| Field | Required | Behavior |
|---|---|---|
template | JSON only | Prompt template. In a Markdown command, the file body supplies it. |
description | No | Text shown with the command in autocomplete. |
agent | No | Agent selected before the prompt runs. |
model | No | Model override in provider/model or provider/model#variant format. |
subtask | No | Accepted as a boolean, but currently has no execution effect in V2. |
template in frontmatter because the Markdown body always supplies it.
Arguments
Use$ARGUMENTS for the complete argument string:
.opencode/commands/component.md
$1, $2, and higher numbers for parsed positional arguments. Single and
double quotes group text containing spaces and are removed during parsing.
.opencode/commands/check.md
$1, then $1 receives the full parsed argument list. Missing positions
become empty strings.
If a template contains neither positional placeholders nor $ARGUMENTS,
OpenCode appends non-empty arguments to the template after a blank line.
Shell interpolation
Wrap a shell command in! followed by backticks to insert its output before
the prompt is submitted:
.opencode/commands/review-diff.md
@path
written into a stored template remains ordinary prompt text; V2 does not
automatically attach that file.
Agent, model, and execution
Running a command evaluates its arguments and shell blocks, submits the result as a durable user prompt in the current session, and schedules normal model execution. Ifagent is set, it overrides the agent selected when the command was
invoked and becomes the session’s active agent. If model is set, it overrides
the model. Otherwise, a model configured on the command’s agent takes
precedence over the model selected at invocation.
Although subtask is accepted in JSON and frontmatter, V2 currently ignores
it: commands run in the current session and do not create a child session.
Selecting an agent whose mode is subagent also does not turn the command into
a subtask.