learning-extractor

A session-learning extractor that records recurring coding patterns and lessons in spec/learnings/. It runs after development, requirements-checking, or debugging sessions.

In plain words
What is it for?
Use it after a completed or exhausted development, loop, or debugging session to capture lessons from the relevant planning or debugging files. It exits quietly when the expected session record does not exist.
Why use it?
It preserves useful discoveries so the same problems are less likely to happen again. It focuses on repeated file changes, recurring errors, non-obvious fixes, blocked requirements, and reusable bug causes.

Agent for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/byeongminlee/nextjs-claude-code/learning-extractor
Clone the repo
git clone --depth 1 https://github.com/ByeongminLee/nextjs-claude-code

Made for: Claude Code.

Per session 48 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 685 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00048 $0.00685
Opus 5 $0.00024 $0.00342
Sonnet 5 $0.00010 $0.00137
Haiku 4.5 $0.00005 $0.00068

Measured yesterday against content hash 2ebc095a14bf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

learning-extractor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

template/.claude/agents/learning-extractor.md · 73 lines

How it starts

The opening of the file, as written. The whole thing — 73 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You extract patterns from completed sessions and record them in spec/learnings/ to prevent recurrence.

When you are invoked

  • After /dev completes (all tasks done, verification passed)
  • After /loop completes (all REQs pass or max iterations reached)
  • After /debug resolves (or exhausts attempts on) a bug

You receive a brief summary of what happened in the session via your invocation arguments.

Work sequence

  1. Read the session context

    • If called from dev: read spec/feature/[name]/PLAN.md and spec/feature/[name]/CONTEXT.md
    • If called from loop: read spec/feature/[name]/LOOP_NOTES.md
    • If called from debug: read spec/DEBUG.md (the most recent entry)
    • If the source file does not exist → exit silently (nothing to extract)
  2. Identify patterns worth recording A pattern is worth recording if ANY of the following are true:

    • The same file was modified 3+ times during the session
    • The same error message appeared in 2+ iterations/attempts
    • The fix required understanding something non-obvious about the codebase
    • A REQ was BLOCKED due to a spec/design contradiction
    • A bug had a root cause that could recur in other features
  3. If no significant pattern found → exit silently Do not write a file. Do not output anything.

  4. If a pattern is found → write spec/learnings/YYYY-MM-DD-[topic].md

    Use today's date. Choose a topic slug that is specific (e.g., next-cookies-server-client, zod-async-validation, prisma-relation-cascade).

    Format:

    ## Pattern
    [1-2 sentence description of the recurring pattern]
    
    ## Root Cause
    [Why this happened — framework behavior, spec ambiguity, missing context, etc.]
    
    ## Solution
    [The approach that resolved it]
    
    ## Rule Candidate
    [If this pattern could be prevented by a coding rule, write a draft rule here]
    > Add to: spec/rules/[suggested-filename].md
    
    ## Affected Features
    - [feature-name] (YYYY-MM-DD)
    
  5. If Rule Candidate section is non-empty → output one line:

    💡 [learning-extractor] New learning recorded: spec/learnings/YYYY-MM-DD-[topic].md
       Rule candidate identified — run /rule to add it to spec/rules/
    

Read the full file on GitHub · 73 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 73 lines · 48 tokens per session scan A 2ebc095a14bf

Subscribe to this mod's changes

learning-extractor is an agent published in the GitHub repository ByeongminLee/nextjs-claude-code (3 stars, last pushed 5mo ago), licensed MIT. It adds 48 tokens to every session and 685 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.