---
name: synthesize-learnings
description: Distill durable learnings from a finished session/ticket and open assign-to-you, never-merge PRs against the Gemma knowledge surface (agentic-toolkit, gemma-best-practices, gemma-sql-style) to self-improve the data team.
disable-model-invocation: true
argument-hint: "[session scope, e.g. 'this session' or a ticket id]"
---

# Synthesize learnings

Run the self-improvement loop for the scope in `$ARGUMENTS` (default: the current/just-finished session). This is the entry point for the **`learning-synthesizer`** role — follow that agent definition's rubric and safety rails exactly.

## Flow

1. **Gather** what happened in scope:
   - Teammate transcripts (`subagents/agent-*.jsonl` in the session directory).
   - The shared task list (`TaskList` / `TaskGet`) — completed tasks and QA findings.
   - The session's PRs and review comments (`gh pr view`, `gh api repos/{owner}/{repo}/pulls/{n}/comments`).
   - The diffs produced, and especially anything the QA auditor noted it "would flag".

2. **Distill** candidate learnings, then **filter** through the include/exclude rubric in `learning-synthesizer.md`. Abstract each to its general form and **strip every client specific (names, values, columns, ticket text) and any secret.** When unsure whether something is durable, drop it.

3. **Route & dedupe.** Group survivors by target repo (`gemma-agentic-toolkit` / `gemma-best-practices` / `gemma-sql-style`). Check existing repo content and `gh pr list` to skip anything already documented or already proposed.

4. **Approval gate (required).** Present a concise table to the user — *learning → target repo → exact edit* — plus what you excluded and why. **Do not open or push anything until the user approves.** This is the human review point.

5. **Open one PR per approved repo.** For each: confirm a clean working tree and the correct `origin` remote, branch off `main` (worktree if needed), make the minimal edit, commit (conventional message), push, and `gh pr create --assignee @me`. **Never merge, never force-push, never auto-merge.**

6. **Report**: a summary with PR links, plus the excluded learnings (so the user can override a "drop" call).

## Automatic triggering (opt-in)

By default this runs **manually** (`/synthesize-learnings`). To run it whenever a session ends, wire a `Stop` hook that invokes Claude Code headlessly — opt-in, because it spends tokens on every session end and opens PRs:

```jsonc
// ~/.claude/settings.json (or project settings) — opt-in, NOT shipped enabled
{
  "hooks": {
    "Stop": [
      { "hooks": [ {
        "type": "command",
        "command": "claude --print '/synthesize-learnings this session' >> ~/.claude/synthesize.log 2>&1 &",
        "statusMessage": "Checking the session for durable learnings"
      } ] }
    ]
  }
}
```

Even when auto-triggered, the agent still opens **assign-to-you, never-merge** PRs — you remain the reviewer. Start manual; enable the hook only once you trust its signal.
