Get the FREE Ultimate OpenClaw Setup Guide →
npx machina-cli add skill Pamacea/smite/pattern-capture --openclaw
Files (1)
SKILL.md
8.1 KB

Pattern Capture Skill

Mission

Automatically capture, document, and organize successful code patterns for future reuse. Transform ad-hoc solutions into reusable knowledge.


When to Use

  • After successful feature implementation: "That went well, let me save this pattern"
  • When solving a tricky problem: Document the solution for next time
  • During refactoring: Extract reusable patterns from existing code
  • Team knowledge sharing: Document patterns for others to use

Examples

# After successful implementation
/studio build --capture-pattern "Rust async refactor"

# Manual pattern capture
/pattern-capture "document authentication flow"

# Search patterns
/pattern list rust
/pattern show rust/async-refactor

When NOT to Use

  • Failed implementations (only capture successful patterns)
  • Trivial code (not worth documenting)
  • Project-specific hacks (not reusable)
  • Temporary solutions (not worth preserving)
  • One-off fixes (no reusable value)
  • During active debugging (capture after success)

Pattern Template

Every captured pattern follows this structure:

# Pattern: [Descriptive Name]

## Context
[When to use this pattern - problem it solves]

## Before
[Code state before applying pattern]

## After
[Code state after applying pattern]

## Steps
1. [Step 1]
2. [Step 2]
3. [Step 3]

## Benefits
- [Benefit 1]
- [Benefit 2]

## Trade-offs
- [Trade-off 1]
- [Trade-off 2]

## Related Patterns
- [Pattern 1]
- [Pattern 2]

## Examples
### Example 1: [Use case]
\`\`\`language
[Code example]
\`\`\`

### Example 2: [Use case]
\`\`\`language
[Code example]
\`\`\`

Capture Workflow

Step 1: Identify Pattern

Ask yourself:

  • What problem did this solve?
  • Is this reusable? (Used 3+ times = good candidate)
  • What makes this pattern special?

Step 2: Extract Context

Document:

  • Technology stack: What languages/frameworks?
  • Problem domain: Business logic, UI, data, etc.
  • Complexity: Simple, medium, complex
  • Prerequisites: What else must exist?

Step 3: Document Steps

Break down into clear, actionable steps:

  1. What to check first
  2. What to modify
  3. What to verify

Step 4: Add Examples

Provide:

  • Minimal example: Simplest case
  • Real-world example: Actual use case
  • Edge cases: What to watch for

Step 5: Categorize

Add tags for discovery:

  • Technology: rust, nextjs, prisma
  • Domain: api, ui, database, auth
  • Complexity: simple, medium, complex

Pattern Categories

Architecture Patterns

  • Layered architecture: Separation of concerns
  • CQRS: Command Query Responsibility Segregation
  • Event-driven: Async communication patterns
  • Microservices: Service boundaries

Code Patterns

  • Error handling: Result types, exceptions
  • Async patterns: Promises, async/await, streams
  • Validation: Input validation, schema validation
  • State management: Local, global, server state

Database Patterns

  • Query optimization: Indexing, N+1 prevention
  • Transaction patterns: ACID guarantees
  • Migration patterns: Safe schema changes
  • Caching strategies: When and what to cache

Testing Patterns

  • Test structure: Arrange-Act-Assert
  • Mock strategies: What to mock vs real
  • Test data: Factories, fixtures
  • Coverage: Unit vs integration vs E2E

Security Patterns

  • Authentication: JWT, sessions, OAuth
  • Authorization: RBAC, ABAC, policy checks
  • Input validation: Sanitization, type checking
  • Output encoding: XSS prevention

Auto-Capture Triggers

This skill can be automatically triggered when:

  1. Successful test after failure: Pattern was the solution
  2. Multi-file refactoring: Indicates reusable approach
  3. Complex problem solved: Document for future reference
  4. User explicitly requests: /pattern-capture

Storage Location

Patterns are stored in:

plugins/agents/workflow/patterns/
├── rust/
│   ├── async-refactor.md
│   ├── error-handling.md
│   └── api-endpoint.md
├── nextjs/
│   ├── server-components.md
│   ├── data-fetching.md
│   └── form-validation.md
└── prisma/
    ├── schema-design.md
    ├── query-optimization.md
    └── migrations.md

Discovery

Find patterns using:

# Search by technology
/pattern list rust

# Search by domain
/pattern list api

# Search by keyword
/pattern list async

# Get specific pattern
/pattern show rust/async-refactor

Quality Checklist

Before saving a pattern, verify:

  • Clear purpose: Problem statement is obvious
  • Reproducible: Steps are detailed enough
  • Tested examples: Code examples actually work
  • Trade-offs documented: Not overselling benefits
  • Well-categorized: Easy to find later
  • Version specific: Notes on tech versions if relevant

Example: Capturing a Rust Pattern

Trigger

/studio build --capture-pattern "Rust async refactor"

Generated Pattern

# Pattern: Rust Async Refactor

## Context
Refactor blocking Rust code to use async/await with proper error handling.

## Before
\`\`\`rust
pub fn get_user(id: u32) -> User {
    let conn = db::connect().unwrap();
    let user = conn.query_user(id).unwrap();
    user
}
\`\`\`

## After
\`\`\`rust
pub async fn get_user(id: u32) -> Result<User, DbError> {
    let mut conn = db::connect().await?;
    let user = conn.query_user(id).await?;
    Ok(user)
}
\`\`\`

## Steps
1. Change function signature to `async fn`
2. Change return type to `Result<T, E>`
3. Replace `.unwrap()` with `?` operator
4. Add `.await` to async calls
5. Update call sites to use async/await

## Benefits
- Non-blocking: Other tasks can run during I/O
- Proper error handling: No panics on failure
- Better scalability: Handle more concurrent requests

## Trade-offs
- Complexity: Async code is harder to debug
- Runtime: Requires tokio or async-std
- Not always needed: Blocking is fine for simple scripts

## Related Patterns
- rust-error-handling
- rust-api-endpoint
- tokio-spawning

Integration with Other Skills

This skill works with:

  • tdd-guide: Capture test patterns
  • code-reviewer: Extract improvement patterns
  • planner: Document architectural patterns

Anti-Patterns

Anti-PatternProblemFix
Capturing failed attemptsWastes time, teaches wrong patternsOnly capture successful implementations
Documenting trivial codeNoise in pattern libraryOnly capture non-obvious, reusable patterns
Missing trade-offsOverpromises benefitsAlways document downsides
No examplesHard to apply patternInclude before/after code examples
Outdated patternsMisleading informationReview and update monthly
Too specificNot reusableGeneralize to make applicable across contexts
No contextHard to know when to useAlways include "when to use this pattern"

Maintenance

  • Review monthly: Are patterns still relevant?
  • Update with new tech: Add patterns for new versions
  • Deprecate old patterns: Mark as outdated when necessary
  • Merge duplicates: Consolidate similar patterns

Success Metrics

A good pattern library:

  • ✅ Patterns are found (not recreated)
  • ✅ New devs adopt patterns quickly
  • ✅ Code consistency improves
  • ✅ Fewer repeated discussions
  • ✅ Team knowledge grows organically

Version: 1.0.0 | Category: workflow | Last updated: 2026-02-19

Source

git clone https://github.com/Pamacea/smite/blob/main/plugins/studio/skills/pattern-capture/SKILL.mdView on GitHub

Overview

Pattern Capture records successful code patterns with context after a feature lands, turning ad-hoc solutions into documented knowledge. It auto-triggers during multi-file refactors or when solving complex problems, creating a reusable pattern library for the team.

How This Skill Works

When a pattern is captured, the skill collects context such as tech stack, problem domain, complexity, and prerequisites, then stores a Pattern Template detailing Context, Before/After, Steps, Benefits, Trade-offs, and Examples. Patterns are categorized with tags and made discoverable for future reuse by the team.

When to Use It

  • After successful feature implementation: that went well, save this pattern
  • When solving a tricky problem: document the solution for next time
  • During refactoring: extract reusable patterns from existing code
  • Team knowledge sharing: document patterns for others to use
  • When building a catalog of patterns for future reuse across projects

Quick Start

  1. Step 1: After a successful feature, trigger capture (e.g., /studio build --capture-pattern "Descriptive Name")
  2. Step 2: Fill out the Pattern Template with Context, Before, After, Steps, Benefits, Trade-offs, and Examples
  3. Step 3: Tag with technology, domain, and complexity; save to the shared pattern library

Best Practices

  • Capture only successful, reusable patterns (not failed attempts)
  • Ensure the pattern is reused or has 3+ occurrences before documenting
  • Document full context: technology stack, problem domain, complexity, prerequisites
  • Use the Pattern Template: Context, Before, After, Steps, Benefits, Trade-offs, Related Patterns, and Examples
  • Tag and categorize with technology, domain, and complexity for easy discovery

Example Use Cases

  • Example 1: Rust async refactor
  • Example 2: document authentication flow
  • Example 3: Multi-file refactor to extract a reusable pattern
  • Example 4: Complex data pipeline solution pattern
  • Example 5: API input validation and error handling pattern

Frequently Asked Questions

Add this skill to your agents

Related Skills

ab-test-setup

ranbot-ai/awesome-skills

Structured guide for setting up A/B tests with mandatory gates for hypothesis, metrics, and execution readiness.

pdf

anthropics/skills

Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.

claude-md-optimizer

smith-horn/product-builder-starter

Optimize oversized CLAUDE.md files using progressive disclosure. Analyzes content tiers, detects encryption constraints, creates sub-documents, and rewrites the main file with a Sub-Documentation Table. Triggers: optimize CLAUDE.md, reduce CLAUDE.md size, CLAUDE.md too long, apply progressive disclosure to CLAUDE.md

session-management

athola/claude-night-market

Manage Claude Code sessions with naming, checkpointing, and resume strategies.

multi-review

Pamacea/smite

MANDATORY gate BEFORE merging PR or deploying to production in smite project. Invoke FIRST when 'comprehensive review', 'check security', 'performance review', 'test coverage review', 'code quality audit' - orchestrates parallel review by 4 specialized agents (security, performance, testing, documentation) with consolidated report and scoring. Specific phrases: 'review this PR', 'security audit', 'performance check', 'test review'. (user)

progressive-build

Pamacea/smite

Invoke BEFORE building complex features requiring both speed AND quality in smite project - progressive enhancement workflow using Haiku (MVP in 2min) → Sonnet (quality in 5min) → Opus (excellence in 10min). Triggers on 'complex feature', 'optimize and build', 'production-ready feature', 'build with optimization'. Total: 17min, 9.5/10 quality, 73% cost savings vs Opus-only. Specific phrases: 'progressive build', 'enhance this', 'iterate and improve'. (user)

Sponsor this space

Reach thousands of developers