Extract reusable patterns from a completed task. Identify approach, tools used, what worked, and produce structured pattern JSON with tags and confidence scoring. Triggers: extract pattern, learn from task, capture pattern, what worked, save approach
memory/patterns/ directory exists (create if not)memory/patterns/index.json exists for pattern indexing (create if not)Read the task description, the approach taken, and the final output. Identify:
A good pattern is:
Check memory/patterns/index.json for existing patterns. If this approach is already captured, skip extraction and instead update the existing pattern's usage_count via neural-pattern-score.
Create a pattern JSON file at memory/patterns/pat-[slug].json:
{
"id": "pat-[slug]",
"name": "[Human-readable pattern name]",
"description": "[One-sentence description of when and how to use this pattern]",
"tags": ["tag1", "tag2", "tag3"],
"context_keywords": ["keyword1", "keyword2", "keyword3"],
"approach": "[Step-by-step description of the approach]",
"tools_used": ["tool1", "tool2"],
"agents_involved": ["agent1", "agent2"],
"confidence": 0.5,
"usage_count": 1,
"success_count": 1,
"failure_count": 0,
"created": "[ISO timestamp]",
"last_used": "[ISO timestamp]",
"source_task": "[Brief description of the task this was extracted from]"
}
Tags should be broad categories: ["api", "error-handling", "performance"]
Context keywords should be specific terms that would appear in a similar task: ["timeout", "retry", "exponential-backoff"]
Aim for 3-5 tags and 3-8 context keywords per pattern.
New patterns always start at confidence 0.5 (neutral). Confidence adjusts over time:
neural-pattern-score)Add an entry to memory/patterns/index.json:
{
"id": "pat-[slug]",
"name": "[name]",
"tags": ["tag1", "tag2"],
"confidence": 0.5,
"last_used": "[ISO timestamp]"
}
Append to logs/claude_log.md:
### Pattern Extracted — [timestamp]
- Pattern: [name] (pat-[slug])
- Source: [task description]
- Tags: [tag list]
- Confidence: 0.5 (initial)
memory/patterns/pat-[slug].json — the structured pattern filememory/patterns/index.json with the new entrylogs/claude_log.md