Skip to main content

Overview

While OpenCode is running, you can execute special commands by prefixing them with /. These commands control the session, invoke custom workflows, and manage your environment.

Built-in Commands

Session Control

Change the model for the current session.
The model persists for the rest of the session. Use the format provider/model as shown in opencode models.
Change the agent for the current session.
Switches to a different agent configuration. See agent command for managing agents.
Undo the last assistant message and return to the previous state.
Removes the last message from history and reverts any changes. Can be used multiple times to step backwards.
Redo a previously undone message.
Reapplies messages that were undone. Only works if you haven’t sent new messages after undoing.
Create a shareable link for the current session.
Generates a URL (like https://opncd.ai/s/abc123) that others can view. See sharing documentation for details.
Create a new session from the current point.
Creates a branch of the conversation, allowing you to explore different directions without affecting the original.

Custom Commands

You can define custom commands that execute predefined prompts with arguments.
Built-in command to create or update AGENTS.md in your project.
This documents your project structure and conventions for OpenCode to reference.
Built-in command to review code changes.
Reviews uncommitted changes by default, or specify:
  • commit - Review the last commit
  • branch - Review all changes in the current branch
  • pr - Review changes in a pull request

Defining Custom Commands

Create custom commands in opencode.json:

Command Configuration

description
string
required
Short description shown in command autocomplete
template
string
required
The prompt template to execute. Can include:
  • $1, $2, etc. - Numbered arguments
  • $ARGUMENTS - All arguments as a single string
agent
string
Specific agent to use for this command
model
string
Specific model to use (format: provider/model)
subtask
boolean
default:"false"
Whether to execute as a subtask (uses Task tool)

Using Arguments

Commands can accept arguments:
Usage:
Expands to:

Argument Placeholders

  • $1, $2, $3 - Individual positional arguments
  • $ARGUMENTS - All arguments combined into a single string
Example with $ARGUMENTS:
Usage:

MCP Prompts

If you have MCP servers configured, their prompts are automatically available as commands:
MCP prompts:
  • Use the server’s prompt name as the command
  • Accept arguments as defined by the server
  • Are dynamically loaded from connected servers

Skills as Commands

Skills are automatically available as commands:
Skills:
  • Use the skill name as the command
  • Inject their content as the prompt
  • Can bundle templates, scripts, and references

Command Discovery

To see available commands:
  1. Autocomplete: Type / in the TUI to see suggestions
  2. Description: Commands show their description in autocomplete
  3. Help: Commands with arguments show hints (e.g., $1, $2)

Command Priority

When multiple sources define a command with the same name:
  1. Built-in commands (e.g., /init, /review)
  2. User-defined commands (in opencode.json)
  3. MCP prompts
  4. Skills
Higher priority commands override lower ones.

Examples

Development Workflow

Testing Workflows

Documentation

Refactoring

Running Commands Programmatically

Use the run command with --command flag:
This executes the test command with the given arguments without opening the TUI.

Best Practices

Clear descriptions

Write concise descriptions that explain when to use each command

Specific templates

Be explicit in templates about what the agent should do

Use arguments

Make commands flexible with argument placeholders

Choose agents

Assign specialized agents to appropriate commands

Commands Config

Learn more about command configuration

Agents

Create specialized agents

MCP Servers

Add MCP prompts as commands

Skills

Install and use skills