/init, /undo, /redo, /share, /help. Learn more.
Create command files
Create markdown files in thecommands/ directory to define custom commands.
Create .opencode/commands/test.md:
.opencode/commands/test.md
/ followed by the command name.
Configure
You can add custom commands through the OpenCode config or by creating markdown files in thecommands/ directory.
JSON
Use thecommand option in your OpenCode config:
opencode.jsonc
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
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
$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…
.opencode/commands/create-file.md
$1withconfig.json$2withsrc$3with{ "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
.opencode/commands/review-changes.md
File references
Include files in your command using@ followed by the filename.
.opencode/commands/review-component.md
Options
Let’s look at the configuration options in detail.Template
Thetemplate option defines the prompt that will be sent to the LLM when the command is executed.
opencode.json
Description
Use thedescription option to provide a brief description of what the command does.
opencode.json
Agent
Use theagent 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
Subtask
Use thesubtask 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
Model
Use themodel config to override the default model for this command.
opencode.json
How commands work
Understanding the command system helps you create more powerful custom commands.Command discovery
OpenCode discovers commands from multiple sources:- Built-in commands:
/init,/review, etc. - Config file commands: Defined in
opencode.json - MCP prompts: Exposed by MCP servers as commands
- Skills: Skills can be invoked as commands (if no command with that name exists)
- Markdown files: Files in
.opencode/commands/directories
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
!`command`- Runs the command and injects its output
@path/to/file- Includes the file content
Command execution
When a command is executed:- The command is looked up by name
- The template is retrieved (may be async for MCP prompts)
- Placeholders are substituted with actual values
- The processed template is sent as a user message to the LLM
- If
agentis specified, the message is routed to that agent - If
subtaskis true, it’s executed as a subagent invocation
command.executed event is published:
Examples
Code review command
.opencode/commands/review.md
Documentation generator
.opencode/commands/document.md
/document src/utils/parser.ts
Test generator
.opencode/commands/generate-tests.md
/generate-tests src/parser.ts
Release notes
.opencode/commands/release-notes.md
Architecture review
.opencode/commands/architecture.md
Performance analysis
.opencode/commands/perf.md
/perf src/api/handler.ts
Migration helper
.opencode/commands/migrate.md
/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
/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
Usesubtask: 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: