command-creation
Original:🇺🇸 English
Translated
This skill should be used when the user asks to "create a command", "add a custom command", "make a slash command", "create /command", or needs guidance on creating custom commands in OpenCode.
3installs
Added on
NPX Install
npx skill4agent add the-perfect-developer/the-perfect-opencode command-creationTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Command Creation for OpenCode
Create custom slash commands for repetitive tasks that execute specific prompts with dynamic arguments.
MUST FOLLOW
Commands must only specify in their frontmatter — never . Model selection is managed at the agent level in . Adding a field to a command bypasses centralized configuration and creates inconsistency across the project.
agentmodelopencode.jsonmodelAlways ask the user which agent should run the command. The field is required and must never be omitted. The two primary choices are:
agent:- — For commands that create or modify files, run tests, build, or deploy
build - — For commands that analyze, review, or read without making changes
plan
yaml
---
description: Brief description
agent: build # or: plan
---Do not add to command frontmatter. To change the model used by a command, configure the target agent's model in .
model:opencode.jsonWhat Commands Are
Custom commands let you define reusable prompts that can be triggered with in the OpenCode TUI. They provide:
/command-name- Repetitive task automation - Common workflows like testing, deployment, code review
- Dynamic arguments - Pass parameters to customize command behavior
- Shell integration - Include bash command output in prompts
- File references - Automatically include file contents
- Agent and model selection - Route commands to specific agents or models
Commands execute immediately when invoked, sending the configured prompt to the LLM.
Quick Start
Create a command in three steps:
-
Create command file:bash
mkdir -p .opencode/commands touch .opencode/commands/test.md -
Add frontmatter and content to:
test.mdmarkdown--- description: Run tests with coverage agent: build model: anthropic/claude-3-5-sonnet-20241022 --- Run the full test suite with coverage report and show any failures. Focus on the failing tests and suggest fixes. -
Use the command in TUI:
/test
That's it! The command will execute the prompt with the configured settings.
File Locations
Create command files in these locations:
Project-local:
.opencode/commands/command-name.md
Global (user-wide):
~/.config/opencode/commands/command-name.md
Use project-local for repository-specific commands. Use global for general-purpose commands you use across projects.
Creating Commands
Method 1: Markdown Files (Recommended)
Create a markdown file in the directory. The filename becomes the command name.
commands/Structure:
.opencode/commands/
├── test.md # /test command
├── review.md # /review command
└── component.md # /component commandExample - :
.opencode/commands/review.mdmarkdown
---
description: Review code changes
agent: plan
---
Review recent git commits:
!`git log --oneline -10`
Review these changes and suggest any improvements.Frontmatter fields:
- - Brief description shown in TUI (optional)
description - - Which agent should execute the command (optional)
agent - - Force subagent invocation (optional boolean)
subtask - Do not use — model is managed inmodelat the agent levelopencode.json
The content after frontmatter becomes the command template.
Method 2: JSON Configuration
Add commands to using the option:
opencode.jsonccommandjsonc
{
"$schema": "https://opencode.ai/config.json",
"command": {
"test": {
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}Use JSON for simple commands or when you want all configuration in one file.
Command Templates
Templates support special syntax for dynamic behavior:
1. Arguments with $ARGUMENTS
Pass arguments to commands using the placeholder:
$ARGUMENTS.opencode/commands/component.mdmarkdown
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.Usage:
/component ButtonThis replaces with .
$ARGUMENTSButton2. Positional Arguments ($1, $2, $3, ...)
Access individual arguments using positional parameters:
.opencode/commands/create-file.mdmarkdown
---
description: Create a new file with content
---
Create a file named $1 in the directory $2
with the following content: $3Usage:
/create-file config.json src "{ \"key\": \"value\" }"This replaces:
- →
$1config.json - →
$2src - →
$3{ "key": "value" }
3. Shell Output with !command
commandInject bash command output into prompts using ! syntax:
command.opencode/commands/analyze-coverage.mdmarkdown
---
description: Analyze test coverage
---
Here are the current test results:
!`npm test`
Based on these results, suggest improvements to increase coverage.More examples:
markdown
Recent commits:
!`git log --oneline -10`
Current branch status:
!`git status`
Package versions:
!`npm list --depth=0`Commands run in your project's root directory and their output is included in the prompt.
4. File References with @
Include file contents using followed by the filename:
@.opencode/commands/review-component.mdmarkdown
---
description: Review component
---
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.The file content is automatically included in the prompt.
Multiple files:
markdown
Compare @src/old-api.ts and @src/new-api.ts.
Identify breaking changes and migration steps.Configuration Options
template (required for JSON)
The prompt sent to the LLM when the command executes.
JSON:
json
{
"command": {
"test": {
"template": "Run tests and report failures."
}
}
}Markdown: Content after frontmatter is the template.
description (optional)
Brief description shown in the TUI when typing the command.
JSON:
json
{
"command": {
"test": {
"description": "Run tests with coverage"
}
}
}Markdown:
yaml
---
description: Run tests with coverage
---agent (required)
Specify which agent should execute the command. Always ask the user whether the command should use or — never leave this field out.
buildplan- — For tasks that create/modify files, run tests, build, or deploy
build - — For analysis, code review, and read-only tasks
plan
JSON:
json
{
"command": {
"review": {
"agent": "plan"
}
}
}Markdown:
yaml
---
agent: plan
---If the agent is a subagent, the command triggers a subagent invocation by default. Disable with .
subtask: falseDefault: Current agent if not specified.
subtask (optional)
Force the command to trigger a subagent invocation. Useful to avoid polluting primary context.
JSON:
json
{
"command": {
"analyze": {
"subtask": true
}
}
}Markdown:
yaml
---
subtask: true
---This forces subagent behavior even if the agent's is .
modeprimarymodel (optional)
Override the default model for this command.
JSON:
json
{
"command": {
"analyze": {
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}Markdown:
yaml
---
model: anthropic/claude-3-5-sonnet-20241022
---Common Patterns
Testing Commands
.opencode/commands/test.mdmarkdown
---
description: Run tests with coverage
agent: build
---
Run the full test suite with coverage report:
!`npm test -- --coverage`
Analyze failures and suggest fixes.Code Review Commands
.opencode/commands/review.mdmarkdown
---
description: Review recent changes
---
Recent commits:
!`git log --oneline -10`
Changed files:
!`git diff --name-only HEAD~5`
Review these changes for:
- Code quality issues
- Performance concerns
- Security vulnerabilitiesComponent Generation Commands
.opencode/commands/component.mdmarkdown
---
description: Create React component
---
Create a new React component named $1:
- Location: src/components/$1.tsx
- Include TypeScript types
- Add basic props interface
- Follow project conventions from @src/components/Example.tsxUsage:
/component ButtonDeployment Commands
.opencode/commands/deploy.mdmarkdown
---
description: Deploy to environment
agent: build
subtask: true
---
Deploy to $1 environment:
!`git status`
Steps:
1. Run pre-deployment checks
2. Build production bundle
3. Deploy to $1
4. Verify deploymentUsage:
/deploy stagingDocumentation Commands
.opencode/commands/doc.mdmarkdown
---
description: Generate documentation
---
Generate documentation for $ARGUMENTS:
Code to document:
@$ARGUMENTS
Create comprehensive documentation including:
- Function/class description
- Parameters and return values
- Usage examples
- Edge casesUsage:
/doc src/utils/parser.tsBuilt-in Commands
OpenCode includes built-in commands:
- - Initialize OpenCode in a project
/init - - Undo last change
/undo - - Redo last undone change
/redo - - Share conversation
/share - - Show help
/help
Note: Custom commands can override built-in commands. If you define a custom command with the same name, it will replace the built-in version.
Best Practices
DO:
- Use markdown files for easier editing and version control
- Include clear descriptions for discoverability
- Use positional arguments for multiple parameters
- Leverage shell commands for dynamic context
- Test commands before sharing with team
- Use subagent mode for long-running or complex tasks
- Keep templates focused on a single task
DON'T:
- Create overly complex templates with too many arguments
- Use shell commands that modify system state
- Include sensitive data in command templates
- Override built-in commands unless necessary
- Forget to document what arguments commands expect
- Set in command frontmatter — use
model:only; model is managed inagent:opencode.json
Examples
See working examples in the directory:
examples/- - Test execution with coverage
test-command.md - - Component generation with arguments
component-command.md - - Code review with git integration
review-command.md - - Multi-step deployment workflow
deploy-command.md
Troubleshooting
Command doesn't appear:
- Verify file is in or
.opencode/commands/~/.config/opencode/commands/ - Check filename is lowercase with extension
.md - Ensure YAML frontmatter is valid (if used)
Arguments not replaced:
- Check you're using or
$ARGUMENTS,$1, etc.$2 - Verify you're passing arguments:
/command arg1 arg2
Shell command fails:
- Test command in terminal first:
bash -c "your command" - Check command runs from project root
- Verify command exists on system
File reference not working:
- Check file path is correct relative to project root
- Verify file exists:
ls path/to/file - Use forward slashes even on Windows
Additional Resources
Reference Files
For detailed information:
- - Complete template syntax reference
references/template-syntax.md - - All configuration options explained
references/configuration-options.md - - More command patterns and examples
references/common-patterns.md
Example Files
Working examples in :
examples/- - Test execution
test-command.md - - Component generation
component-command.md - - Code review
review-command.md - - Deployment workflow
deploy-command.md
Quick Reference
Markdown command structure:
markdown
---
description: Brief description
agent: agent-name
subtask: true
---
Template content with $ARGUMENTS or $1, $2
Include shell output: !`command`
Include files: @path/to/fileJSON command structure:
json
{
"command": {
"name": {
"template": "Prompt text",
"description": "Brief description",
"agent": "agent-name",
"model": "model-name",
"subtask": true
}
}
}Special syntax:
- - All arguments as single string
$ARGUMENTS - ,
$1,$2- Individual arguments by position$3 - !- Shell command output
command - - File contents
@path/to/file