Skip to main content
Custom commands let you specify a prompt you want to run when that command is executed in the TUI.
Custom commands are in addition to the built-in commands like /init, /undo, /redo, /share, /help. Learn more.

Create command files

Create markdown files in the commands/ directory to define custom commands. Create .opencode/commands/test.md:
.opencode/commands/test.md
The frontmatter defines command properties. The content becomes the template. Use the command by typing / followed by the command name.

Configure

You can add custom commands through the OpenCode config or by creating markdown files in the commands/ directory.

JSON

Use the command option in your OpenCode config:
opencode.jsonc
Now you can run this command in the TUI:

Markdown

You can also define commands using markdown files. Place them in:
  • Global: ~/.config/opencode/commands/
  • Per-project: .opencode/commands/
~/.config/opencode/commands/test.md
The markdown file name becomes the command name. For example, test.md lets you run:

Prompt config

The prompts for the custom commands support several special placeholders and syntax.

Arguments

Pass arguments to commands using the $ARGUMENTS placeholder.
.opencode/commands/component.md
Run the command with arguments:
And $ARGUMENTS will be replaced with Button. You can also access individual arguments using positional parameters:
  • $1 - First argument
  • $2 - Second argument
  • $3 - Third argument
  • And so on…
For example:
.opencode/commands/create-file.md
Run the command:
This replaces:
  • $1 with config.json
  • $2 with src
  • $3 with { "key": "value" }

Shell output

Use !command to inject bash command output into your prompt. For example, to create a custom command that analyzes test coverage:
.opencode/commands/analyze-coverage.md
Or to review recent changes:
.opencode/commands/review-changes.md
Commands run in your project’s root directory and their output becomes part of the prompt.

File references

Include files in your command using @ followed by the filename.
.opencode/commands/review-component.md
The file content gets included in the prompt automatically.

Options

Let’s look at the configuration options in detail.

Template

The template option defines the prompt that will be sent to the LLM when the command is executed.
opencode.json
This is a required config option.

Description

Use the description option to provide a brief description of what the command does.
opencode.json
This is shown as the description in the TUI when you type in the command.

Agent

Use the agent config to optionally specify which agent should execute this command. If this is a subagent the command will trigger a subagent invocation by default. To disable this behavior, set subtask to false.
opencode.json
This is an optional config option. If not specified, defaults to your current agent.

Subtask

Use the subtask boolean to force the command to trigger a subagent invocation. This is useful if you want the command to not pollute your primary context and will force the agent to act as a subagent, even if mode is set to primary on the agent configuration.
opencode.json
This is an optional config option.

Model

Use the model config to override the default model for this command.
opencode.json
This is an optional config option.

How commands work

Understanding the command system helps you create more powerful custom commands.

Command discovery

OpenCode discovers commands from multiple sources:
  1. Built-in commands: /init, /review, etc.
  2. Config file commands: Defined in opencode.json
  3. MCP prompts: Exposed by MCP servers as commands
  4. Skills: Skills can be invoked as commands (if no command with that name exists)
  5. Markdown files: Files in .opencode/commands/ directories
Commands are loaded in this order, with later sources taking precedence:

Template processing

Command templates support several special syntaxes that are processed before being sent to the LLM: Argument substitution:
  • $ARGUMENTS - Replaced with all arguments as a single string
  • $1, $2, $3, etc. - Replaced with individual positional arguments
Shell execution:
  • !`command` - Runs the command and injects its output
File inclusion:
  • @path/to/file - Includes the file content
The system tracks which placeholders are available:
These hints are used by the TUI to show which arguments are expected.

Command execution

When a command is executed:
  1. The command is looked up by name
  2. The template is retrieved (may be async for MCP prompts)
  3. Placeholders are substituted with actual values
  4. The processed template is sent as a user message to the LLM
  5. If agent is specified, the message is routed to that agent
  6. If subtask is true, it’s executed as a subagent invocation
The command.executed event is published:

Examples

Code review command

.opencode/commands/review.md

Documentation generator

.opencode/commands/document.md
Usage: /document src/utils/parser.ts

Test generator

.opencode/commands/generate-tests.md
Usage: /generate-tests src/parser.ts

Release notes

.opencode/commands/release-notes.md

Architecture review

.opencode/commands/architecture.md

Performance analysis

.opencode/commands/perf.md
Usage: /perf src/api/handler.ts

Migration helper

.opencode/commands/migrate.md
Usage: /migrate lodash ramda

Built-in commands

opencode includes several built-in commands like /init, /undo, /redo, /share, /help; learn more.

/init

Creates or updates the AGENTS.md file by analyzing your project structure.

/review

Reviews code changes (commits, branches, or PRs). Defaults to reviewing uncommitted changes. Usage:
  • /review - Review uncommitted changes
  • /review commit abc123 - Review specific commit
  • /review branch feature-x - Review branch changes
  • /review pr 42 - Review pull request #42
The /review command is configured with subtask: true, meaning it runs as a subagent and doesn’t pollute your main context.
Custom commands can override built-in commands. If you define a custom command with the same name, it will override the built-in command.

Best practices

Use clear descriptions

The description appears in the TUI’s command list. Make it clear and concise:

Leverage shell commands

Use shell commands to provide context:

Combine with file references

Use appropriate agents

Route commands to specialized agents:

Set subtask when appropriate

Use subtask: true for:
  • Analysis tasks that don’t need to persist context
  • Review operations
  • One-off queries

Provide specific instructions

Be explicit about what you want:

Version control your commands

Commit your .opencode/commands/ directory to share commands with your team: