1
---
2
name: writing-skills
3
description: Use when creating new skills, editing existing skills, or verifying skills work before deployment
4
---
5
6
# Writing Skills
7
8
## Overview
9
10
**Writing skills IS Test-Driven Development applied to process documentation.**
11
12
**Personal skills live in your runtime's skills directory** (`~/.claude/skills/` on Claude Code) — see [codex-tools.md](../using-superpowers/references/codex-tools.md) or [gemini-tools.md](../using-superpowers/references/gemini-tools.md) for the path on those runtimes. Codex, Copilot CLI, and Gemini CLI all also recognize `~/.agents/skills/` as a cross-runtime alias.
13
14
You write test cases (pressure scenarios with subagents), watch them fail (baseline behavior), write the skill (documentation), watch tests pass (agents comply), and refactor (close loopholes).
15
16
**Core principle:** If you didn't watch an agent fail without the skill, you don't know if the skill teaches the right thing.
17
18
**REQUIRED BACKGROUND:** You MUST understand superpowers:test-driven-development before using this skill. That skill defines the fundamental RED-GREEN-REFACTOR cycle. This skill adapts TDD to documentation.
19
20
**Official guidance:** For Anthropic's official skill authoring best practices, see references/anthropic-best-practices.md. This document provides additional patterns and guidelines that complement the TDD-focused approach in this skill.
21
22
## What is a Skill?
23
24
A **skill** is a reference guide for proven techniques, patterns, or tools. Skills help future agents find and apply effective approaches.
25
26
**Skills are:** Reusable techniques, patterns, tools, reference guides
27
28
**Skills are NOT:** Narratives about how you solved a problem once
29
30
## TDD Mapping for Skills
31
32
| TDD Concept | Skill Creation |
33
|-------------|----------------|
34
| **Test case** | Pressure scenario with subagent |
35
| **Production code** | Skill document (SKILL.md) |
36
| **Test fails (RED)** | Agent violates rule without skill (baseline) |
37
| **Test passes (GREEN)** | Agent complies with skill present |
38
| **Refactor** | Close loopholes while maintaining compliance |
39
| **Write test first** | Run baseline scenario BEFORE writing skill |
40
| **Watch it fail** | Document exact rationalizations agent uses |
41
| **Minimal code** | Write skill addressing those specific violations |
42
| **Watch it pass** | Verify agent now complies |
43
| **Refactor cycle** | Find new rationalizations → plug → re-verify |
44
45
The entire skill creation process follows RED-GREEN-REFACTOR.
46
47
## When to Create a Skill
48
49
**Create when:**
50
- Technique wasn't intuitively obvious to you
51
- You'd reference this again across projects
52
- Pattern applies broadly (not project-specific)
53
- Others would benefit
54
55
**Don't create for:**
56
- One-off solutions
57
- Standard practices well-documented elsewhere
58
- Project-specific conventions (put in your instructions file)
59
- Mechanical constraints (if it's enforceable with regex/validation, automate it—save documentation for judgment calls)
60
61
## Skill Types
62
63
### Technique
64
Concrete method with steps to follow (condition-based-waiting, root-cause-tracing)
65
66
### Pattern
67
Way of thinking about problems (flatten-with-flags, test-invariants)
68
69
### Reference
70
API docs, syntax guides, tool documentation (office docs)
71
72
## Directory Structure
73
74
75
```
76
skills/
77
skill-name/
78
SKILL.md # Main reference (required)
79
supporting-file.* # Only if needed
80
```
81
82
**Flat namespace** - all skills in one searchable namespace
83
84
**Separate files for:**
85
1. **Heavy reference** (100+ lines) - API docs, comprehensive syntax
86
2. **Reusable tools** - Scripts, utilities, templates
87
88
**Keep inline:**
89
- Principles and concepts
90
- Code patterns (< 50 lines)
91
- Everything else
92
93
## Writing SKILL.md
94
95
A skill's `description` says only when to use it: triggering conditions and
96
symptoms, starting with "Use when...". It never summarizes the skill's
97
workflow, because an agent that reads a workflow summary follows it instead
98
of reading the skill.
99
100
When you write or change a skill's frontmatter, name or description, or
101
need to cut its size, read [references/discovery.md](references/discovery.md):
102
the SKILL.md template, description and keyword guidance, naming, token
103
budgets, and cross-referencing other skills.
104
105
## Flowcharts
106
107
When you add or change a flowchart in a skill, read
108
[references/flowcharts.md](references/flowcharts.md) first: when a flowchart
109
earns its place, the graphviz conventions, and how to render one.
110
111
## Code Examples
112
113
**One excellent example beats many mediocre ones**
114
115
Choose most relevant language:
116
- Testing techniques → TypeScript/JavaScript
117
- System debugging → Shell/Python
118
- Data processing → Python
119
120
**Good example:**
121
- Complete and runnable
122
- Well-commented explaining WHY
123
- From real scenario
124
- Shows pattern clearly
125
- Ready to adapt (not generic template)
126
127
**Don't:**
128
- Implement in 5+ languages
129
- Create fill-in-the-blank templates
130
- Write contrived examples
131
132
You're good at porting - one great example is enough.
133
134
## File Organization
135
136
### Self-Contained Skill
137
```
138
defense-in-depth/
139
SKILL.md # Everything inline
140
```
141
When: All content fits, no heavy reference needed
142
143
### Skill with Reusable Tool
144
```
145
condition-based-waiting/
146
SKILL.md # Overview + patterns
147
example.ts # Working helpers to adapt
148
```
149
When: Tool is reusable code, not just narrative
150
151
### Skill with Heavy Reference
152
```
153
pptx/
154
SKILL.md # Overview + workflows
155
pptxgenjs.md # 600 lines API reference
156
ooxml.md # 500 lines XML structure
157
scripts/ # Executable tools
158
```
159
When: Reference material too large for inline
160
161
Invoke bundled scripts through their interpreter in the prose (`bash scripts/tool.sh`, `node scripts/tool.js`), never by bare path: some harness plugin packagers strip executable bits, and a bare `scripts/tool.sh` fails there with `Permission denied`.
162
163
## The Iron Law (Same as TDD)
164
165
```
166
NO SKILL WITHOUT A FAILING TEST FIRST
167
```
168
169
This applies to NEW skills AND EDITS to existing skills.
170
171
Write skill before testing? Delete it. Start over.
172
Edit skill without testing? Same violation.
173
174
**No exceptions:**
175
- Not for "simple additions"
176
- Not for "just adding a section"
177
- Not for "documentation updates"
178
- Don't keep untested changes as "reference"
179
- Don't "adapt" while running tests
180
- Delete means delete
181
182
**REQUIRED BACKGROUND:** The superpowers:test-driven-development skill explains why this matters. Same principles apply to documentation.
183
184
## Testing All Skill Types
185
186
Different skill types need different test approaches:
187
188
### Discipline-Enforcing Skills (rules/requirements)
189
190
**Examples:** TDD, verification-before-completion, designing-before-coding
191
192
**Test with:**
193
- Academic questions: Do they understand the rules?
194
- Pressure scenarios: Do they comply under stress?
195
- Multiple pressures combined: time + sunk cost + exhaustion
196
- Identify rationalizations and add explicit counters
197
198
**Success criteria:** Agent follows rule under maximum pressure
199
200
### Technique Skills (how-to guides)
201
202
**Examples:** condition-based-waiting, root-cause-tracing, defensive-programming
203
204
**Test with:**
205
- Application scenarios: Can they apply the technique correctly?
206
- Variation scenarios: Do they handle edge cases?
207
- Missing information tests: Do instructions have gaps?
208
209
**Success criteria:** Agent successfully applies technique to new scenario
210
211
### Pattern Skills (mental models)
212
213
**Examples:** reducing-complexity, information-hiding concepts
214
215
**Test with:**
216
- Recognition scenarios: Do they recognize when pattern applies?
217
- Application scenarios: Can they use the mental model?
218
- Counter-examples: Do they know when NOT to apply?
219
220
**Success criteria:** Agent correctly identifies when/how to apply pattern
221
222
### Reference Skills (documentation/APIs)
223
224
**Examples:** API documentation, command references, library guides
225
226
**Test with:**
227
- Retrieval scenarios: Can they find the right information?
228
- Application scenarios: Can they use what they found correctly?
229
- Gap testing: Are common use cases covered?
230
231
**Success criteria:** Agent finds and correctly applies reference information
232
233
## Common Rationalizations for Skipping Testing
234
235
| Excuse | Reality |
236
|--------|---------|
237
| "Skill is obviously clear" | Clear to you ≠ clear to other agents. Test it. |
238
| "It's just a reference" | References can have gaps, unclear sections. Test retrieval. |
239
| "Testing is overkill" | Untested skills have issues. Always. 15 min testing saves hours. |
240
| "I'll test if problems emerge" | Problems = agents can't use skill. Test BEFORE deploying. |
241
| "Too tedious to test" | Testing is less tedious than debugging bad skill in production. |
242
| "I'm confident it's good" | Overconfidence guarantees issues. Test anyway. |
243
| "Academic review is enough" | Reading ≠ using. Test application scenarios. |
244
| "No time to test" | Deploying untested skill wastes more time fixing it later. |
245
246
**All of these mean: Test before deploying. No exceptions.**
247
248
## Match the Form to the Failure
249
250
Before writing guidance, classify the baseline failure. The form that bulletproofs one failure type measurably backfires on another.
251
252
| Baseline failure | Right form | Wrong form |
253
|---|---|---|
254
| Skips/violates a rule under pressure (knows better, does it anyway) | Prohibition + rationalization table + red flags (see references/bulletproofing.md) | Soft guidance ("prefer...", "consider...") |
255
| Complies, but output has the wrong shape (bloated prompt, buried verdict, restated spec) | Positive recipe or contract: state what the output IS — its parts, in order | Prohibition list ("don't restate", "never narrate") |
256
| Omits a required element from something they already produce | Structural: REQUIRED field or slot in the template they fill in | Prose reminders near the template |
257
| Behavior should depend on a condition | Conditional keyed to an observable predicate ("if the brief exists, reference it") | Unconditional rule + exemption clauses |
258
259
**Why prohibitions backfire on shaping problems:** under a competing incentive ("make the prompt self-contained"), agents negotiate with "don't X". In head-to-head wording tests on dispatch-prompt guidance, the prohibition arm produced clearly more of the unwanted content than the recipe arm (fully separated distributions), and trended worse than even the no-guidance control — micro-test your own case rather than assuming, but never reach for the prohibition by default. A recipe leaves nothing to negotiate: the output matches the stated shape or it doesn't.
260
261
**Rules for whichever form you pick:**
262
- **No nuance clauses.** "Don't X unless it matters" reopens the negotiation — appending a single nuance clause to a winning recipe degraded it from consistent to noisy in the same wording tests. Express a real exception as its own conditional on an observable predicate.
263
- **Exemption clauses don't scope.** "This limit doesn't apply to code blocks" still suppresses code blocks. If part of the output must be exempt, restructure so the rule can't reach it.
264
265
## Bulletproofing Against Rationalization
266
267
When the baseline failure is a discipline failure, read
268
[references/bulletproofing.md](references/bulletproofing.md) before you write
269
the guidance: closing loopholes, the spirit-vs-letter line, the
270
rationalization table, and the red-flags list.
271
272
## RED-GREEN-REFACTOR for Skills
273
274
Follow the TDD cycle:
275
276
### RED: Write Failing Test (Baseline)
277
278
Run pressure scenario with subagent WITHOUT the skill. Document exact behavior:
279
- What choices did they make?
280
- What rationalizations did they use (verbatim)?
281
- Which pressures triggered violations?
282
283
This is "watch the test fail" - you must see what agents naturally do before writing the skill.
284
285
### GREEN: Write Minimal Skill
286
287
Write skill that addresses those specific rationalizations. Don't add extra content for hypothetical cases.
288
289
Run same scenarios WITH skill. Agent should now comply.
290
291
### REFACTOR: Close Loopholes
292
293
Agent found new rationalization? Add explicit counter. Re-test until bulletproof.
294
295
### Micro-Test Wording Before Full Scenarios
296
297
Full pressure-scenario runs are the final gate, but they are slow and expensive per iteration. Verify the wording itself first with micro-tests:
298
299
1. **One fresh-context sample per call** — a raw API call, or a single-shot subagent if you don't have API access. System prompt = the realistic context the guidance will live in (the full skill or prompt template, not the guidance in isolation); user message = a task that tempts the failure.
300
2. **Always include a no-guidance control.** If the control doesn't exhibit the failure, there is nothing to fix — stop, don't author the guidance.
301
3. **5+ reps per variant.** Single samples lie.
302
4. **Manually read every flagged match.** Score programmatically if you like, but template echoes and quoted counter-examples masquerade as hits; automated counts alone overstate both failure and success.
303
5. **Variance is a metric.** When guidance lands, reps converge on the same shape. Five different interpretations across five reps means the wording isn't binding — tighten the form before adding words.
304
305
Micro-tests verify wording; they do not replace pressure scenarios for discipline skills.
306
307
**Testing methodology:** See [references/testing-skills-with-subagents.md](references/testing-skills-with-subagents.md) for the complete testing methodology:
308
- How to write pressure scenarios
309
- Pressure types (time, sunk cost, authority, exhaustion)
310
- Plugging holes systematically
311
- Meta-testing techniques
312
313
## Anti-Patterns
314
315
### ❌ Narrative Example
316
"In session 2025-10-03, we found empty projectDir caused..."
317
**Why bad:** Too specific, not reusable
318
319
### ❌ Multi-Language Dilution
320
example-js.js, example-py.py, example-go.go
321
**Why bad:** Mediocre quality, maintenance burden
322
323
### ❌ Code in Flowcharts
324
```dot
325
step1 [label="import fs"];
326
step2 [label="read file"];
327
```
328
**Why bad:** Can't copy-paste, hard to read
329
330
### ❌ Generic Labels
331
helper1, helper2, step3, pattern4
332
**Why bad:** Labels should have semantic meaning
333
334
## STOP: Before Moving to Next Skill
335
336
**After writing ANY skill, you MUST STOP and complete the deployment process.**
337
338
**Do NOT:**
339
- Create multiple skills in batch without testing each
340
- Move to next skill before current one is verified
341
- Skip testing because "batching is more efficient"
342
343
**The deployment checklist below is MANDATORY for EACH skill.**
344
345
Deploying untested skills = deploying untested code. It's a violation of quality standards.
346
347
## Skill Creation Checklist (TDD Adapted)
348
349
**IMPORTANT: Create a todo for EACH checklist item below.**
350
351
**RED Phase - Write Failing Test:**
352
- [ ] Create pressure scenarios (3+ combined pressures for discipline skills)
353
- [ ] Run scenarios WITHOUT skill - document baseline behavior verbatim
354
- [ ] Identify patterns in rationalizations/failures
355
356
**GREEN Phase - Write Minimal Skill:**
357
- [ ] Name uses only letters, numbers, hyphens (no parentheses/special chars)
358
- [ ] YAML frontmatter with required `name` and `description` fields (max 1024 chars; see [spec](https://agentskills.io/specification))
359
- [ ] Description starts with "Use when..." and includes specific triggers/symptoms
360
- [ ] Description written in third person
361
- [ ] Keywords throughout for search (errors, symptoms, tools)
362
- [ ] Clear overview with core principle
363
- [ ] Address specific baseline failures identified in RED
364
- [ ] Guidance form matches the failure type (see Match the Form to the Failure)
365
- [ ] For behavior-shaping guidance: wording micro-tested against a no-guidance control (5+ reps, every flagged match read manually) — N/A for pure reference skills
366
- [ ] Code inline OR link to separate file
367
- [ ] One excellent example (not multi-language)
368
- [ ] Run scenarios WITH skill - verify agents now comply
369
370
**REFACTOR Phase - Close Loopholes:**
371
- [ ] Identify NEW rationalizations from testing
372
- [ ] Add explicit counters (if discipline skill)
373
- [ ] Build rationalization table from all test iterations
374
- [ ] Create red flags list
375
- [ ] Re-test until bulletproof
376
377
**Quality Checks:**
378
- [ ] Small flowchart only if decision non-obvious
379
- [ ] Quick reference table
380
- [ ] Common mistakes section
381
- [ ] No narrative storytelling
382
- [ ] Supporting files only for tools or heavy reference
383
384
**Deployment:**
385
- [ ] Commit skill to git and push to your fork (if configured)
386
- [ ] Consider contributing back via PR (if broadly useful)
387
388
## Discovery Workflow
389
390
How future agents find your skill:
391
392
1. **Encounters problem** ("tests are flaky")
393
2. **Searches skills** (greps descriptions, browses categories)
394
3. **Finds SKILL** (description matches)
395
4. **Scans overview** (is this relevant?)
396
5. **Reads patterns** (quick reference table)
397
6. **Loads example** (only when implementing)
398
399
**Optimize for this flow** - put searchable terms early and often.
400