AgentSkillsCN

opencode-commands

创建并管理OpenCode斜杠命令。无论是定义/命令快捷方式、模板语法、参数插值,还是工作流组合,此功能都能助你得心应手。 当用户提出“创建命令”、“斜杠命令”、“/命令”、“快捷方式”时,或询问关于命令前言的选项时,应主动运用此功能。 示例: - 用户输入:“创建/review命令” → 设计带有描述与可选代理路由的命令 - 用户输入:“如何向命令传递参数?” → 详细解释$ARGUMENTS、$1、$2、`!shell`、@file等参数用法 - 用户输入:“制作一个运行测试的命令” → 创建带有Shell插值的命令

SKILL.md
--- frontmatter
name: opencode-commands
description: |-
  Create and manage OpenCode slash commands. Use for defining /command shortcuts, template syntax, argument interpolation, and workflow composition.
  
  Use proactively when user says "create a command", "slash command", "/command", "shortcut for", or asks about command frontmatter options.
  
  Examples:
  - user: "Create a /review command" → design command with description, optional agent routing
  - user: "How do I pass arguments to commands?" → explain $ARGUMENTS, $1, $2, `!shell`, @file
  - user: "Make a command that runs tests" → create command with shell interpolation
<overview>

Create user-accessible slash commands that streamline workflows.

</overview> <rules>

Command Fundamentals

Location

ScopePath
Project.opencode/command/<name>.md
Global~/.config/opencode/command/<name>.md

Commands MAY also be defined inline in opencode.json:

jsonc
{
  "command": {
    "my-command": {
      "template": "Do the thing with $ARGUMENTS",
      "description": "One-line description"
    }
  }
}

Frontmatter Options

FieldTypeDescription
descriptionstringREQUIRED. Brief description shown in command list
agentstringRoute to specific agent (e.g., plan for read-only research)
modelstringOverride model for this command
subtaskbooleanIf true, runs as background task via task tool

Template Placeholders

PlaceholderExpansion
$ARGUMENTSAll arguments after the command
$1, $2...Positional arguments (space-separated)
`!cmd`Output of shell command (e.g., `!git status`)
@filenameContents of file (e.g., @src/main.ts)
</rules> <examples>

Command Patterns

Simple Command

markdown
---
description: Run all tests with coverage
---

Run tests with coverage reporting:
\`!npm run test:coverage\`

Agent-Routed Command

markdown
---
description: Research a topic without modifying files
agent: explore
---

Research the following topic thoroughly, gathering context from the codebase and web:

$ARGUMENTS

Workflow Command with Arguments

markdown
---
description: Create a new component with tests
---

Create a new React component named "$1" in the $2 directory.

Requirements:
1. Component file with TypeScript
2. Test file with basic render test
3. Index export

Use the existing patterns from @src/components/Button/index.tsx

Background Task Command

markdown
---
description: Deep research task (runs in background)
subtask: true
agent: explore
---

Perform comprehensive research on: $ARGUMENTS

Return findings in a structured report.
</examples> <constraints>

Best Practices

MUST

  • Keep descriptions under 80 characters
  • Use agent: explore or agent: plan for read-only operations
  • Use subtask: true for long-running operations
  • Include example arguments in the description when helpful
  • Use @file to inject context from existing code

MUST NOT

  • Create commands that duplicate existing tools
  • Use commands for one-off tasks (just ask directly)
  • Forget to test with opencode run "test" after changes
  • Route to agents that don't exist
</constraints> <guidelines>

Command vs Direct Request

Commands are USER shortcuts. Use them when:

  • You repeat the same request pattern frequently
  • You want consistent agent/model routing
  • You need to inject file context or shell output

For one-off tasks, just ask Claude directly.

</guidelines> <examples>

Validation

After creating a command:

bash
opencode run "test"

Then test with:

code
/your-command test arguments
</examples>