Learn Skill - Continuous Learning System
Purpose
Capture reusable patterns discovered during sessions as "instincts" with confidence scoring.
Instincts start weak (0.3) and grow stronger with repeated confirmation (max 0.9).
Trigger
- User types
/learn followed by a pattern description
- User types
/learn with no args (auto-detect from current session context)
Algorithm
- Parse input: Extract the pattern description and optional tags from user input
- Read instincts file: Load
~/.claude/learnings/instincts.json
- If file is empty or missing, initialize with default structure
- Check for duplicates: Compare new pattern against existing instincts
- Fuzzy match: if 60%+ of significant words (4+ chars) overlap, treat as existing
- If match found: increment confidence by 0.2 (cap at 0.9), add new evidence entry, update last_confirmed
- If no match: create new instinct with confidence 0.3
- Generate instinct object (for new patterns):
{
"id": "inst_NNN",
"pattern": "<pattern description>",
"confidence": 0.3,
"evidence": ["session_YYYY-MM-DD: <context>"],
"created": "YYYY-MM-DD",
"last_confirmed": "YYYY-MM-DD",
"tags": ["<auto-detected-or-user-provided>"],
"source": "user|auto",
"evolved_to": null
}
- Save: Write updated instincts.json, increment metadata.total_learned
- Display: Show the saved/updated instinct to the user in a clear format
ID Generation
- Format:
inst_NNN where NNN is zero-padded 3-digit sequential number
- Read existing instincts, find max ID number, increment by 1
- First instinct:
inst_001
Tag Auto-Detection
If user does not provide tags, infer from pattern text using these keyword groups:
| Keywords in pattern |
Tag |
| parallel, concurrent, async, simultaneous |
parallelism |
| glob, grep, search, find |
search |
| performance, fast, speed, optimize |
performance |
| test, assert, verify, check |
testing |
| error, fix, bug, debug |
debugging |
| git, commit, branch, merge |
git |
| file, read, write, edit |
file-ops |
| security, auth, token, secret |
security |
| cache, memory, resource |
resources |
Assign up to 3 tags. If no keywords match primary categories, try secondary:
| Keywords |
Tag |
| checkpoint, session, memory, context |
session-management |
| architecture, design, structure |
architecture |
| workflow, process, pipeline |
workflow |
If still no match, use ["general"] (last resort).
Fuzzy Match Logic
significant_words(text) = [word.lower() for word in text.split() if len(word) >= 4]
# Jaccard similarity (intersection/union) is symmetric and handles
# different-length patterns better than precision-style overlap
jaccard(a, b) = len(set(significant_words(a)) & set(significant_words(b))) / len(set(significant_words(a)) | set(significant_words(b)))
is_duplicate = jaccard >= 0.6
Confidence Scale
| Observation |
Confidence |
Meaning |
| 1st (creation) |
0.3 |
New pattern, first discovery |
| 2nd (confirmed once) |
0.5 |
Same pattern seen again (+0.2) |
| 3rd (confirmed twice) |
0.7 |
Evolution candidate (+0.2, 3+ confirms) |
| 4th+ (confirmed 3+) |
0.9 |
Verified pattern (+0.2, capped at 0.9) |
Formula: new_confidence = min(current_confidence + 0.2, 0.9)
Contradiction: new_confidence = max(current_confidence - 0.2, 0.0) -> archive at 0.0
Output Format
INSTINCT CAPTURED
ID: inst_NNN
Pattern: <description>
Confidence: 0.X [NEW | +0.2 CONFIRMED]
Tags: tag1, tag2
Evidence: N entries
Tip: Use /evolve when you have 3+ instincts at 0.7+ to create reusable skills.
Corruption Detection and Recovery
Detection criteria: instincts.json is corrupted if:
- Invalid JSON syntax
- Missing "version" field
- Missing "instincts" array
- File size > 10MB
Recovery:
- Back up as
instincts.json.YYYYMMDD_HHMMSS.bak (timestamped, not overwrite)
- Keep max 3 backups (delete oldest)
- Reinitialize with fresh schema
- Log: "Recovered from corrupted instincts.json"
Error Handling
- If no pattern text provided and no session context available, ask user to describe the pattern
- Maximum 500 instincts in file; if exceeded, archive instincts with confidence < 0.3 that are older than 30 days
1---2name: learn3description: Capture a learning pattern from the current session with confidence scoring. Use when the user says /learn or when a reusable pattern is discovered.4---56# Learn Skill - Continuous Learning System78## Purpose910Capture reusable patterns discovered during sessions as "instincts" with confidence scoring.11Instincts start weak (0.3) and grow stronger with repeated confirmation (max 0.9).1213## Trigger1415- User types `/learn` followed by a pattern description16- User types `/learn` with no args (auto-detect from current session context)1718## Algorithm19201. **Parse input**: Extract the pattern description and optional tags from user input212. **Read instincts file**: Load `~/.claude/learnings/instincts.json`22 - If file is empty or missing, initialize with default structure233. **Check for duplicates**: Compare new pattern against existing instincts24 - Fuzzy match: if 60%+ of significant words (4+ chars) overlap, treat as existing25 - If match found: increment confidence by 0.2 (cap at 0.9), add new evidence entry, update last_confirmed26 - If no match: create new instinct with confidence 0.3274. **Generate instinct object** (for new patterns):28 ```json29 {30 "id": "inst_NNN",31 "pattern": "<pattern description>",32 "confidence": 0.3,33 "evidence": ["session_YYYY-MM-DD: <context>"],34 "created": "YYYY-MM-DD",35 "last_confirmed": "YYYY-MM-DD",36 "tags": ["<auto-detected-or-user-provided>"],37 "source": "user|auto",38 "evolved_to": null39 }40 ```415. **Save**: Write updated instincts.json, increment metadata.total_learned426. **Display**: Show the saved/updated instinct to the user in a clear format4344## ID Generation4546- Format: `inst_NNN` where NNN is zero-padded 3-digit sequential number47- Read existing instincts, find max ID number, increment by 148- First instinct: `inst_001`4950## Tag Auto-Detection5152If user does not provide tags, infer from pattern text using these keyword groups:5354| Keywords in pattern | Tag |55|---|---|56| parallel, concurrent, async, simultaneous | `parallelism` |57| glob, grep, search, find | `search` |58| performance, fast, speed, optimize | `performance` |59| test, assert, verify, check | `testing` |60| error, fix, bug, debug | `debugging` |61| git, commit, branch, merge | `git` |62| file, read, write, edit | `file-ops` |63| security, auth, token, secret | `security` |64| cache, memory, resource | `resources` |6566Assign up to 3 tags. If no keywords match primary categories, try secondary:6768| Keywords | Tag |69|---|---|70| checkpoint, session, memory, context | `session-management` |71| architecture, design, structure | `architecture` |72| workflow, process, pipeline | `workflow` |7374If still no match, use `["general"]` (last resort).7576## Fuzzy Match Logic7778```79significant_words(text) = [word.lower() for word in text.split() if len(word) >= 4]80# Jaccard similarity (intersection/union) is symmetric and handles81# different-length patterns better than precision-style overlap82jaccard(a, b) = len(set(significant_words(a)) & set(significant_words(b))) / len(set(significant_words(a)) | set(significant_words(b)))83is_duplicate = jaccard >= 0.684```8586## Confidence Scale8788| Observation | Confidence | Meaning |89|---|---|---|90| 1st (creation) | 0.3 | New pattern, first discovery |91| 2nd (confirmed once) | 0.5 | Same pattern seen again (+0.2) |92| 3rd (confirmed twice) | 0.7 | Evolution candidate (+0.2, 3+ confirms) |93| 4th+ (confirmed 3+) | 0.9 | Verified pattern (+0.2, capped at 0.9) |9495Formula: `new_confidence = min(current_confidence + 0.2, 0.9)`96Contradiction: `new_confidence = max(current_confidence - 0.2, 0.0)` -> archive at 0.09798## Output Format99100```101INSTINCT CAPTURED102103ID: inst_NNN104Pattern: <description>105Confidence: 0.X [NEW | +0.2 CONFIRMED]106Tags: tag1, tag2107Evidence: N entries108109Tip: Use /evolve when you have 3+ instincts at 0.7+ to create reusable skills.110```111112## Corruption Detection and Recovery113114**Detection criteria:** instincts.json is corrupted if:115- Invalid JSON syntax116- Missing "version" field117- Missing "instincts" array118- File size > 10MB119120**Recovery:**1211. Back up as `instincts.json.YYYYMMDD_HHMMSS.bak` (timestamped, not overwrite)1222. Keep max 3 backups (delete oldest)1233. Reinitialize with fresh schema1244. Log: "Recovered from corrupted instincts.json"125126## Error Handling127128- If no pattern text provided and no session context available, ask user to describe the pattern129- Maximum 500 instincts in file; if exceeded, archive instincts with confidence < 0.3 that are older than 30 days