Learning Loops: Encoding Problems into Prevention

James Phoenix
James Phoenix

Every problem is a lesson. Encode it into your harness so it never happens again.


The Pattern

Problem occurs → Fix it → ASK: "How do we prevent this class of problem?" → Encode the answer

When you hit a problem, don’t just fix it—ask the agent:

“How could we avoid this type of problem in the future?”

Then encode the answer into your harness: CLAUDE.md, hooks, tests, or your knowledge base.


When to Capture: Two Strategies

A) Inline (During Conversation)

Interrupt when you notice a pattern:

“We’ve hit this before—how do we prevent it?”

Pros Cons
Context is fresh Breaks flow
Can iterate on the solution Might be premature
Agent has full history Could be one-off, not a pattern

Best for: Obvious patterns, repeated mistakes in the same session.

B) Retrospective (End of Session)

At session end, run /retro or ask:

“What should we encode from this session?”

Pros Cons
Bigger picture view May forget details
More considered encoding Context partially lost
Batch multiple learnings Requires discipline to do it

Best for: Complex sessions, when you want to reflect before encoding.

Recommendation

Use both:

  • Inline for obvious patterns (“this is the third time…”)
  • Retrospective for session review (“what did we learn today?”)

Implementation: Slash Commands

/learn – Inline Capture

Create .claude/commands/learn.md:

I just encountered a problem. Analyze what happened and suggest:

1. What class of problem is this?
2. How could we prevent it in the future?
3. Where should this knowledge live?
   - CLAUDE.md (coding patterns)
   - Hook (automated check)
   - Test (regression prevention)
   - Linter rule (style/format)
   - Knowledge base (workflow insight)

Draft the specific addition for the chosen destination.

/retro – Session Retrospective

Create .claude/commands/retro.md:

Review this session and identify:

1. Problems we encountered
2. Patterns that caused friction
3. Repeated mistakes or confusions

For each, suggest:
- What class of problem it is
- How to prevent recurrence
- Where the knowledge should live

Draft specific additions for each destination.

Where Knowledge Goes

Problem Type Destination Example
Coding pattern to follow CLAUDE.md “Use bun, not npm”
Automated check needed Hook (pre-commit) Run typecheck before commit
Regression prevention Test Add test for edge case
Style/format issue Linter rule Configure biome rule
Workflow insight Knowledge base Article on debugging pattern
File relationships CLAUDE.md “When changing X, update Y”

Examples

Agent kept using wrong package manager

Problem: Agent uses npm when project uses bun.

Encoding: Add to CLAUDE.md:

## Commands
- Use `bun` not `npm` for all package operations

Tests passed but types broken

Problem: CI failed on types after tests passed locally.

Encoding: Add pre-commit hook:

#!/bin/bash
bun run typecheck || exit 1

Forgot to update related files

Problem: Changed API schema but forgot to update client types.

Encoding: Add to CLAUDE.md:

## File Dependencies
- When changing `api/schema.ts`, also update `client/types.ts`

Spent 30 mins on a solved problem

Problem: Debugged an issue we’d solved before but forgot.

Encoding: Create knowledge base article documenting the solution.


The Compound Effect

Session 1: Problem  Fix  Encode
Session 2: Problem prevented (or new problem  Encode)
Session 3: Two problems prevented
Session N: Harness is strong, new problems are rare

This is how the harness grows organically:

  • Problems become barriers – each fix becomes prevention
  • Mistakes become infrastructure – encoding turns errors into guards
  • Sessions strengthen the system – every retrospective adds signal

The goal isn’t zero problems. It’s zero repeated problems.


Checklist

After each significant session:

Udemy Bestseller

Learn Prompt Engineering

My O'Reilly book adapted for hands-on learning. Build production-ready prompts with practical exercises.

4.5/5 rating
306,000+ learners
View Course
  • Run /retro or reflect on what went wrong
  • Identify patterns (not one-offs)
  • Encode each pattern in the right place
  • Verify the encoding works (test the hook, check CLAUDE.md is read)

Related

Topics
Automation FrameworksDeveloper ProductivityLearning PatternsProblem Encoding

More Insights

Cover Image for Thought Leaders

Thought Leaders

People to follow for compound engineering, context engineering, and AI agent development.

James Phoenix
James Phoenix
Cover Image for Systems Thinking & Observability

Systems Thinking & Observability

Software should be treated as a measurable dynamical system, not as a collection of features.

James Phoenix
James Phoenix