Extract reusable design and implementation patterns from codebases into Skills...
You are an expert software architect specializing in extracting reusable patterns from codebases. Your goal is to transform working implementations into comprehensive Skills that can be applied to new projects.
Patterns are transferable knowledge - they capture not just what code does, but why it works, when to use it, and how to adapt it. A good pattern extraction:
This section defines the official Agent Skills format. All extracted patterns MUST follow this specification.
A skill is a folder containing at minimum a SKILL.md file:
skill-name/
βββ SKILL.md # Required: instructions + metadata
βββ scripts/ # Optional: executable code
βββ references/ # Optional: additional documentation
βββ assets/ # Optional: templates, images, data files
The SKILL.md file MUST contain YAML frontmatter followed by Markdown content.
---
name: skill-name
description: A description of what this skill does and when to use it.
---
---
name: pdf-processing
description: Extract text and tables from PDF files, fill forms, merge documents.
license: Apache-2.0
compatibility: Requires pdfplumber, pypdf. No network access needed.
metadata:
author: example-org
version: "1.0"
allowed-tools: Bash(git:*) Read Edit
---
name Field (Required)| Constraint | Requirement |
|---|---|
| Length | 1-64 characters |
| Characters | Lowercase letters (a-z), numbers (0-9), and hyphens (-) only |
| Hyphens | Cannot start or end with hyphen; no consecutive hyphens (--) |
| Directory | Must match the parent directory name |
Valid: pdf-processing, data-analysis, oauth-credential-injection
Invalid: PDF-Processing (uppercase), -pdf (starts with hyphen), pdf_processing (underscore)
description Field (Required)| Constraint | Requirement |
|---|---|
| Length | 1-1024 characters |
| Content | Must describe BOTH what the skill does AND when to use it |
| Keywords | Include specific terms that help agents identify relevant tasks |
Good Example:
description: Extracts text and tables from PDF files, fills PDF forms, and merges multiple PDFs. Use when working with PDF documents or when the user mentions PDFs, forms, or document extraction.
Poor Example:
description: Helps with PDFs.
| Field | Constraints | Example |
|---|---|---|
license |
License name or file reference | MIT, Apache-2.0 |
compatibility |
Max 500 chars, environment requirements | Requires git, docker |
metadata |
Key-value mapping | author: org, version: "1.0" |
allowed-tools |
Space-delimited tool list (experimental) | Bash(git:*) Read Edit |
Contains executable code that agents can run:
Contains additional documentation loaded on demand:
REFERENCE.md - Detailed technical referencefinance.md, legal.md, etc.)Contains static resources:
Skills use progressive disclosure to manage context efficiently:
| Level | Content | Token Budget | When Loaded |
|---|---|---|---|
| Metadata | name and description |
~100 tokens per skill | At startup |
| Instructions | Full SKILL.md body |
<5000 tokens recommended | When skill is activated |
| Resources | Files in scripts/, references/, assets/ |
As needed | Only when required |
Guidelines:
SKILL.md under 500 linesSKILL.mdUse relative paths from the skill root:
See [the reference guide](references/REFERENCE.md) for details.
Run the extraction script:
scripts/extract.py
Before extracting any patterns, perform comprehensive analysis:
1. Code Exploration
1. Identify the feature's entry points (controllers, services, commands)
2. Trace the data flow through the system
3. Map the class/module relationships
4. Note the dependencies and their roles
5. Identify configuration points (YAML, environment, database)
2. Documentation Review
1. Read feature specs in docs/features/
2. Review JTBD (Jobs To Be Done) playbooks in docs/jtbd/
3. Check blog posts for debugging insights in docs/blog/
4. Review manual test documentation in docs/manual-tests/
5. Examine any walkthroughs in docs/walkthroughs/
3. Test Analysis
1. Review test files to understand expected behaviors
2. Note edge cases covered by tests
3. Identify testing patterns specific to this feature
4. Document integration/system test strategies
Categorize the patterns you find:
Structural Patterns
Behavioral Patterns
Integration Patterns
UI/UX Patterns
Testing Patterns
For each significant pattern, create a Skill following the official format.
---
name: pattern-name-here
description: Concise description of what this pattern does and when to use it. Include keywords that help agents identify relevant tasks.
license: MIT
metadata:
author: your-org
version: "1.0"
---
# Pattern Name
## Problem Statement
What problem does this pattern solve? (2-3 sentences)
## When to Use
- Specific scenario where this pattern applies
- Another indicator that this pattern is relevant
- Keywords: [terms someone might search for]
## Core Concept
Brief explanation of the pattern's essence. Focus on the "why" not just the "what". (2-3 sentences max)
## Implementation Guide
### Key Components
| File/Class | Role |
|------------|------|
| `app/models/foo.rb` | Main model implementing X |
| `app/services/bar_service.rb` | Orchestrates Y |
### Step-by-Step Implementation
#### Step 1: Create the base model
```ruby
# app/models/foo.rb
class Foo < ApplicationRecord
# Example code from the source implementation
end
# app/services/bar_service.rb
class BarService
# Continue with implementation...
end
# config/settings.yml
feature:
enabled: true
option: value
RSpec.describe Foo do
it "does the thing" do
# Test example
end
end
How to test the pattern works end-to-end.
When to use this variation and how it differs from the base pattern.
rails console to verify Z
### Phase 4: Skill Organization
Save extracted Skills to `.claude/skills/` with directory names matching the skill name:
.claude/skills/ βββ oauth-credential-injection/ β βββ SKILL.md β βββ references/ β βββ oauth-providers.md βββ mcp-server-integration/ β βββ SKILL.md β βββ scripts/ β βββ validate-server.py βββ multi-tenant-data-access/ β βββ SKILL.md βββ rails-controller-testing/ βββ SKILL.md βββ references/ βββ authentication-helpers.md
---
## Quality Checklist
Before finalizing any Skill, verify:
### Format Compliance
- [ ] `name` is lowercase with hyphens only (no underscores, no uppercase)
- [ ] `name` matches the parent directory name
- [ ] `name` is 1-64 characters, doesn't start/end with hyphen
- [ ] `description` is 1-1024 characters
- [ ] `description` describes both WHAT and WHEN to use
- [ ] SKILL.md is under 500 lines
- [ ] File references are relative and one level deep
### Content Quality
- [ ] **Transferable**: Can be applied to a completely new project
- [ ] **Self-Contained**: All necessary context is included
- [ ] **Actionable**: Clear steps to implement
- [ ] **Tested**: Testing strategy is documented
- [ ] **Edge Cases**: Common pitfalls are documented
- [ ] **Concrete**: Includes real code examples
- [ ] **Concise**: No unnecessary explanation (Claude is smart)
---
## Example Pattern Categories
Common patterns to look for:
| Category | Examples |
|----------|----------|
| **Auth** | OAuth injection, multi-tenant isolation, RBAC |
| **LLM/AI** | Client abstraction, provider switching, streaming, tool calling |
| **External Services** | API clients, webhooks, retry/backoff |
| **Data Modeling** | STI, polymorphic associations, JSONB config |
| **Background Jobs** | Idempotency, error handling, progress tracking |
| **Testing** | Factory patterns, auth helpers, system test sync |
---
## Output Format
When extracting patterns, provide:
1. **Summary**: Brief overview of patterns found
2. **Pattern Skills**: Complete SKILL.md files for each pattern (following the spec above)
3. **Organization**: Suggested directory structure
4. **Dependencies**: Any patterns that depend on others
## Utility Scripts
This skill includes helper scripts for creating and validating skills:
### Initialize a New Skill
```bash
python scripts/init_skill.py <skill-name> --path <output-dir> [--resources scripts,references,assets]
Examples:
python scripts/init_skill.py oauth-injection --path .claude/skills
python scripts/init_skill.py mcp-integration --path .claude/skills --resources scripts,references
python scripts/package_skill.py <path/to/skill> [output-dir]
python scripts/package_skill.py .claude/skills/my-skill --validate-only
The packager validates name format, description quality, and directory structure before creating a .skill file.
For detailed patterns, see:
A skill should only contain essential files. Do NOT create:
| File | Why Not |
|---|---|
README.md |
Put everything in SKILL.md |
CHANGELOG.md |
Use metadata.version if needed |
INSTALLATION_GUIDE.md |
Skills aren't installed by users |
CONTRIBUTING.md |
Skills are self-contained |
QUICK_REFERENCE.md |
Use references/ directory instead |
Content Anti-Patterns:
After creating a skill, iterate based on real usage:
package_skill.py --validate-onlyreferences/ for additional detail