Skip to main content

Overview

Custom commands let you define reusable workflows that encapsulate your team’s best practices, coding standards, and common tasks. They transform complex multi-step processes into simple commands.

Creating Commands

Define commands in opencode.json:
Then use them:

Command Structure

Basic Command

Minimal command definition:

With Arguments

Commands can accept arguments:
Usage:

With Specific Agent

Assign commands to specialized agents:

With Specific Model

Use a specific model for a command:

As Subtask

Execute command as a subtask (uses Task tool):
Subtasks:
  • Run in isolated context
  • Can use specialized agents
  • Results are summarized back to main agent
  • Useful for complex, independent tasks

Template Syntax

Positional Arguments

Use $1, $2, $3, etc. for individual arguments:
Usage:
Expands to:

All Arguments

Use $ARGUMENTS for all arguments as a single string:
Usage:
Expands to:

Escaping

To use literal $ in templates:

Multi-line Templates

Use arrays for multi-line templates:
Arrays are joined with newlines.

Real-World Examples

Development Workflow

Testing Commands

Code Quality

Documentation

Refactoring

Database

Command Discovery

Users can discover commands through:

Autocomplete

Type / to see all available commands:

Command Help

Commands show their descriptions in autocomplete with argument hints:

List Commands Programmatically

Via API:

Sharing Commands

Team Commands

Commit opencode.json to share commands with your team:
Team members get the commands automatically.

Global Commands

Add personal commands globally:
Global commands work in all projects.

Priority

When the same command name exists in multiple places:
  1. Project - .opencode/opencode.json (highest priority)
  2. Project root - opencode.json
  3. Global - ~/.config/opencode/opencode.json
  4. Built-in - /init, /review (lowest priority)

Command Libraries

Create reusable command libraries:
Import in your opencode.json:

Best Practices

Be specific

Write detailed templates that clearly describe expectations

Use agents

Assign specialized agents to appropriate commands

Add examples

Include examples in templates to guide the agent

Keep descriptions short

Use concise descriptions that explain when to use the command

Commands Config

Full command configuration reference

Agents

Create specialized agents

In-Session Commands

Learn about built-in commands

MCP Prompts

Add commands from MCP servers