···11---
22name: skill-builder
33-description: Complete guide for creating new opencode skills and agents. Covers naming conventions, description requirements, directory structure for global and project-local skills, frontmatter formats with permission settings, content guidelines including line limits and RFC 2119 language, and a validation checklist. Use when building a new skill, creating a new agent, or setting up skill/agent directories.
33+description: Guide for creating opencode skills and agents. Covers skill directory structure, SKILL.md frontmatter format, writing effective descriptions with trigger phrases, progressive disclosure across three loading levels, content patterns (templates, workflows, feedback loops), agent file format with permissions, testing strategies, and a validation checklist. Use when building a new skill, creating a new agent, or setting up skill/agent directories.
44---
5566-## Naming Conventions
66+# Skill & Agent Authoring
77+88+You are creating a skill or agent for opencode. A skill is a folder containing a `SKILL.md` file. An agent is a standalone `.md` file. Both use YAML frontmatter + markdown body.
99+1010+## 1. Skill Structure
1111+1212+```
1313+<skill-name>/
1414+├── SKILL.md # required — the single entrypoint
1515+├── scripts/ # optional — bundled scripts for validation, generation
1616+├── references/ # optional — detailed docs, specs, examples
1717+└── assets/ # optional — templates, config files
1818+```
1919+2020+- File MUST be named exactly `SKILL.md` (case-sensitive)
2121+- Folder MUST use kebab-case: lowercase, hyphens only, no spaces/capitals/underscores
2222+- MUST NOT include a README.md inside skill folders, because SKILL.md is the single entrypoint and a README creates ambiguity about which file is authoritative
2323+- Skills live at `~/.config/opencode/skills/<name>/` (global) or `.opencode/skills/<name>/` (project-local)
2424+2525+## 2. Frontmatter Reference
2626+2727+```yaml
2828+---
2929+name: my-skill # required
3030+description: ... # required
3131+license: MIT # optional
3232+compatibility: ... # optional
3333+metadata: # optional
3434+ author: jane
3535+ version: "1.0"
3636+allowed-tools: Bash Read # optional, space-delimited
3737+---
3838+```
3939+4040+| Field | Constraints |
4141+|---|---|
4242+| `name` | 1-64 chars. Lowercase alphanumeric + hyphens. No leading/trailing/consecutive hyphens. MUST match folder name. |
4343+| `description` | 1-1024 chars. No XML angle brackets. See §3. |
4444+| `license` | Short license identifier (e.g., MIT, Apache-2.0). |
4545+| `compatibility` | 1-500 chars. Environment requirements (OS, runtime, tools). |
4646+| `metadata` | Key-value string map. |
4747+| `allowed-tools` | Space-delimited tool names pre-approved for this skill. |
4848+4949+Security constraints:
5050+- MUST NOT use XML angle brackets (`<` `>`) in any frontmatter value, because frontmatter is injected into XML-structured system prompts and unescaped brackets break parsing
5151+- `name` MUST NOT contain "claude" or "anthropic" (reserved)
5252+5353+## 3. Writing Effective Descriptions
5454+5555+The description is the most important part of a skill. It determines whether the agent loads the skill. Descriptions are injected into the system prompt as-is, so they MUST be written in third person.
5656+5757+### Structure
75888-### Skills
5959+```
6060+[What it does] + [When to use it] + [Key capabilities/keywords]
6161+```
9621010-- 1-64 characters
1111-- Lowercase alphanumeric with single hyphens only
1212-- NO leading or trailing hyphens
1313-- NO consecutive hyphens
1414-- MUST match the folder name
6363+Front-load the primary use case. Include trigger phrases — the words a user would actually say.
15641616-### Agents
6565+### Good Examples
17661818-- Filename determines agent name (e.g., `orchestrator.md` creates `orchestrator` agent)
1919-- MUST use `.md` extension
6767+```
6868+Systematic debugging protocol emphasizing empirical investigation over code
6969+reasoning. Covers the observe-hypothesize-experiment-narrow loop, establishing
7070+failure conditions, gathering evidence from logs and git history. Use when
7171+investigating crashes, test failures, unexpected behavior, or any situation
7272+where the system is not doing what it should.
7373+```
20742121-## Description Requirements
7575+```
7676+Guide for writing database migrations in PostgreSQL. Covers safe column
7777+additions, index creation with CONCURRENTLY, data backfills, and rollback
7878+strategies. Use when creating, modifying, or reviewing database migrations.
7979+Keywords: schema change, ALTER TABLE, CREATE INDEX.
8080+```
22812323-MUST include:
8282+```
8383+Enforces clean coding conventions for any implementation task. Covers guard
8484+clauses, happy-path alignment, pure functions, error handling. Use when writing
8585+new code, refactoring, fixing bugs, or reviewing code for quality.
8686+```
8787+8888+### Bad Examples
8989+9090+- `"Helps with projects"` — too vague, no trigger conditions, will never fire
9191+- `"A comprehensive tool for managing all aspects of deployment"` — no specifics, no keywords
9292+- `"Use this skill when needed"` — circular, gives the agent nothing to match against
9393+9494+### Preventing Mis-triggers
9595+9696+SHOULD include negative triggers when the skill's domain overlaps with common tasks:
9797+9898+```
9999+Do NOT use for simple one-off SQL queries — only for schema migrations.
100100+```
101101+102102+### Debugging Trigger Issues
103103+104104+Ask the agent: _"When would you use the [skill name] skill?"_ If it cannot answer clearly, the description needs work.
105105+106106+## 4. Progressive Disclosure
107107+108108+Skills load in three levels to minimize context cost:
109109+110110+| Level | What loads | When | Budget |
111111+|---|---|---|---|
112112+| 1. Frontmatter | `name` + `description` | Always (system prompt) | ~100 tokens per skill |
113113+| 2. SKILL.md body | Core instructions | Agent triggers the skill | Keep under 500 lines |
114114+| 3. Linked files | references/, scripts/, assets/ | Agent reads explicitly | No cost until accessed |
115115+116116+Practical guidance:
117117+118118+- SKILL.md SHOULD contain only core instructions the agent needs on every invocation
119119+- Move detailed reference material (API specs, long examples, lookup tables) to `references/` and link to them from SKILL.md
120120+- Keep references one level deep from SKILL.md, because agents may partially read or skip deeply nested file trees
121121+- Reference files over 100 lines SHOULD include a table of contents at the top
122122+123123+## 5. Content Guidelines
124124+125125+Default assumption: the agent is already competent. Only add context it does not already have.
126126+127127+- Be specific and actionable. Not _"handle errors appropriately"_ but _"return errors with context using fmt.Errorf"_
128128+- Use examples (input/output pairs) to show expected behavior
129129+- Use RFC 2119 keywords (MUST, SHOULD, MAY) for all constraints
130130+- Negative constraints (MUST NOT, SHOULD NOT) MUST include a reason explaining why
131131+- Use consistent terminology — pick one term and use it throughout
132132+- MUST NOT include time-sensitive information (version numbers, release dates), because skills are not updated on a schedule
133133+134134+### Degree of Freedom
135135+136136+Match instruction specificity to task fragility:
137137+138138+- **High freedom** (prose instructions): when multiple valid approaches exist. _"SHOULD use guard clauses for early returns."_
139139+- **Low freedom** (exact commands/scripts): when operations are fragile or destructive. _"MUST run `pg_dump` before applying migration."_
140140+141141+For critical validations, prefer bundled scripts over prose instructions, because code is deterministic and prose is interpreted.
142142+143143+## 6. Content Patterns
144144+145145+### Template Pattern
146146+147147+Provide output format templates. Mark required vs. optional sections.
148148+149149+```markdown
150150+## Summary
151151+[required — 1-2 sentences]
152152+153153+## Details
154154+[optional — supporting context]
155155+```
156156+157157+### Workflow Pattern
158158+159159+Sequential steps with validation gates.
160160+161161+```
162162+1. Run linter → MUST pass before proceeding
163163+2. Run tests → fix failures, repeat step 1
164164+3. Generate docs → review output
165165+```
241662525-1. WHAT the skill/agent does
2626-2. WHEN to use it
2727-3. Trigger phrases users would say
167167+### Feedback Loop Pattern
281682929-MUST NOT:
169169+```
170170+1. Run validator: `./scripts/validate.sh`
171171+2. If errors, fix and go to step 1
172172+3. If clean, proceed
173173+```
301743131-- Exceed 1024 characters
3232-- Contain XML angle brackets (`<` or `>`) in frontmatter
175175+### Conditional Workflow
331763434-## Directory Structure
177177+Decision trees for different paths:
3517836179```
3737-~/.config/opencode/
3838-├── skills/
3939-│ └── <skill-name>/
4040-│ └── SKILL.md
4141-├── agents/
4242-│ └── <agent-name>.md
180180+If new table → use CREATE TABLE template
181181+If adding column → use ALTER TABLE template with NOT NULL + default
182182+If dropping column → require migration plan review first
43183```
441844545-OR in project root:
185185+### Examples Pattern
186186+187187+Input/output pairs showing expected behavior:
4618847189```
4848-.opencode/
4949-├── skills/<skill-name>/SKILL.md
5050-└── agents/<agent-name>.md
190190+Input: createUser("jane", "admin")
191191+Output: { id: 1, name: "jane", role: "admin", createdAt: "..." }
51192```
521935353-## Frontmatter
194194+## 7. Agents
195195+196196+Agents are standalone `.md` files. The filename determines the agent name (`orchestrator.md` → `orchestrator`).
197197+198198+### Location
199199+200200+- Global: `~/.config/opencode/agents/<name>.md`
201201+- Project: `.opencode/agents/<name>.md`
542025555-### Agents
203203+### Frontmatter
5620457205```yaml
58206---
5959-description: ...
207207+description: Coordinates multi-step tasks by delegating to specialized subagents.
60208mode: primary|subagent
6161-62209permission:
63210 edit: allow|deny|ask
64211 bash:
6565- "*": ask|allow|deny
212212+ "*": ask
66213 "git *": allow
214214+ "npm test": allow
67215 skill:
6868- "*": allow|deny|ask
216216+ "*": allow
69217 task:
7070- "*": allow|deny|ask
218218+ "*": allow
71219---
72220```
732217474-### Skills
222222+| Field | Required | Notes |
223223+|---|---|---|
224224+| `description` | Yes | Same rules as skill descriptions (§3). |
225225+| `mode` | No | `primary` (top-level) or `subagent` (delegated to). |
226226+| `permission` | No | Tool permission overrides. Pattern-matched, most specific wins. |
227227+228228+### Content
752297676-```yaml
7777----
7878-name: skill-name
7979-description: ...
8080----
230230+Agent body defines role, protocol, and constraints. Keep under 100 lines.
231231+232232+```markdown
233233+You are the **Code Reviewer**. You review pull requests for correctness and style.
234234+235235+## Protocol
236236+1. Read the diff
237237+2. Check against project conventions
238238+3. Report issues with file:line references
239239+240240+## Constraints
241241+- MUST NOT suggest style changes that contradict existing patterns
242242+- MUST NOT approve without reading every changed file
81243```
822448383-## Content Guidelines
245245+## 8. Testing
842468585-- Agents: keep under 100 lines
8686-- Skills: keep under 500 lines
8787-- Use RFC 2119 keywords (MUST, SHOULD, MAY) for all constraints
8888-- Negative constraints (MUST NOT, SHOULD NOT) MUST include a reason explaining why.
8989-- NEVER use sycophantic language ("Good call", "Great question", etc.)
9090-- Be direct and concise
247247+### Trigger Testing
912489292-## Trigger Phrases
249249+- Does the skill trigger on direct requests? (_"Create a new skill for..."_)
250250+- Does it trigger on paraphrased requests? (_"I need to set up an agent"_)
251251+- Does it stay silent on unrelated tasks? (_"Fix this CSS bug"_)
932529494-Example triggers for a skill:
253253+### Functional Testing
952549696-- "Create a new agent for..."
9797-- "I need a skill that..."
9898-- "How do I add a new..."
255255+- Does it produce correct output for typical inputs?
256256+- Does error handling work (missing fields, invalid names)?
257257+- Are edge cases covered (empty descriptions, long names)?
99258100100-Example triggers for an agent:
259259+### Iteration
101260102102-- "Use the orchestrator agent"
103103-- "Delegate to subagent"
261261+| Problem | Fix |
262262+|---|---|
263263+| Under-triggering | Add more keywords and trigger phrases to description |
264264+| Over-triggering | Be more specific, add negative triggers |
265265+| Wrong output | Add examples, tighten constraints |
104266105105-## Validation Checklist
267267+Debug with: _"When would you use the [skill name] skill?"_
106268107107-Before committing:
269269+## 9. Validation Checklist
108270109109-- [ ] SKILL.md exists (case-sensitive)
110110-- [ ] Frontmatter has required fields
111111- - Skills: `name` + `description`
112112- - Agents: `description`
113113-- [ ] Name matches folder/filename exactly
114114-- [ ] Description under 1024 characters
115115-- [ ] No XML brackets in frontmatter
116116-- [ ] All constraints use RFC 2119 language (MUST/SHOULD/MAY)
271271+### Skills
117272118118-## Creating a Skill
273273+- [ ] File is named `SKILL.md` (case-sensitive)
274274+- [ ] Folder uses kebab-case
275275+- [ ] Frontmatter has `name` and `description`
276276+- [ ] `name` matches folder name exactly
277277+- [ ] `name` does not contain "claude" or "anthropic"
278278+- [ ] Description is 1-1024 characters
279279+- [ ] Description includes what, when, and trigger keywords
280280+- [ ] Description written in third person
281281+- [ ] No XML angle brackets in frontmatter
282282+- [ ] No README.md in skill folder
283283+- [ ] Body under 500 lines
284284+- [ ] All constraints use RFC 2119 language
285285+- [ ] Negative constraints include a reason
119286120120-1. Create directory: `mkdir -p ~/.config/opencode/skills/<name>`
121121-2. Create SKILL.md with frontmatter
122122-3. Add content following guidelines
123123-4. Validate against checklist
287287+### Agents
288288+289289+- [ ] File uses `.md` extension
290290+- [ ] Frontmatter has `description`
291291+- [ ] Description is 1-1024 characters
292292+- [ ] No XML angle brackets in frontmatter
293293+- [ ] Body under 100 lines
294294+- [ ] `mode` is `primary` or `subagent` (if specified)
295295+- [ ] Permission patterns are valid
124296125125-## Creating an Agent
297297+## 10. Anti-patterns
126298127127-1. Create file: `~/.config/opencode/agents/<name>.md`
128128-2. Add frontmatter with description, mode, permissions
129129-3. Add agent content
130130-4. Validate against checklist
299299+- **Vague descriptions** — _"Helps with projects"_ tells the agent nothing
300300+- **Missing trigger phrases** — skill exists but never fires
301301+- **Deeply nested references** — agents lose track past one level of nesting
302302+- **Too many options without a default** — _"you could use A, B, or C"_ without guidance on which to pick
303303+- **Time-sensitive content** — version numbers and dates go stale silently
304304+- **Inconsistent terminology** — using "skill", "plugin", and "extension" interchangeably
305305+- **Backslash paths** — use forward slashes; backslashes break on Unix systems