Stop-hook — auto-improving lesson capture

Stop-hook — auto-improving lesson capture

What it does

At the end of every Claude Code session, the hook scans the transcript for either:

  • A line containing LESSON: <text> (anywhere in an assistant turn), or
  • A fenced block ```lesson … ``` (future extension — current v1 captures the simple LESSON: form only).

Matches are appended to memory/lessons/YYYY-MM.md, grouped by ISO timestamp. Duplicates within a session are de-duped (sort -u). If nothing matches, the hook is silent.

Why it matters

This closes Gap #2 from RD-0033: the factory had no mechanism to let a talent self-improve across sessions. Now any talent can write LESSON: client prefers chiffres en français avec espace insécable and it lands in persistent memory for the next session.

Convention for talents

In any role's CLAUDE-{domain}.md, add a Lessons section that instructs:

Quand vous découvrez un fait durable sur le client ou son métier qui devrait survivre à la session (préférence, contrainte, vocabulaire, échec passé), émettez en fin de réponse LESSON: <fait en une phrase>. Le hook l'archive automatiquement dans memory/lessons/.

Install

  1. Copy stop-self-improve.sh{talent-repo}/.claude/hooks/stop-self-improve.sh
  2. chmod +x (already set in source).
  3. Merge the hooks.Stop block from stop-self-improve.json into {talent-repo}/.claude/settings.json.
  4. Verify: run a session, end it, check memory/lessons/YYYY-MM.md was created.

Windows note

The shell script uses bash. On Windows, Claude Code runs hooks via Git Bash by default — no change needed. If a talent ships on PowerShell-only environments, a .ps1 sibling will be added in v2.