>_

How Claude Code Learns From Every Correction I Make

Robin||5 min
Last updated: February 17, 2026
claude-codehooksautomationself-correction
How Claude Code Learns From Every Correction I Make

Last Tuesday I corrected Claude Code on the same thing for the fourth time. Same preference. Same session structure. Different day. The correction landed, Claude adjusted, and then the session ended - taking that adjustment with it.

The next morning, same mistake. I typed the same correction again.

This is the core frustration with AI coding assistants: they're excellent at responding to corrections in the moment, but they can't learn from them across sessions. The correction evaporates when the context window closes. Whatever I taught Claude today, I'll be teaching it again next week.

I decided to fix this with a hook.

Want the foundational patterns first? The free 3-pattern guide covers memory, delegation, and knowledge graphs at concept level.

The Problem: Corrections Are Ephemeral

Here's a concrete example. I prefer snake_case for Python variables. Every session where Python comes up, I correct it. Sometimes once, sometimes twice. Then the session ends.

The next session starts fresh. Same default. Same correction. Five sessions, five corrections, zero permanent change.

This isn't a Claude failure - it's an architectural reality. Without a mechanism to capture corrections and convert them to persistent rules, every session starts from zero. The AI isn't learning; you're just repeating yourself indefinitely.

The same pattern applies to workflow preferences, code style, architectural decisions, even communication tone. Any behavioral preference that deviates from defaults gets corrected by you, repeatedly, forever - unless something captures that signal and makes it permanent.

Before - Corrections Vanish
  • -Same correction repeated across sessions
  • -AI forgets preferences between restarts
  • -Manual rule writing for every preference
  • -No learning loop from user feedback
After - Corrections Become Rules
  • +Correction detected automatically (7 patterns)
  • +Rules staged then promoted after validation
  • +Behavior changes permanently after 1 correction
  • +Closed-loop: correct once, fixed forever

The Solution: A Claude Code Hook That Turns Corrections Into Rules

I built a UserPromptSubmit hook - it fires on every message I send to Claude. Its job is to detect whether my message is correcting Claude's behavior, and if so, generate a new behavioral rule from that correction.

The detection works across seven correction patterns. Some are explicit: "no, not like that" or "stop doing X". Some are implicit: "instead, try Y" or "can you do this differently". Some are evaluative: "that's too verbose" or "you're overcomplicating this". Each pattern has a confidence weight based on how reliably it signals a genuine correction versus frustration or clarification.

When a correction is detected with enough confidence, the hook generates a candidate rule. That rule describes the behavioral change implied by the correction - in the same format as existing Claude Code rules.

But here's where it gets interesting: the rule doesn't go live immediately.

Self-Learning Architecture
Promotion Layer3 successful applications = permanent rule
Staging LayerNew rules quarantined until validated
Scoring LayerComposite confidence with bonuses and penalties
Detection Layer7 correction patterns with confidence weights (0.65-0.9)

The Staging Pipeline

Immediately promoting a correction to a permanent rule would be a mistake. A single frustrated "no" shouldn't reshape behavior forever. Context matters. Tone matters. Sometimes a correction is task-specific, not general.

So new rules get staged first.

A staged rule is applied in future sessions but tracked separately from permanent rules. The hook watches for each application - did Claude use this rule? Did the session proceed without another correction on the same topic? Three successful applications promote the rule to permanent status, where it joins the existing rule set without any staging overhead.

If a staged rule gets corrected again before reaching three successes, it gets discarded or revised. This filters out false positives without requiring manual review.

Correction-to-Rule Pipeline
User corrects Claude's behavior
v
Hook detects correction pattern (7 types)
v
Confidence score calculated (threshold: 60%)
v
New behavioral rule generated and STAGED
v
Rule applied in future sessions
v
After 3 successes: promoted to permanent

A Concrete Example

I was running a code review session. Claude picked Haiku for the task - fast, cheap, reasonable default. I typed: "no, use Sonnet for this, not Haiku."

The hook fired. It classified the message as an override command. The last turn was Claude's response - context bonus applied. Total confidence landed well above threshold.

The hook generated a staged rule: "Prefer Sonnet for code review tasks." That rule was added to the staging area.

Next code review session, the staged rule was active. Claude picked Sonnet without prompting. Session two, same. Session three, same. On the fourth session, the rule was promoted to permanent. I've never corrected that preference again.

One correction. One rule. Behavior changed permanently.

One correction. One rule. Behavior changed permanently.

Why This Is Different

Claude's built-in memory stores facts - things you've told it about yourself, your projects, your preferences. That's useful. But it stores information, not behavioral instructions.

This pipeline generates rules - explicit directives that change how Claude approaches tasks. "Robin prefers Sonnet" is a fact. "Prefer Sonnet for code review tasks" is a rule that changes Claude's decision-making process when selecting models.

The distinction matters because facts and rules operate at different levels. A fact tells Claude what I like. A rule changes what Claude does.

I built something similar for context drift in long sessions - a hook that injects relevant context mid-session when Claude's attention drifts. That hook reads the AI's reasoning. This hook reads my corrections. Both are feedback loops, but they operate on different signals: one monitors the AI, the other monitors me.

I looked for prior work while building this. Reflexion (2023) and Google's RL self-correction research both address in-session correction - the model corrects itself within a single context window. Neither generates persistent rules that survive session boundaries. The closest competing workflow tool has a learn-capture mechanism, but no staging or promotion system.

The staging pipeline is the piece I haven't seen elsewhere. It's what makes the system usable rather than just theoretically interesting.

The Before and After

Before the pipeline: five sessions, five corrections, five resets. Every preference I had that deviated from defaults was a tax I paid repeatedly.

After: I correct something once. A rule gets staged. Three sessions later, it's permanent. The correction is done.

The longer I run this system, the more personalized my Claude Code setup becomes - not because I'm manually writing rules, but because the corrections I make naturally during work are being captured and converted automatically. This pairs well with the broader hook automation system that handles everything from context management to delegation.

If you want to build your own correction pipeline - the full Python implementation, all 7 pattern types with their weights, the confidence scoring algorithm, and the staging/promotion system - that's part of Claude Code Mastery.

Want the full system blueprint? Get the free 3-pattern guide.

FAQ

What types of corrections does the hook detect?+
Seven pattern types, from explicit negation to alternative suggestions, wrong assumption corrections, override commands, too-much feedback, clarifications, and preference corrections. Each pattern carries a confidence weight between 0.65 and 0.9 based on how reliably it signals a genuine behavioral correction.
Why stage rules instead of applying them immediately?+
Staging prevents false positives. A single frustrated correction during a difficult debug session shouldn't create a permanent rule that changes behavior forever. The three-application threshold proves the correction reflects a real preference, not a one-off reaction. Rules that get corrected again before reaching three successes are discarded or revised automatically.
Does this work across different Claude Code sessions?+
Yes, that's the key innovation. Rules are persisted in the filesystem as standard Claude Code rule files. A correction you make today changes behavior in tomorrow's session and every session after. The hook reads staged and permanent rules at startup, so no session continuity is required.
How is this different from Claude's built-in memory features?+
Built-in memory stores facts. This pipeline generates behavioral rules - explicit instructions that change how Claude approaches decisions, not just what it knows about you. The distinction matters because rules are actionable in ways that facts are not. They change Claude's decision-making process, not just its knowledge.

>_ Get the free Claude Code guide

>_ No spam. Unsubscribe anytime.

>_ Related