SkilVaultSign inStart free

Catalogue / write-opencode-commands

write-opencode-commands

Older skill: source not recordedSignedGuides an agent through authoring custom OpenCode slash commands, either as markdown files in a commands directory or as entries under the command key of opencode.jsonc, covering the prompt template, description, agent, model and subtask settings, argument placeholders, shell output capture, file in…
---
name: write-opencode-commands
description: >
  Guides an agent through authoring custom OpenCode slash commands, either
  as markdown files in a commands directory or as entries under the command
  key of opencode.jsonc, covering the prompt template, description, agent,
  model and subtask settings, argument placeholders, shell output capture,
  file inlining, naming, scoping, built-in overrides and verification. Use
  when the user wants to create, edit, reorganize or override an OpenCode
  command, or to convert a repeatedly typed prompt into a reusable slash
  command. Not for defining agents, models or plugins, for the command
  systems of other tools, or for general prompt-writing help unrelated to
  OpenCode.
---

Writing OpenCode Slash Commands

An OpenCode command binds a prompt to a short name: the user types the name after a slash and OpenCode substitutes the stored template at invocation time. Walk the decisions in order — storage location, runtime settings, body composition — then produce the file or config entry and a test plan.

Where the command lives

| Container | Location | Name comes from | Choose it when | |---|---|---|---| | Project markdown file | .opencode/commands/ at the repo root | filename minus the .md extension | the default; it versions with the code and teammates inherit it on clone | | Personal markdown file | ~/.config/opencode/commands/ | filename minus the .md extension | utilities the user wants available in every project | | JSON entry | a key under command in opencode.jsonc (project) or the user-level config file | the entry's key | the user already centralizes settings there, or wants several small commands in one file |

Default to a project markdown file: it reviews cleanly in diffs and each command stays independently editable.

Runtime settings

In a markdown file, settings sit in YAML frontmatter between two --- lines and the text below them is the template. In JSON, every setting is a sibling key and the template is one of them:

| Key | Applies to | Meaning | |---|---|---| | template | JSON only, required; a markdown file's body serves this role | the prompt OpenCode sends when the command runs | | description | both, optional | one-liner displayed in the command picker | | agent | both, optional | id of a configured agent to execute it | | model | both, optional | model override written as provider/model-id | | subtask | both, optional boolean | true forces execution in a separate subagent, keeping the main conversation clean |

Reference an agent or model id only after confirming it exists in the user's setup — an invented id fails the moment the command runs. Reserve subtask: true for long or noisy analysis and leave interactive work in the main thread. Pin a smaller model only for genuinely trivial commands; leave it unset when quality matters.

Composing the body

Write the body as the instruction you would hand a capable assistant once. One command, one job — if a draft sprawls across unrelated tasks, propose splitting it. Then add only the dynamic pieces that earn their context cost:

| Token | Substituted at run time by | |---|---| | $ARGUMENTS | everything typed after the command name, as one string | | $1, $2, $3 | individual positional words; the user must quote multi-word values | | ` !command | output of a shell command, executed with bash from the project root when the command is invoked | | @path/to/file` | that file's contents, inlined into the prompt |

Vetting a shell capture

A capture executes on the user's machine the instant the command runs, so classify it before embedding. A friendly name proves nothing: package-manager and task-runner wrappers can write files, install software, or reach the network behind an innocuous label — open the underlying script and read it before judging. Embed only captures you have verified merely print information, favoring obviously read-only reporters that list, count, measure, or search. If behavior cannot be verified, drop the capture and have the user paste the output instead. Cap every capture's output with an explicit line or byte limit so a large result cannot swallow the context window.

Guarding consequential steps

If the command's job includes anything destructive, irreversible, or visible beyond the user's machine — deleting or overwriting files, rewriting version-control history, installing or removing software, publishing, deploying, sending messages, opening pull requests — the template itself must instruct the executing agent to halt before that step, present exactly what it intends to do, and wait for explicit approval in that conversation; on silence or hesitation, do nothing. Bake this pause into the body every time; never rely on the user to ask.

Naming and writing the artifact

  • Kebab-case, short, a verb or noun phrase (debt-scan, patch-notes, db-explain) — the name is what the user types.
  • Create the commands directory if it does not exist, then save the file. For JSON, merge the entry into the existing command object without disturbing neighboring keys.
  • Handle collisions out loud. A custom command may deliberately shadow a built-in such as /init, so if the chosen name is taken or overrides anything, state precisely what gets replaced and get the user's explicit go-ahead in this conversation before writing.

Verifying and handing off

Re-read the artifact before calling it done: frontmatter sits between --- delimiters and parses as YAML; the filename is kebab-case; every token you promised is present; agent and model ids are real; every capture is verified read-only and carries an explicit output cap; every consequential step has its pause. Then tell the user to reload or restart the session so the command registers, and to exercise it three ways — bare, with one argument, and with a quoted multi-word argument or the full positional set. Suggest committing project commands and noting them in the README.

Two worked examples

Markdown with a positional argument, a file reference and a pause — .opencode/commands/patch-notes.md, invoked as /patch-notes feat/rate-limiter:

---
description: Summarize a branch as draft release notes
agent: build
---
Summarize the changes on the "$1" branch as draft release notes.
Match the tone and layout in @docs/release-notes-guide.md.

Print the draft here for me to read first. Publishing notes is
visible outside this machine, so never publish on your own
initiative: show me the draft and wait until I approve in this
conversation.

JSON entry with an isolated subagent and a bounded, read-only capture — merged into opencode.jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "command": {
    "debt-scan": {
      "description": "Cluster open TODO and FIXME markers into themes",
      "agent": "plan",
      "model": "anthropic/claude-haiku-4-5",
      "subtask": true,
      "template": "Markers found under src, capped at the first 120 matching lines:\n!`grep -rn -E \"TODO|FIXME|HACK\" src --include=*.ts | head -n 120`\n\nCluster these into themes with a per-theme count, then name the three cheapest to clear. The capture above stops at 120 lines, so results may be truncated: treat the counts as a floor, state in your report that they come from a bounded sample, and say whether the cap was reached. Analysis only — change, delete, and send nothing."
    }
  }
}

The search capture passes inspection because it only reads and prints, and the trailing line limiter keeps the injection bounded; anything invoking project scripts would have to be opened and read before it could be embedded at all.

Things this skill must not do

  • Put a secret in a template. Command files are committed, cloned and shared, so a key, token, password or machine-specific path in one is effectively published — and never embed a capture whose purpose is printing credentials or environment secrets.
  • Embed a capture that writes or deletes files, alters version control, installs or publishes anything, makes network requests, or downloads code in order to run it. Unverified wrappers do not count as read-only.
  • Emit a template that performs a destructive, irreversible or externally visible step without the pause described above.
  • Overwrite an existing command file or shadow a built-in without explicit confirmation from the user in this conversation.
  • Guess agent or model ids; use only ones present in the user's configuration.

This skill does not cover defining agents, models or plugins — only the commands that reference them — and it ships no generator script; write the command files directly using the structures above.

If it misbehaves

| Symptom | Check | |---|---| | Command missing from the picker | directory and scope, filename spelling, session reloaded | | Arguments arrive empty | token actually present in the body; multi-word values quoted by the user | | Capture fails | it runs under bash from the project root — confirm the command is on PATH and works from that directory | | File reference loads nothing | path given relative to the project root, file exists |

Credit

Derived from an MIT-licensed community skill (origin: tumf/skills); the MIT License permits reuse and modification.