Writing Skills
Overview
Writing skills IS Test-Driven Development applied to process documentation.
Personal skills live in agent-specific directories (~/.claude/skills for Claude Code, ~/.codex/skills for Codex)
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).
Core principle: If you didn't watch an agent fail without the skill, you don't know if the skill teaches the right thing.
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.
Official guidance: For Anthropic's official skill authoring best practices, see anthropic-best-practices.md. This document provides additional patterns and guidelines that complement the TDD-focused approach in this skill.
What is a Skill?
A skill is a reference guide for proven techniques, patterns, or tools. Skills help future Claude instances find and apply effective approaches.
Skills are: Reusable techniques, patterns, tools, reference guides
Skills are NOT: Narratives about how you solved a problem once
TDD Mapping for Skills
| TDD Concept | Skill Creation |
|---|
| Test case | Pressure scenario with subagent |
| Production code |
Skill document (SKILL.md) |
|
Test fails (RED) | Agent violates rule without skill (baseline) |
|
Test passes (GREEN) | Agent complies with skill present |
|
Refactor | Close loopholes while maintaining compliance |
|
Write test first | Run baseline scenario BEFORE writing skill |
|
Watch it fail | Document exact rationalizations agent uses |
|
Minimal code | Write skill addressing those specific violations |
|
Watch it pass | Verify agent now complies |
|
Refactor cycle | Find new rationalizations → plug → re-verify |
The entire skill creation process follows RED-GREEN-REFACTOR.
When to Create a Skill
Create when:
- - Technique wasn't intuitively obvious to you
- You'd reference this again across projects
- Pattern applies broadly (not project-specific)
- Others would benefit
Don't create for:
- - One-off solutions
- Standard practices well-documented elsewhere
- Project-specific conventions (put in CLAUDE.md)
- Mechanical constraints (if it's enforceable with regex/validation, automate it—save documentation for judgment calls)
Skill Types
Technique
Concrete method with steps to follow (condition-based-waiting, root-cause-tracing)
Pattern
Way of thinking about problems (flatten-with-flags, test-invariants)
Reference
API docs, syntax guides, tool documentation (office docs)
Directory Structure
CODEBLOCK0
Flat namespace - all skills in one searchable namespace
Separate files for:
- 1. Heavy reference (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 supported:
name and INLINECODE3 - Max 1024 characters total
- INLINECODE4 : Use letters, numbers, and hyphens only (no parentheses, special chars)
- INLINECODE5 : Third-person, describes ONLY when to use (NOT what it does)
- Start with "Use when..." to focus on triggering conditions
- Include specific symptoms, situations, and contexts
-
NEVER summarize the skill's process or workflow (see CSO section for why)
- Keep under 500 characters if possible
CODEBLOCK1
Claude Search Optimization (CSO)
Critical for discovery: Future Claude needs to FIND your skill
1. Rich Description Field
Purpose: Claude reads description 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..." to focus on triggering conditions
CRITICAL: Description = When to Use, NOT What the Skill Does
The description should ONLY describe triggering conditions. Do NOT summarize the skill's process or workflow in the description.
Why this matters: Testing revealed that when a description summarizes the skill's workflow, Claude may follow the description instead of reading the full skill content. A description saying "code review between tasks" caused Claude to do ONE review, even though the skill's flowchart clearly showed TWO reviews (spec compliance then code quality).
When the description was changed to just "Use when executing implementation plans with independent tasks" (no workflow summary), Claude correctly read the flowchart and followed the two-stage review process.
The trap: Descriptions that summarize workflow create a shortcut Claude will take. The skill body becomes documentation Claude skips.
CODEBLOCK2
Content:
- - Use concrete triggers, symptoms, and situations that signal this skill applies
- Describe the problem (race conditions, inconsistent behavior) not language-specific symptoms (setTimeout, sleep)
- Keep triggers technology-agnostic unless the skill itself is technology-specific
- If skill is technology-specific, make that explicit in the trigger
- Write in third person (injected into system prompt)
- NEVER summarize the skill's process or workflow
CODEBLOCK3
2. Keyword Coverage
Use words Claude would search for:
- - Error messages: "Hook timed out", "ENOTEMPTY", "race condition"
- Symptoms: "flaky", "hanging", "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-skills not INLINECODE7 - ✅
condition-based-waiting not INLINECODE9
4. Token Efficiency (Critical)
Problem: getting-started and frequently-referenced skills load into EVERY conversation. Every token counts.
Target word counts:
- - getting-started workflows: <150 words each
- Frequently-loaded skills: <200 words total
- Other skills: <500 words (still be concise)
Techniques:
Move details to tool help:
CODEBLOCK4
Use cross-references:
CODEBLOCK5
Compress examples:
CODEBLOCK6
Eliminate redundancy:
- - Don't repeat what's in cross-referenced skills
- Don't explain what's obvious from command
- Don't include multiple examples of same pattern
Verification:
CODEBLOCK7
Name by what you DO or core insight:
- - ✅
condition-based-waiting > INLINECODE11 - ✅
using-skills not INLINECODE13 - ✅
flatten-with-flags > INLINECODE15 - ✅
root-cause-tracing > INLINECODE17
Gerunds (-ing) work well for processes:
- -
creating-skills, testing-skills, INLINECODE20 - Active, describes the action you're taking
4. Cross-Referencing Other Skills
When writing documentation that references other skills:
Use skill name only, with explicit requirement markers:
- - ✅ Good: INLINECODE21
- ✅ Good: INLINECODE22
- ❌ Bad:
See skills/testing/test-driven-development (unclear if required) - ❌ Bad:
@skills/testing/test-driven-development/SKILL.md (force-loads, burns context)
Why no @ links: @ syntax force-loads files immediately, consuming 200k+ context before you need them.
Flowchart Usage
CODEBLOCK8
Use flowcharts ONLY 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 semantic meaning (step1, helper2)
See @graphviz-conventions.dot for graphviz style rules.
Visualizing for your human partner: Use render-graphs.js in this directory to render a skill's flowcharts to SVG:
CODEBLOCK9
Code Examples
One excellent example beats many mediocre ones
Choose most relevant language:
- - Testing techniques → TypeScript/JavaScript
- System debugging → Shell/Python
- Data processing → Python
Good example:
- - Complete and runnable
- Well-commented explaining WHY
- From real scenario
- Shows pattern clearly
- Ready to adapt (not generic template)
Don't:
- - Implement in 5+ languages
- Create fill-in-the-blank templates
- Write contrived examples
You're good at porting - one great example is enough.
File Organization
Self-Contained Skill
defense-in-depth/
SKILL.md # Everything inline
When: All content fits, no heavy reference needed
Skill with Reusable Tool
condition-based-waiting/
SKILL.md # Overview + patterns
example.ts # Working helpers to adapt
When: Tool is reusable code, not just narrative
Skill with Heavy Reference
pptx/
SKILL.md # Overview + workflows
pptxgenjs.md # 600 lines API reference
ooxml.md # 500 lines XML structure
scripts/ # Executable tools
When: Reference material too large for inline
The Iron Law (Same as TDD)
CODEBLOCK13
This applies to NEW skills AND EDITS to existing skills.
Write skill before testing? Delete it. Start over.
Edit skill without testing? Same violation.
No exceptions:
- - Not for "simple additions"
- Not for "just adding a section"
- Not for "documentation updates"
- Don't keep untested changes as "reference"
- Don't "adapt" while running tests
- Delete means delete
REQUIRED BACKGROUND: The superpowers:test-driven-development skill explains why this matters. Same principles apply to documentation.
Testing All Skill Types
Different skill types need different test approaches:
Discipline-Enforcing Skills (rules/requirements)
Examples: TDD, verification-before-completion, designing-before-coding
Test with:
- - Academic questions: Do they understand the rules?
- Pressure scenarios: Do they comply under stress?
- Multiple pressures combined: time + sunk cost + exhaustion
- Identify rationalizations and add explicit counters
Success criteria: Agent follows rule under maximum pressure
Technique Skills (how-to guides)
Examples: condition-based-waiting, root-cause-tracing, defensive-programming
Test with:
- - Application scenarios: Can they apply the technique correctly?
- Variation scenarios: Do they handle edge cases?
- Missing information tests: Do instructions have gaps?
Success criteria: Agent successfully applies technique to new scenario
Pattern Skills (mental models)
Examples: reducing-complexity, information-hiding concepts
Test with:
- - Recognition scenarios: Do they recognize when pattern applies?
- Application scenarios: Can they use the mental model?
- Counter-examples: Do they know when NOT to apply?
Success criteria: Agent correctly identifies when/how to apply pattern
Reference Skills (documentation/APIs)
Examples: API documentation, command references, library guides
Test with:
- - Retrieval scenarios: Can they find the right information?
- Application scenarios: Can they use what they found correctly?
- Gap testing: Are common use cases covered?
Success criteria: Agent finds and correctly applies reference information
Common Rationalizations for Skipping Testing
| Excuse | Reality |
|---|
| "Skill is obviously clear" | Clear to you ≠ clear to other agents. Test it. |
| "It's just a reference" |
References can have gaps, unclear sections. Test retrieval. |
| "Testing is overkill" | Untested skills have issues. Always. 15 min testing saves hours. |
| "I'll test if problems emerge" | Problems = agents can't use skill. Test BEFORE deploying. |
| "Too tedious to test" | Testing is less tedious than debugging bad skill in production. |
| "I'm confident it's good" | Overconfidence guarantees issues. Test anyway. |
| "Academic review is enough" | Reading ≠ using. Test application scenarios. |
| "No time to test" | Deploying untested skill wastes more time fixing it later. |
All of these mean: Test before deploying. No exceptions.
Bulletproofing Skills Against Rationalization
Skills that enforce discipline (like TDD) need to resist rationalization. Agents are smart and will find loopholes when under pressure.
Psychology note: Understanding WHY persuasion techniques work helps you apply them systematically. See persuasion-principles.md for research foundation (Cialdini, 2021; Meincke et al., 2025) on authority, commitment, scarcity, social proof, and unity principles.
Close Every Loophole Explicitly
Don't just state the rule - forbid specific workarounds:
Write code before test? Delete it.
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
Address "Spirit vs Letter" Arguments
Add foundational principle early:
CODEBLOCK16
This cuts off entire class of "I'm following the spirit" rationalizations.
Build Rationalization Table
Capture rationalizations from baseline testing (see Testing section below). Every excuse agents make goes in the table:
CODEBLOCK17
Create Red Flags List
Make it easy for agents to self-check when rationalizing:
CODEBLOCK18
Update CSO for Violation Symptoms
Add to description: symptoms of when you're ABOUT to violate the rule:
CODEBLOCK19
RED-GREEN-REFACTOR for Skills
Follow the TDD cycle:
RED: Write Failing Test (Baseline)
Run pressure scenario with subagent WITHOUT the skill. Document exact behavior:
- - What choices did they make?
- What rationalizations did they use (verbatim)?
- Which pressures triggered violations?
This is "watch the test fail" - you must see what agents naturally do before writing the skill.
GREEN: Write Minimal Skill
Write skill that addresses those specific rationalizations. Don't add extra content for hypothetical cases.
Run same scenarios WITH skill. Agent should now comply.
REFACTOR: Close Loopholes
Agent found new rationalization? Add explicit counter. Re-test until bulletproof.
Testing methodology: See @testing-skills-with-subagents.md for the complete testing methodology:
- - How to write pressure scenarios
- Pressure types (time, sunk cost, authority, exhaustion)
- Plugging holes systematically
- Meta-testing techniques
Anti-Patterns
❌ Narrative Example
"In session 2025-10-03, we found empty projectDir caused..."
Why bad: Too specific, not reusable
❌ Multi-Language Dilution
example-js.js, example-py.py, example-go.go
Why bad: Mediocre quality, maintenance burden
❌ Code in Flowcharts
step1 [label="import fs"];
step2 [label="read file"];
Why bad: Can't copy-paste, hard to read
❌ Generic Labels
helper1, helper2, step3, pattern4
Why bad: Labels should have semantic meaning
STOP: Before Moving to Next Skill
After writing ANY skill, you MUST STOP and complete the deployment process.
Do NOT:
- - Create multiple skills in batch without testing each
- Move to next skill before current one is verified
- Skip testing because "batching is more efficient"
The deployment checklist below is MANDATORY for EACH skill.
Deploying untested skills = deploying untested code. It's a violation of quality standards.
Skill Creation Checklist (TDD Adapted)
IMPORTANT: Use TodoWrite to create todos for EACH checklist item below.
RED Phase - Write Failing Test:
- - [ ] Create pressure scenarios (3+ combined pressures for discipline skills)
- [ ] Run scenarios WITHOUT skill - document baseline behavior verbatim
- [ ] Identify patterns in rationalizations/failures
GREEN Phase - Write Minimal Skill:
- - [ ] Name uses only letters, numbers, hyphens (no parentheses/special chars)
- [ ] YAML frontmatter with only name and description (max 1024 chars)
- [ ] Description starts with "Use when..." and includes specific triggers/symptoms
- [ ] Description written in third person
- [ ] Keywords throughout for search (errors, symptoms, tools)
- [ ] Clear overview with core principle
- [ ] Address specific baseline failures identified in RED
- [ ] Code inline OR link to separate file
- [ ] One excellent example (not multi-language)
- [ ] Run scenarios WITH skill - verify agents now comply
REFACTOR Phase - Close Loopholes:
- - [ ] Identify NEW rationalizations from testing
- [ ] Add explicit counters (if discipline skill)
- [ ] Build rationalization table from all test iterations
- [ ] Create red flags list
- [ ] Re-test until bulletproof
Quality Checks:
- - [ ] Small flowchart only if decision non-obvious
- [ ] Quick reference table
- [ ] Common mistakes section
- [ ] No narrative storytelling
- [ ] Supporting files only for tools or heavy reference
Deployment:
- - [ ] Commit skill to git and push to your fork (if configured)
- [ ] Consider contributing back via PR (if broadly useful)
Discovery Workflow
How future Claude finds your skill:
- 1. Encounters problem ("tests are flaky")
- Finds SKILL (description matches)
- Scans overview (is this relevant?)
- Reads patterns (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 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 discipline applied to documentation.
写作技能
概述
写作技能是将测试驱动开发应用于流程文档。
个人技能存放在特定于代理的目录中(Claude Code 使用 ~/.claude/skills,Codex 使用 ~/.codex/skills)
你编写测试用例(包含子代理的压力场景),观察它们失败(基线行为),编写技能(文档),观察测试通过(代理遵从),然后重构(堵住漏洞)。
核心原则: 如果你没有观察过代理在没有该技能的情况下失败,你就不知道这个技能是否教会了正确的东西。
必备背景: 在使用此技能之前,你必须理解超级能力:测试驱动开发。该技能定义了基本的红-绿-重构循环。本技能将 TDD 适配到文档编写中。
官方指南: 有关 Anthropic 的官方技能编写最佳实践,请参阅 anthropic-best-practices.md。本文档提供了额外的模式和指南,以补充本技能中专注于 TDD 的方法。
什么是技能?
技能是经过验证的技术、模式或工具的参考指南。技能帮助未来的 Claude 实例找到并应用有效的方法。
技能是: 可复用的技术、模式、工具、参考指南
技能不是: 关于你曾经如何解决某个问题的叙述
技能的 TDD 映射
| TDD 概念 | 技能创建 |
|---|
| 测试用例 | 包含子代理的压力场景 |
| 生产代码 |
技能文档 (SKILL.md) |
|
测试失败 (红) | 代理在没有技能的情况下违反规则(基线) |
|
测试通过 (绿) | 代理在有技能的情况下遵从 |
|
重构 | 在保持遵从性的同时堵住漏洞 |
|
先写测试 | 在编写技能
之前运行基线场景 |
|
观察失败 | 记录代理使用的确切合理化理由 |
|
最小化代码 | 编写针对这些特定违规行为的技能 |
|
观察通过 | 验证代理现在遵从 |
|
重构循环 | 发现新的合理化理由 → 堵住 → 重新验证 |
整个技能创建过程遵循红-绿-重构。
何时创建技能
在以下情况创建:
- - 该技术对你来说并非直观明显
- 你会在多个项目中再次参考它
- 该模式适用范围广泛(非项目特定)
- 其他人会从中受益
不要为以下情况创建:
- - 一次性解决方案
- 其他地方已有完善文档的标准实践
- 项目特定的约定(放在 CLAUDE.md 中)
- 机械性约束(如果可以用正则表达式/验证来强制执行,就自动化它——将文档留给需要判断的地方)
技能类型
技术
具有可遵循步骤的具体方法(基于条件的等待、根因追踪)
模式
思考问题的方式(用标志展平、测试不变量)
参考
API 文档、语法指南、工具文档(办公文档)
目录结构
skills/
技能名称/
SKILL.md # 主要参考(必需)
支持文件.* # 仅在需要时
扁平命名空间 - 所有技能都在一个可搜索的命名空间中
单独文件用于:
- 1. 大型参考(100 行以上)- API 文档、综合语法
- 可复用工具 - 脚本、实用程序、模板
保持内联:
- - 原则和概念
- 代码模式(少于 50 行)
- 其他所有内容
SKILL.md 结构
前置元数据 (YAML):
- - 仅支持两个字段:name 和 description
- 总字符数最多 1024 个
- name:仅使用字母、数字和连字符(无括号、特殊字符)
- description:第三人称,仅描述何时使用(非其功能)
- 以Use when...开头,聚焦触发条件
- 包含具体症状、情境和上下文
-
切勿总结技能的过程或工作流程(原因见 CSO 部分)
- 如果可能,保持在 500 字符以内
markdown
name: 用连字符连接的技能名称
description: 当[具体触发条件和症状]时使用
技能名称
概述
这是什么?用 1-2 句话说明核心原则。
何时使用
[如果决策不直观,使用小型内联流程图]
包含症状和用例的列表
何时不使用
核心模式(针对技术/模式)
之前/之后的代码对比
快速参考
用于快速浏览常见操作的表格或列表
实现
简单模式使用内联代码
大型参考或可复用工具链接到文件
常见错误
出错的地方 + 修复方法
实际影响(可选)
具体结果
Claude 搜索优化 (CSO)
对发现至关重要: 未来的 Claude 需要找到你的技能
1. 丰富的描述字段
目的: Claude 读取描述以决定为给定任务加载哪些技能。让它回答:我现在应该阅读这个技能吗?
格式: 以Use when...开头,聚焦触发条件
关键:描述 = 何时使用,而非技能做什么
描述应仅描述触发条件。不要在描述中总结技能的过程或工作流程。
为什么这很重要: 测试揭示,当描述总结了技能的工作流程时,Claude 可能会遵循描述而不是阅读完整的技能内容。一个描述为任务间代码审查的技能导致 Claude 只做了一次审查,即使技能的流程图清楚地显示了两次审查(规范合规性,然后是代码质量)。
当描述改为当执行包含独立任务的实施计划时使用(没有工作流程总结)时,Claude 正确地阅读了流程图并遵循了两阶段审查流程。
陷阱: 总结工作流程的描述会创建一个 Claude 会走的捷径。技能主体变成了 Claude 跳过的文档。
yaml
❌ 错误:总结了工作流程 - Claude 可能会遵循此描述而非阅读技能
description: 当执行计划时使用 - 为每个任务分派子代理,并在任务间进行代码审查
❌ 错误:过程细节过多
description: 用于 TDD - 先写测试,观察失败,编写最小化代码,重构
✅ 正确:仅触发条件,无工作流程总结
description: 当在当前会话中执行包含独立任务的实施计划时使用
✅ 正确:仅触发条件
description: 在实现任何功能或错误修复时,在编写实现代码之前使用
内容:
- - 使用具体的触发条件、症状和表明此技能适用的情境
- 描述问题(竞态条件、不一致行为),而非特定于语言的症状(setTimeout、sleep)
- 保持触发条件与技术无关,除非技能本身是特定于技术的
- 如果技能是特定于技术的,在触发条件中明确说明
- 使用第三人称书写(注入到系统提示中)
- 切勿总结技能的过程或工作流程
yaml
❌ 错误:过于抽象、模糊,不包含何时使用
description: 用于异步测试
❌ 错误:第一人称
description: 当测试不稳定时,我可以帮助你进行异步测试
❌ 错误:提到了技术,但技能并非特定于此技术
description: 当测试使用 setTimeout/sleep 且不稳定时使用
✅ 正确:以Use when开头,描述问题,无工作流程
description: 当测试存在竞态条件、时序依赖或通过/失败不一致时使用
✅ 正确:特定于技术的技能,带有明确的触发条件
description: 当使用 React Router 并处理身份验证重定向时使用
2. 关键词覆盖
使用 Claude 会搜索的词:
- - 错误消息:Hook timed out、ENOTEMPTY、竞态条件
- 症状:不稳定、挂起、僵尸、污染
- 同义词:超时/挂起/冻结、清理/拆卸/afterEach
- 工具:实际命令、库名、文件类型
3. 描述性命名
使用主动语态,动词优先:
- - ✅ creating-skills 而非 skill-creation
- ✅ condition-based-waiting 而非 async-test-helpers
4. Token 效率(关键)
问题: 入门指南和频繁引用的技能会加载到每个对话中。每个 token 都很重要。
目标字数:
- - 入门指南工作流程:每个少于 150 词
- 频繁加载的技能:总计少于 200 词
- 其他技能:少于 500 词(仍需简洁)
技巧:
将细节移至工具帮助:
bash
❌ 错误:在 SKILL.md 中记录所有标志
search-conversations 支持 --text、--both、--after DATE、--before DATE、--limit N
✅ 正确:引用 --help
search-conversations 支持多种模式和过滤器。运行 --help 获取详细信息。
使用交叉引用:
markdown
❌ 错误