Create and use Custom Commands
mainCustom commands are predefined prompts stored as Markdown files. When executed, the file content is sent to the AI assistant.
Command Locations
- User Commands (prefixed with
user:):$XDG_CONFIG_HOME/opencode/commands/(e.g.,~/.config/opencode/commands/)$HOME/.opencode/commands/
- Project Commands (prefixed with
project:):<PROJECT DIR>/.opencode/commands/
Creating Commands
Each .md file name (without extension) becomes the command ID. Subdirectories create nested IDs (e.g., ~/.config/opencode/commands/git/commit.md becomes user:git:commit).
Using Arguments
Use $NAME placeholders (uppercase, numbers, underscores, starting with a letter) to define arguments. OpenCode will prompt for these values at runtime.
Example ~/.config/opencode/commands/prime-context.md:
RUN git ls-files
READ README.mdExample with arguments:
# Fetch Context for Issue $ISSUE_NUMBER
RUN gh issue view $ISSUE_NUMBER --json title,body,comments
RUN git grep --author="$AUTHOR_NAME" -n .Execution
- Press
Ctrl+Kto open the command dialog. - Select your command (prefixed with
user:orproject:). - Press
Enterto execute.
# Fetch Context for Issue $ISSUE_NUMBER
RUN gh issue view $ISSUE_NUMBER --json title,body,comments
RUN git grep --author="$AUTHOR_NAME" -n .
RUN grep -R "$SEARCH_PATTERN" $DIRECTORY