# Continuous Learning Skill

> **Session pattern extraction and skill building at session end.**

---

## Learning Triggers

### End of Session
When session ends, analyze:
- Patterns that worked well
- Recurring solutions applied
- Errors fixed and their fixes

### Successful Completions
When tasks complete successfully:
- What approach worked?
- What would have been faster?

---

## Pattern Detection

### Code Patterns

Detect recurring code structures:

```python
# Pattern: Error handling with logging
try:
    result = operation()
except SpecificError as e:
    logger.error("operation_failed", error=str(e))
    raise ValidationError(f"Failed: {e}") from e
```

### Workflow Patterns

Detect recurring workflows:
- Always run tests before commit
- Check types after adding functions
- Update docs after API changes

### Fix Patterns

Detect recurring error fixes:
- Import missing modules
- Add missing type hints
- Fix async/await propagation

---

## Pattern Storage

### Location
`.claude/state/learned-patterns.json`

### Format
```json
{
  "codePatterns": [
    {
      "name": "error-handling-with-logging",
      "frequency": 12,
      "lastUsed": "2026-01-24T10:00:00Z",
      "context": "exception handling",
      "template": "try/except with structlog"
    }
  ],
  "workflowPatterns": [
    {
      "name": "pre-commit-verification",
      "steps": ["lint", "typecheck", "test"],
      "frequency": 25
    }
  ],
  "fixPatterns": [
    {
      "error": "ModuleNotFoundError",
      "fix": "pip install missing module",
      "frequency": 8
    }
  ]
}
```

---

## Skill Extraction

### From Patterns to Skills

High-frequency patterns become skills:

1. **Identify** - Pattern used 5+ times
2. **Extract** - Document the pattern
3. **Generalize** - Make it reusable
4. **Store** - Add to skills directory

### Example Extraction

Pattern detected:
```python
# Used 10 times this week
@pytest.mark.parametrize("input,expected", [...])
def test_function(input, expected):
    assert function(input) == expected
```

Becomes skill: `skills/testing/parametrized-tests.md`

---

## Session End Hook

### Trigger
```json
{
  "hooks": {
    "SessionEnd": [
      {
        "type": "command",
        "command": "bash .claude/scripts/extract-patterns.sh"
      }
    ]
  }
}
```

### Actions
1. Analyze session history
2. Detect recurring patterns
3. Update pattern storage
4. Suggest skill extractions

---

## Learning Report

### Format
```markdown
## Session Learning Report

### Patterns Detected This Session

#### Code Patterns
| Pattern | Used | Context |
|---------|------|---------|
| Error handling with logging | 3x | Exception handlers |
| Parametrized tests | 2x | Test files |

#### Workflow Patterns
| Pattern | Used |
|---------|------|
| Pre-commit verification | 5x |
| TDD cycle | 3x |

### Suggested Skill Extractions

1. **Error handling with logging**
   - Used 12x total
   - Ready for extraction

2. **API endpoint pattern**
   - Used 8x total
   - Consider extraction

### Export to Skills?
Run `/learn --export` to create skill files
```

---

## Integration

### With Session State
- Patterns stored in `.claude/state/`
- Persists across sessions
- Influences future suggestions

### With Skills
- High-frequency patterns become skills
- Skills improve over time
- Feedback loop for improvement

---

## Related Skills

- [strategic-compact](../strategic-compact/) - Context management
- [tdd-workflow](../tdd-workflow/) - Testing patterns
