# Writing Skills (TDD for Process Documentation)
<!--
ref: @skills/writing-skills
tags: [skills, meta, authoring, testing, discipline, prompt-engineering]
triggers: [creating new skill, editing skill, skill not triggering, agent ignores skill, agent rationalizes around rule, writing agent guidance]
trigger_prompt: Use when creating or editing agent skills/protocols/guidance docs, or when agents comply with a rule's description but violate its body.
category: meta
version: 1
updated_at: 2026-07-11T14:24:47.033Z
-->

Writing skills is Test-Driven Development applied to process documentation: write test cases (pressure scenarios run by fresh subagents), watch them fail (baseline behavior without the skill), write the skill, watch the tests pass (agents comply), then refactor (close loopholes).

**Core principle:** without watching an agent fail *without* the skill, there is no evidence the skill teaches the right thing.

**The Iron Law (same as TDD):** no skill without a failing test first — for new skills *and* edits. A skill written before testing gets deleted and rewritten.

## TDD mapping

| TDD concept | Skill creation |
|-------------|----------------|
| Test case | Pressure scenario with a subagent |
| Test fails (RED) | Agent violates the rule without the skill (baseline) |
| Test passes (GREEN) | Agent complies with the skill present |
| Refactor | Close loopholes while maintaining compliance |
| Watch it fail | Document the agent's exact rationalizations, verbatim |
| Minimal code | Write the skill addressing those specific violations only |

## When to create a skill

Create when the technique wasn't intuitively obvious, would be referenced again across projects, and applies broadly. Don't create for one-off solutions, standard practices documented elsewhere, project-specific conventions, or mechanical constraints (if regex/validation can enforce it, automate it — save documentation for judgment calls).

## The description is the highest-leverage line

The description (trigger) answers one question: *"should I read this right now?"* It states triggering conditions — concrete symptoms, situations, contexts — and **never summarizes the skill's workflow**.

Why: in testing, when a description summarized the workflow ("code review between tasks"), agents followed the description's summary instead of reading the body — doing one review where the body required two. With triggering conditions only, agents read the body and complied. A workflow summary in the description is a shortcut agents will take; the body becomes documentation agents skip.

- Bad: `Use when executing plans — dispatches subagent per task with code review between tasks`
- Good: `Use when executing implementation plans with independent tasks in the current session`

Describe the *problem* (race conditions, flaky tests), not language-specific symptoms; keep triggers technology-agnostic unless the skill is technology-specific; include error messages, symptoms, and synonyms an agent would search for.

## Match the form to the failure

Classify the baseline failure before writing guidance — the form that bulletproofs one failure type measurably backfires on another:

| Baseline failure | Right form | Wrong form |
|---|---|---|
| Skips/violates a rule under pressure (knows better, does it anyway) | Prohibition + rationalization table + red flags | Soft guidance ("prefer…", "consider…") |
| Complies, but output has the wrong shape | Positive recipe/contract: state what the output IS — its parts, in order | Prohibition list ("don't restate", "never narrate") |
| Omits a required element from output it already produces | Structural: a REQUIRED field or slot in the template | Prose reminders near the template |
| Behavior should depend on a condition | Conditional keyed to an observable predicate | Unconditional rule + exemption clauses |

Prohibitions backfire on shaping problems: under a competing incentive, agents negotiate with "don't X" — in head-to-head wording tests, the prohibition arm produced *more* of the unwanted content than a no-guidance control. A recipe leaves nothing to negotiate.

Two wording rules regardless of form: **no nuance clauses** ("don't X unless it matters" reopens the negotiation — express real exceptions as their own conditional on an observable predicate), and **exemption clauses don't scope** ("this limit doesn't apply to code blocks" still suppresses code blocks — restructure so the rule can't reach the exempt part).

## Bulletproofing discipline skills

For rules agents skip under pressure:

1. **Close every loophole explicitly.** Not just "delete it" but: don't keep it as reference, don't adapt it, don't look at it — delete means delete.
2. **Cut off spirit-vs-letter arguments early:** "Violating the letter of the rules is violating the spirit of the rules."
3. **Build a rationalization table** from baseline testing — every excuse an agent actually made, paired with the reality.
4. **Add a red-flags list** — the exact phrases an agent about to violate the rule says to itself, so it can self-check.

## Testing by skill type

- **Discipline skills** (rules): pressure scenarios with 3+ combined pressures (time, sunk cost, authority, exhaustion). Success = compliance under maximum pressure.
- **Technique skills** (how-to): application scenarios, edge-case variations, gap-hunting for missing instructions. Success = correct application to a new scenario.
- **Pattern skills** (mental models): recognition scenarios plus counter-examples (knowing when NOT to apply). 
- **Reference skills** (APIs/docs): retrieval scenarios — can the agent find and correctly apply the information?

## Micro-test wording before full scenarios

Full pressure-scenario runs are the final gate but slow per iteration. Verify wording first:

1. One fresh-context sample per call; system prompt = the realistic context the guidance will live in; user message = a task that tempts the failure.
2. **Always include a no-guidance control.** If the control doesn't exhibit the failure, there's nothing to fix — stop.
3. 5+ reps per variant; single samples lie.
4. Manually read every flagged match — template echoes and quoted counter-examples masquerade as hits.
5. **Variance is a metric:** reps converging on the same shape means the wording binds; five different interpretations means tighten the form before adding words.

## Craft rules

- Third-person descriptions; name skills verb-first/gerund by what you DO (`condition-based-waiting`, not `async-test-helpers`).
- One excellent, runnable, commented example beats many mediocre ones; don't port to 5 languages.
- Token efficiency: frequently-loaded content <200 words; move flag documentation to `--help`; cross-reference instead of repeating; compress examples.
- Flowcharts only for non-obvious decision points — never for reference material, code, or linear instructions.
- Separate files only for heavy reference (100+ lines) or reusable tools; keep principles and short patterns inline.
- Test each skill before writing the next; batch-creating untested skills is deploying untested code.

## Common rationalizations for skipping testing

| Excuse | Reality |
|--------|---------|
| "The skill is obviously clear" | Clear to the author ≠ clear to other agents |
| "It's just a reference" | References have gaps — test retrieval |
| "I'll test if problems emerge" | Problems = agents already couldn't use it |
| "Academic review is enough" | Reading ≠ using — test application |
| "No time to test" | An untested skill costs more to fix in production |

---

**Source:** [writing-skills](https://github.com/obra/superpowers/blob/main/skills/writing-skills/SKILL.md) — Superpowers by Jesse Vincent (obra), MIT. Bundled `testing-skills-with-subagents.md` (pressure-scenario methodology), `persuasion-principles.md` (research foundation), `anthropic-best-practices.md`, and `graphviz-conventions.dot` listed-and-linked at source, not harvested.
**Converted via:** `@protocol/skill-to-protocol`

---

*Related: `@protocol/groom-protocols` · `@content/web/github/2026-11-25-claude-code-v2-1-332` · `@content/web/github/2026-11-24-builtin-ship-shadows-user-skill` · `@content/web/github/2026-11-17-open-artifact` · `@content/youtube/yifan-bth/the-openclaw-security-settings-i-actually-change`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*