Skip to content

Slash Commands Cheatsheet

Type / in the input box to trigger the command menu, or press Ctrl+P to open the command palette


📝 Course Notes

Key takeaways from this lesson:

Slash Commands Cheatsheet Notes


Built-in Commands

CommandFunctionDescription
/newNew SessionCreate a new conversation
/sessionsSession ListView historical sessions
/modelsModel SwitchSelect model
/connectAdd ProviderConfigure API Key
/undoUndoUndo file modifications
/redoRedoRedo undone modifications
/shareShareGenerate share link
/unshareUnshareCancel sharing
/compactCompactCompact context
/editorEditorOpen external editor
/exportExportExport session
/themeThemeSwitch theme
/initInitializeGenerate project rules
/helpHelpShow help

Note: Commands have no short aliases. For example, /themes should be /theme.


Command Details

/new - New Session

Create a new conversation session, clearing the current context.

/new

Use Cases:

  • When starting a new task
  • Current conversation is too long and needs a fresh start
  • Switching to an unrelated topic

/sessions - Session Management

Open the session list to switch to historical sessions.

/sessions

Features:

  • View all historical sessions
  • Quickly switch between sessions
  • Delete unwanted sessions

/models - Model Switch

Switch the currently used AI model.

/models

Features:

  • View available model list
  • Switch main model

/connect - Add Provider

Interactively configure a new model provider.

/connect

Credentials are stored in ~/.local/share/opencode/auth.json.

Supported Providers:

  • DeepSeek, Moonshot, MiniMax, Z.AI, etc.
  • Anthropic, OpenAI, Google, etc.
  • Local models like Ollama

See Model Providers List


/undo and /redo - Undo/Redo

Undo or redo AI's file modifications.

/undo   # Undo last modification
/redo   # Redo undone modification

How it Works:

  • Git-based implementation
  • Automatic checkpoint creation for each file modification
  • Multiple undo/redo operations supported

/share and /unshare - Share Session

Generate a session share link, or cancel sharing.

/share     # Generate share link
/unshare   # Cancel sharing

Notes:

  • Anyone can view the session content after sharing
  • Sensitive information (API Keys, etc.) is not shared
  • Link becomes invalid immediately after canceling sharing

/compact - Compact Context

When the conversation is too long, compress historical messages to save tokens.

/compact

Use Cases:

  • Conversation exceeds context limit
  • Want to save API costs
  • AI starts "forgetting" early content

How it Works:

  • AI summarizes historical conversation
  • Retains key information
  • Removes redundant content

/editor - External Editor

Open an external editor for editing long text.

/editor

Use Cases:

  • Input large blocks of code or text
  • Need complex editing features

Configuration:

bash
export EDITOR="code --wait"   # VS Code
export EDITOR=vim             # Vim

/export - Export Session

Export the current session as a JSON file.

/export

/theme - Theme Switch

Switch the TUI interface theme.

/theme

Built-in Themes:

  • opencode - Default
  • system - Adaptive to terminal
  • tokyonight - Tokyo Night
  • catppuccin - Catppuccin
  • gruvbox - Gruvbox
  • nord - Nord

Note: The command is /theme, not /themes.


/init - Project Initialization

Generate rule files for the current project.

/init

Features:

  • Analyzes project structure
  • Generates project rules
  • Creates .opencode/ directory

See Project Initialization


/help - Help

Display help information and available commands.

/help

Custom Commands

You can create your own slash commands. See Custom Commands.

Command File Location

Project-level: .opencode/command/*.md
Global-level: ~/.config/opencode/command/*.md

Example: Creating /review Command

markdown
---
description: Code Review
---

Please review the following code:
$ARGUMENTS

Usage:

/review @src/main.ts

Command Parameters

PlaceholderDescription
$ARGUMENTSAll arguments
$1, $2, ...Nth argument
!command``Shell command output
@fileFile reference

JSON Configuration

Source: commands.mdx

json
{
  "command": {
    "test": {
      "template": "Run tests and report failed cases",
      "description": "Run tests",
      "agent": "build",
      "model": "anthropic/claude-sonnet-4-20250514",
      "subtask": false
    }
  }
}

Configuration Options

OptionTypeRequiredDescription
templatestringPrompt sent to LLM
descriptionstringOptionalCommand description displayed in TUI
agentstringOptionalAgent to execute the command
modelstringOptionalOverride default model
subtaskbooleanOptionalForce execution as subtask (won't pollute main context)

subtask Note: If the agent specified by the command is a subagent, it will trigger subtask invocation by default. Set subtask: false to disable this behavior; set subtask: true to force subtask execution even if the agent's mode is primary.


Quick Reference

I want to...Type
Start a new conversation/new
View history/sessions
Change model/models
Add a provider/connect
Undo modifications/undo
Compact conversation/compact
Change theme/theme
Share session/share