Overview
Theslashcommand tool executes custom slash commands defined in .opencode/commands/ or ~/.config/opencode/commands/.
Source: src/tools/slashcommand/
Command discovery
Commands are discovered from:- Project (
.opencode/commands/) - Highest priority - User (
~/.config/opencode/commands/) - Built-in (plugin commands) - Lowest priority
Command format
Example command file.opencode/commands/publish.sh:
Metadata format
Commands include JSON metadata in comments:description- Short description for command listingargumentHint- Argument format hint (shown in tool description)
Template variables
Commands support template variable substitution:{{USER_MESSAGE}}- Replaced with command arguments{{REPO_NAME}}- Current repository name{{BRANCH_NAME}}- Current git branch{{WORKSPACE_DIR}}- Workspace directory path
Parameters
Command name (with or without leading slash)Examples:
"/publish""publish"(slash optional)
Arguments to pass to the commandReplaces
{{USER_MESSAGE}} in command template and passed as $1 to scripts.Example:Response
Command execution resultSuccess:Error:
Usage examples
Execute command with arguments
Execute command without arguments
Command with template substitution
Command file:Command types
Shell scripts
Python scripts
Node.js scripts
Error handling
Command not found
Execution error
Permission denied
Migration to skill tool
Instead of usingslashcommand, use the skill tool:
Before (deprecated):
skill tool:
- Unified interface for skills and commands
- Better error messages
- Supports command priority and scoping
- Integrates with skill MCP servers
Command discovery details
Command discovery usesdiscoverCommandsSync() which:
- Scans command directories
- Reads metadata from file comments
- Determines command scope (project/user/builtin)
- Handles priority resolution
Implementation details
Metadata parsing
Metadata is extracted from file comments using regex matching:Template interpolation
Template variables are replaced before execution:Execution environment
Commands execute with:- Working directory: Project root
- Environment: Inherited from parent process
- Stdio: Captured for output