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
/model - Switch AI model
/model - Switch AI model
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./agent - Switch agent
/agent - Switch agent
Change the agent for the current session.Switches to a different agent configuration. See agent command for managing agents.
/undo - Revert last message
/undo - Revert last message
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 - Reapply message
/redo - Reapply message
Redo a previously undone message.Reapplies messages that were undone. Only works if you haven’t sent new messages after undoing.
/share - Share session
/share - Share session
/fork - Fork session
/fork - Fork session
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./init - Initialize project
/init - Initialize project
Built-in command to create or update This documents your project structure and conventions for OpenCode to reference.
AGENTS.md in your project./review - Review changes
/review - Review changes
Built-in command to review code changes.Reviews uncommitted changes by default, or specify:
commit- Review the last commitbranch- Review all changes in the current branchpr- Review changes in a pull request
Defining Custom Commands
Create custom commands inopencode.json:
Command Configuration
Short description shown in command autocomplete
The prompt template to execute. Can include:
$1,$2, etc. - Numbered arguments$ARGUMENTS- All arguments as a single string
Specific agent to use for this command
Specific model to use (format:
provider/model)Whether to execute as a subtask (uses Task tool)
Using Arguments
Commands can accept arguments:Argument Placeholders
$1,$2,$3… - Individual positional arguments$ARGUMENTS- All arguments combined into a single string
$ARGUMENTS:
MCP Prompts
If you have MCP servers configured, their prompts are automatically available as commands:- 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:- 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:- Autocomplete: Type
/in the TUI to see suggestions - Description: Commands show their description in autocomplete
- Help: Commands with arguments show hints (e.g.,
$1,$2)
Command Priority
When multiple sources define a command with the same name:- Built-in commands (e.g.,
/init,/review) - User-defined commands (in
opencode.json) - MCP prompts
- Skills
Examples
Development Workflow
Testing Workflows
Documentation
Refactoring
Running Commands Programmatically
Use therun command with --command flag:
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
Related Topics
Commands Config
Learn more about command configuration
Agents
Create specialized agents
MCP Servers
Add MCP prompts as commands
Skills
Install and use skills