Overview
**Writing Skills is applying test-driven development to process documentation. **
Personal skills are located in an agent-specific directory (~/.claude/skillsFor Claude Code,~/.agents/skills/for Codex)
You write test cases (stress scenarios for subagents), watch them fail (baseline behavior), write the skill (documentation), watch the tests pass (the agent complies), and then refactor (close loopholes).
Core principle: If you do not see the agent fail without the skill, you do not know whether the skill taught the right thing.
Required context: Before using this skill, you must understand Superpowers: Test-Driven Development. That skill defines the basic red-green-refactor loop. This skill adapts TDD to documentation.
Official guidance: For Anthropic's official skill creation best practices, see anthropic-best-practices.md. This document provides additional patterns and guidelines to supplement the TDD-centered approach in this skill.
What is a skill?
A skillis a reference guide to a proven technique, pattern, or tool. Skills help future Claude instances find and apply effective methods.
A skill is: A reusable technique, pattern, tool, reference guide
A skill is not: A narrative about how you solved a problem once
TDD Skill Mapping
| TDD Concept | Skill Creation |
|---|---|
| Test case | Stress scenario with a subagent |
| Production code | Skill documentation (SKILL.md) |
| Test fails (red) | The agent violates the rule without the skill (baseline) |
| Test passes (green) | The agent complies with the existing skill |
| Refactor | Close loopholes while maintaining compliance |
| Write the test first | Run the baseline scenario before writing the skill |
| Watch it fail | Document the exact rationalizations used by the agent |
| Minimal code | Write a skill that addresses these specific violations |
| Watch it pass | Verify that the agent now meets the requirements |
| Refactor cycle | Find new rationalizations → block → re-verify |
The entire skill creation process follows red-green-refactor.
When to create a skill
Create when:
- The technique is not intuitively obvious to you
- You can reference it again in the project
- The pattern has broad applicability (not project-specific)
- Others will benefit
Do not create for the following purposes:
- Throwaway solutions
- Standard practices documented in detail elsewhere
- Project-specific conventions (put them in CLAUDE.md)
- Mechanical constraints (if they can be enforced via regular expressions/validation, automate them - save documentation for judgment calls)
Skill types
Technology
Specific methods and steps (condition-based waiting, root cause tracing)
Patterns
Ways of thinking about problems (flattening with markers, testing invariants)
References
API docs, syntax guides, tool docs (office docs)
Directory structure
skills/
skill-name/
SKILL.md # Main reference (required)
supporting-file.* # Only if needed
Flat namespace - All skills are concentrated in one searchable namespace
Separate files:
- Extensive references(100+ lines) - API docs, comprehensive syntax
- Reusable tools - Scripts, utilities, templates
Keep inline:
- Principles and concepts
- Code patterns (< 50 lines)
- Everything else
SKILL.md structure
Frontmatter (YAML):
- Only two fields are supported:
nameanddescription - A maximum of 1024 characters in total
name: Use only letters, numbers, and hyphens (no brackets, special characters)description: Third person, only describe when to use it (not what it does)- Start with "Use when...", focus on trigger conditions
- Include specific symptoms, situations, and contexts
- Never summarize the skill's process or workflow(see the CSO section to understand why)
- Keep it within 500 characters whenever possible
---
name: Skill-Name-With-Hyphens
description: Use when [specific triggering conditions and symptoms]
---
# Skill Name
## Overview
What is this? Core principle in 1-2 sentences.
## When to Use
[Small inline flowchart IF decision non-obvious]
Bullet list with SYMPTOMS and use cases
When NOT to use
## Core Pattern (for techniques/patterns)
Before/after code comparison
## Quick Reference
Table or bullets for scanning common operations
## Implementation
Inline code for simple patterns
Link to file for heavy reference or reusable tools
## Common Mistakes
What goes wrong + fixes
## Real-World Impact (optional)
Concrete results
Claude Search Optimization (CSO)
**The key to discovery:** Future Claude needs to find your skill
1. Rich description field
Purpose: Claude reads descriptions to decide which skills to load for a given task. Make it answer: "Should I read this skill right now?"
Format: Start with "Use when...", focus on trigger conditions
Key: Description = when to use, not what the skill does
The description should only describe trigger conditions. Do not summarize the skill's process or workflow in the description.
Why this matters: Tests show that when a description summarizes a skill's workflow, Claude may follow the description instead of reading the full skill content. Even though the skill's flowchart clearly showed two reviews (spec compliance and then code quality), the description "code review between tasks" caused Claude to perform a single review.
When the description instead became "Use when executing an implementation plan with independent tasks" (without a workflow summary), Claude correctly read the flowchart and followed the two-phase review process.
Pitfall: Descriptions that summarize the workflow create shortcuts that Claude will take. The skill body becomes documentation that Claude skips.
# ❌ BAD: Summarizes workflow - Claude may follow this instead of reading skill
description: Use when executing plans - dispatches subagent per task with code review between tasks
# ❌ BAD: Too much process detail
description: Use for TDD - write test first, watch it fail, write minimal code, refactor
# ✅ GOOD: Just triggering conditions, no workflow summary
description: Use when executing implementation plans with independent tasks in the current session
# ✅ GOOD: Triggering conditions only
description: Use when implementing any feature or bugfix, before writing implementation code
Content:
- Use specific triggers, symptoms, and situations that show when the skill applies
- DescriptionProblem(race conditions, inconsistent behavior) rather thanLanguage-specific symptoms(setTimeout, sleep)
- Keep triggers technology-agnostic unless the skill itself is technology-specific
- If the skill is technology-specific, state that clearly in the trigger
- Write in the third person (injected into the system prompt)
- Never summarize the skill's flow or workflow
# ❌ BAD: Too abstract, vague, doesn't include when to use
description: For async testing
# ❌ BAD: First person
description: I can help you with async tests when they're flaky
# ❌ BAD: Mentions technology but skill isn't specific to it
description: Use when tests use setTimeout/sleep and are flaky
# ✅ GOOD: Starts with "Use when", describes problem, no workflow
description: Use when tests have race conditions, timing dependencies, or pass/fail inconsistently
# ✅ GOOD: Technology-specific skill with explicit trigger
description: Use when using React Router and handling authentication redirects
2. Keyword coverage
Use terms that Claude will search for:
- Error messages: "hook timeout", "ENOTEMPTY", "race condition"
- Symptoms: "flaky", "hangs", "zombie", "pollution"
- Synonyms: "timeout/hang/freeze", "cleanup/teardown/afterEach"
- Tools: actual commands, library names, file types
3. Descriptive naming
Use active voice, verb first:
- ✅
creating-skillsNotskill-creation - ✅
condition-based-waitingNotasync-test-helpers
4. Token efficiency (critical)
**Problem:** Entry points and frequently referenced skills are included in every conversation. Every token matters.
Target word count:
- Entry workflows: each <150 words
- Frequently used skills: total word count <200
- Other skills: <500 words (still be concise)
Techniques:
Move detailed information to tool help:
# ❌ BAD: Document all flags in SKILL.md
search-conversations supports --text, --both, --after DATE, --before DATE, --limit N
# ✅ GOOD: Reference --help
search-conversations supports multiple modes and filters. Run --help for details.
Use cross-references:
# ❌ BAD: Repeat workflow details
When searching, dispatch subagent with template...
[20 lines of repeated instructions]
# ✅ GOOD: Reference other skill
Always use subagents (50-100x context savings). REQUIRED: Use [other-skill-name] for workflow.
Compress examples:
# ❌ BAD: Verbose example (42 words)
your human partner: "How did we handle authentication errors in React Router before?"
You: I'll search past conversations for React Router authentication patterns.
[Dispatch subagent with search query: "React Router authentication error handling 401"]
# ✅ GOOD: Minimal example (20 words)
Partner: "How did we handle auth errors in React Router?"
You: Searching...
[Dispatch subagent → synthesis]
Eliminate redundancy:
- Do not repeat content from cross-referenced skills
- Do not explain what is obvious from the command
- Do not include multiple examples of the same pattern
Confirmation:
wc -w skills/path/SKILL.md
# getting-started workflows: aim for <150 each
# Other frequently-loaded: aim for <200 total
Name it based on what you did or the core insight:
- ✅
condition-based-waiting>async-test-helpers - ✅
using-skillsNotskill-usage - ✅
flatten-with-flags>data-structure-refactoring - ✅
root-cause-tracing>debugging-techniques
Gerunds (-ing) work for processes:
creating-skills,testing-skills,debugging-with-logs- Active, describing the action you are taking
4. Cross-reference other skills
When writing documents that reference other skills:
Use only the skill name, with a clear requirement marker:
- ✅ Good:
**REQUIRED SUB-SKILL:** Use superpowers:test-driven-development - ✅ Good:
**REQUIRED BACKGROUND:** You MUST understand superpowers:systematic-debugging - ❌ Bad:
See skills/testing/test-driven-development(unclear whether it is required) - ❌ Bad:
@skills/testing/test-driven-development/SKILL.md(force load, burns context)
Why no @ link:@The syntax immediately forces loading the file, consuming 200k+ context before they are needed.
Flowchart usage
digraph when_flowchart {
"Need to show information?" [shape=diamond];
"Decision where I might go wrong?" [shape=diamond];
"Use markdown" [shape=box];
"Small inline flowchart" [shape=box];
"Need to show information?" -> "Decision where I might go wrong?" [label="yes"];
"Decision where I might go wrong?" -> "Small inline flowchart" [label="yes"];
"Decision where I might go wrong?" -> "Use markdown" [label="no"];
}
Flowcharts are only used for:
- Non-obvious decision points
- Process loops where you might stop too early
- "When to use A vs B" decisions
Never use flowcharts for:
- Reference material → tables, lists
- Code examples → Markdown blocks
- Linear instructions → numbered lists
- Labels without semantics (step1, helper2)
For graphviz style rules, see @graphviz-conventions.dot.
Visualize for your human partner: Userender-graphs.jsRender the skill flowchart as SVG in this directory:
./render-graphs.js ../some-skill # Each diagram separately
./render-graphs.js ../some-skill --combine # All diagrams in one SVG
Code examples
One excellent example is better than many mediocre examples
Choose the most relevant language:
- Testing techniques → TypeScript/JavaScript
- System debugging → Shell/Python
- Data processing → Python
Good examples:
- Complete and runnable
- Comments are good, explaining why
- From real scenarios
- Clearly show the pattern
- Ready to adapt (not a generic template)
No:
- Implemented in more than 5 languages
- Create fill-in-the-blank templates
- Write artificial examples
You are very good at porting—one good example is enough.
File organization
Self-contained skills
defense-in-depth/
SKILL.md # Everything inline
Timing: everything fits, no need for extensive references
Skills using reusable tools
condition-based-waiting/
SKILL.md # Overview + patterns
example.ts # Working helpers to adapt
When: the tool is reusable code, not just narrative
Skills with extensive references
pptx/
SKILL.md # Overview + workflows
pptxgenjs.md # 600 lines API reference
ooxml.md # 500 lines XML structure
scripts/ # Executable tools
When: the reference material is too large to inline
Iron rule (same as TDD)
NO SKILL WITHOUT A FAILING TEST FIRST
This applies to new skills and edits to existing skills.
Write the skill before testing it? Delete it. Start over. Edit the skill without testing it? Same violation.
No exceptions:
- Not suitable for "simple additions"
- Not for "just adding one section"
- Not applicable to "documentation updates"
- Do not keep untested changes as a "reference"
- Do not "adapt" while running tests
- Deletion is deletion
Required background: Superpowers: Test-Driven Development skills explains why this matters. The same principle also applies to documentation.
Test all skill types
Different skill types require different testing methods:
Discipline enforcement skills (rules/requirements)
Examples: TDD, verification before completion, design before coding
Use tests for:
- Academic questions: do they understand the rules?
- Pressure scenarios: do they comply under pressure?
- Multiple stacked pressures: time + sunk cost + exhaustion
- Identify rationalizations and add explicit counters
Success criteria: The agent follows the rules under maximum pressure
Technical skills (how-to guides)
Examples: Condition-based waiting, root cause tracing, defensive programming
Use tests for:
- Application scenarios: can they apply the technique correctly?
- Variation scenarios: do they handle edge cases?
- Missing information test: are there gaps in the instructions?
Success criteria: The agent successfully applies the technique to new scenarios
Pattern skills (mental models)
Examples: Reducing complexity, information hiding concepts
Use tests for:
- Recognition scenarios: can they recognize when the pattern applies?
- Application scenarios: can they use the mental model?
- Counterexamples: do they know when they should not apply it?
Success criteria: The agent correctly identifies when/how to apply the pattern
Reference skills (documentation/API)
Examples: API documentation, command reference, library guides
Use tests for:
- Retrieval scenarios: can they find the correct information?
- Application scenarios: can they correctly use what they found?
- Gap test: are common use cases covered?
Success criteria: The agent finds and correctly applies the reference information
Common justifications for skipping tests
| Sorry | Reality |
|---|---|
| "Capability is clearly well-defined" | You are clear ≠ other agents are clear. Test it. |
| "This is just a reference" | Reference documents may have blank or unclear parts. Test retrieval. |
| "Testing is overkill" | Untested skills have problems. Always. A 15-minute test can save hours. |
| "I will test whether there is a problem" | Problem = the agent cannot use the skill. Test before deployment. |
| "Testing is too cumbersome" | Testing is much easier than debugging a bad skill in production. |
| "I believe it is good" | Overconfidence leads to problems. Test it anyway. |
| "Academic review is enough" | Reading ≠ using. Test the application scenarios. |
| "There is no time to test" | Deploying an untested skill wastes even more time fixing it. |
**All of this means: test before deployment. No exceptions.**
Bulletproof techniques against rationalization
Skills that enforce discipline (such as TDD) require resisting rationalization. Agents are smart and will find loopholes under pressure.
Psychology note: Understanding why persuasion techniques work can help you apply them systematically. For the research foundation on authority, commitment, scarcity, social proof, and the unity principle (Cialdini, 2021; Meincke et al., 2025), see persuasion-principles.md.
Explicitly close every loophole
Do not just state the rule - prohibit specific workarounds:
<bad>
Write code before test? Delete it.
</bad>
<good>
Write code before test? Delete it. Start over.
**No exceptions:**
- Don't keep it as "reference"
- Don't "adapt" it while writing tests
- Don't look at it
- Delete means delete
</good>
Resolve the "spirit and letter" debate
Add the basic principle early:
**Violating the letter of the rules is violating the spirit of the rules.**
This cuts off the entire class of "I follow the spirit" rationalizations.
Build a rationalization table
Obtain reasonable cases from baseline testing (see the testing section below). Every excuse the agent raises is in the table:
| Excuse | Reality |
|--------|---------|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll test after" | Tests passing immediately prove nothing. |
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
Build a red flag list
Make it easy for agents to self-check when rationalizing:
## Red Flags - STOP and Start Over
- Code before test
- "I already manually tested it"
- "Tests after achieve the same purpose"
- "It's about spirit not ritual"
- "This is different because..."
**All of these mean: Delete code. Start over with TDD.**
Update the CSO's violation symptoms
Add a description: symptoms when you are about to violate the rule:
description: use when implementing any feature or bugfix, before writing implementation code
Skill red-green refactoring
Follow the TDD cycle:
Red: write a failing test (baseline)
Run the stress scenario with a subagent without the skill. Record the exact behavior:
- What choices did they make?
- What rationalizations did they use (verbatim)?
- Which pressures triggered the violation?
This is "observing the test fail" - before writing the skill, you must understand what the agent naturally does.
Green: write the minimal skill
Write a skill that addresses these specific rationalizations. Do not add extra content for hypothetical cases.
Run the same scenario using the skill. The agent should now comply.
Refactor: close the loopholes
The agent found a new rationalization? Add an explicit counter. Retest until bulletproof.
Testing methods: See @testing-skills-with-subagents.md for the complete testing methodology:
- How to write pressure scenarios
- Pressure types (time, sunk cost, authority, exhaustion)
- Systematically plug loopholes
- Meta-testing techniques
Anti-patterns
❌ Narrative examples
"In the 2025-10-03 session, we found that an empty projectDir caused..." Why it's bad: Too specific, not reusable
❌ Multilingual dilution
example-js.js、example-py.py、example-go.go Why it's bad: Mediocre quality, heavy maintenance burden
❌ Code in flowcharts
step1 [label="import fs"];
step2 [label="read file"];
Why it's bad: Cannot copy and paste, hard to read
❌ Generic labels
Assistant 1, Assistant 2, Step 3, Pattern 4 Why it's bad: Labels should have semantic meaning
STOP: Before moving to the next skill
**After writing any skill, you must stop and complete the deployment process. **
Do not:
- Batch-create multiple skills without testing each skill
- Move to the next skill before validating the current skill
- Skip testing because "batching is more efficient"
**The deployment checklist below is mandatory for every skill. **
Deploying an untested skill = deploying untested code. This violates quality standards.
Skill creation checklist (TDD adaptation)
**Important: Use TodoWrite to create a todo for each checklist item below. **
RED phase - Write a failing test:
- Create pressure scenarios (3+ combined pressures for discipline skills)
- Run the scenario without the skill - record baseline behavior verbatim
- Identify rationalization/failure patterns
GREEN phase - Write the minimal skill:
- Name uses only letters, numbers, hyphens (no brackets/special characters)
- YAML frontmatter contains only name and description (max 1024 characters)
- Description starts with "When to use" and includes specific triggers/symptoms
- Description written in third person
- Search keywords (errors, symptoms, tools)
- Clear overview and core principles
- Address the specific baseline failures identified in RED
- Code inline or linked to a separate file
- One good example (not multilingual)
- Run the scenario with the skill - verify whether the agent now complies
REFACTOR phase - Plug loopholes:
- Identify new rationalizations from testing
- Add explicit counters (if it is a discipline skill)
- Iteratively build a rationalization table based on all tests
- Build a red flags list
- Retest until bulletproof
Quality check:
- Use a small flowchart only when the decision is not obvious
- Quick reference table
- Common mistakes section
- No storytelling
- Supporting documents only for tools or extensive reference
Deployment:
- Commit the skill to git and push to your fork (if configured)
- Consider contributing via a PR (if broadly useful)
Discovery workflow
How future Claude finds your skill:
- Encounters problem("tests are flaky")
- Finds skill(description matches)
- Scans overview(is this relevant?)
- Reads pattern(quick reference table)
- Loads example(only when implementing)
Optimize for this flow - put searchable terms early and often.
The bottom line
**Creating skills is TDD for process documentation.**
Same iron law: no skill without a failing test first. Same cycle: RED (baseline) → GREEN (write skill) → REFACTOR (close loopholes). Same benefits: better quality, fewer surprises, bulletproof results.
If you follow TDD for code, follow it for skills. It's the same rule applied to documentation.