learn

learn is a command for Claude Code from JuanMarchetto/agent-skills. It costs 21 tokens per session (749 once invoked), scanned A, original, MIT.

A command for turning the latest error into a saved lesson immediately.

In plain words
What is it for?
Use it after a failed command, build, test, or runtime operation to capture the error, cause, fix, and prevention rule.
Why use it?
It lets you record a useful lesson without waiting for the error to happen repeatedly.

Command for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the learn-by-mistake plugin — 1 skill, 4 commands, 3 hooks shipped together

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 commands/juanmarchetto/agent-skills/learn
Clone the repo
git clone --depth 1 https://github.com/JuanMarchetto/agent-skills

Made for: Claude Code.

Or install learn-by-mistake, the plugin that ships this one along with the rest of its 1 skill, 4 commands, 3 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for learn

README.md
[![agentmods](https://agentmods.dev/badge/commands/juanmarchetto/agent-skills/learn.svg)](https://agentmods.dev/commands/juanmarchetto/agent-skills/learn)
Your own site
<a href="https://agentmods.dev/commands/juanmarchetto/agent-skills/learn"><img src="https://agentmods.dev/badge/commands/juanmarchetto/agent-skills/learn.svg" alt="Measured on agentmods" height="20"></a>
Per session 21 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 749 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.1 $0.00021 $0.00749
Opus 5 $0.00010 $0.00375
Sonnet 5 $0.00004 $0.00150
Haiku 4.5 $0.00002 $0.00075

Measured 2d ago against content hash 57ad569f2e72, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

learn 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 2d ago.

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.

skills/learn-by-mistake/commands/learn.md · 77 lines

How it starts

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

/learn — Force Lesson Extraction

You are the Learn-by-Mistake skill's lesson extraction engine. The user has triggered /learn to force-extract a lesson from the most recent error in this conversation.

Instructions

  1. Find the most recent error in this conversation. Look for:

    • Failed Bash commands (non-zero exit codes)
    • Error messages in stderr
    • Compilation/build failures
    • Runtime exceptions or tracebacks
    • Any tool use that produced an error
  2. If no error is found, tell the user: "No recent error found in this conversation. Try running a command first, or describe the mistake you want to capture."

  3. Extract a lesson using this format:

    ### [YYYY-MM-DD] category: one-line summary
    - **Error**: The error message or pattern (sanitized, enough to match against)
    - **Root cause**: Why it actually failed — the real bug, not the symptom
    - **Fix**: What resolved it — specific, actionable, referencing project files/config when relevant
    - **Prevention**: Reusable rule to check BEFORE this error can happen again
    - **Hits**: 1
    

    Categories (use exactly one): build, test, runtime, types, linter, git, dependency, config

  4. Show the lesson to the user and ask for approval before writing. Example:

    Extracted lesson from the last error:
    
    ### [2026-03-17] config: Use --no-pager with git log in scripts
    - **Error**: git log hangs in non-interactive shell
    - **Root cause**: git defaults to a pager (less) which blocks when there is no TTY
    - **Fix**: Always pass `--no-pager` or pipe to `cat` when using git in scripts
    - **Prevention**: When calling git commands in scripts or hooks, always use `--no-pager` or `| cat`
    - **Hits**: 1
    
    Write this to .claude/lessons.md? (yes/no/edit)
    
  5. On approval, write the lesson directly to the Active Lessons section of .claude/lessons.md:

    • If the file doesn't exist, create it with the standard template (see below)
    • Place it at the end of the Active Lessons section (before the next section header)
    • Sort Active Lessons by Hits count (highest first) when rewriting the file

Read the full file on GitHub · 77 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. 2d ago First seen · 77 lines · 21 tokens per session scan A 57ad569f2e72

Subscribe to this mod's changes

learn is a command published in the GitHub repository JuanMarchetto/agent-skills (5 stars, last pushed 5mo ago), licensed MIT. It adds 21 tokens to every session and 749 once invoked, about $0.0001 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-09-03.