Most looping agents have amnesia. Each cycle starts fresh, so they retry the same failed fix three times because nothing remembers it already didn't work.

A learning agent keeps a journal: after every attempt it writes down what it tried and whether it worked, then reads that journal before the next attempt.
Set it up once and the loop stops repeating itself. Each pass starts from what the last one learned instead of from zero.
Here's the full setup you needπ
Before we dive in, I share daily notes on AI & vibe coding in my Telegram channel: https://t.me/zodchixquantπ§

## Why loops repeat themselves
A normal loop runs the same agent on the same problem again and again, but the agent's memory resets between cycles. It doesn't know cycle 2 already tried the thing it's about to try in cycle 4.
So it loops in circles, swapping the same library, reverting, swapping it back, burning tokens rediscovering dead ends. The loop runs, but it doesn't learn.
The fix is memory that survives between cycles: a journal the agent writes to and reads from every pass.

## File 1: the journal
This is the memory. A plain file the agent appends to, never overwrites. Create .claude/loop-journal.md:
# Loop journal
Append-only. Each attempt: what was tried, the result, the lesson.
## Task: fix failing checkout test
### Attempt 1
Tried: added await to the fetchCart call.
Result: still failed, same error.
Lesson: the race isn't in fetchCart. Look upstream at the cart state.
### Attempt 2
Tried: memoized the cart selector.
Result: failed differently now, cart is undefined on first render.
Lesson: memoization changed timing. The real issue is initial state.The journal is dead simple on purpose. Every entry is three lines: what was tried, what happened, and the lesson for next time.
The lesson line is the gold, it's what stops the next cycle from repeating the attempt.---
## File 2: the learning loop
This is the orchestrator, and the one rule that makes it learn: read the journal first.
Drop into .claude/commands/learn-loop.md:
---
description: Run a task in a loop that learns from a journal each pass
argument-hint: <task>
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
model: sonnet
---
Task: $ARGUMENTS
Each cycle:
1. Read .claude/loop-journal.md fully. Note what was already
tried and what was learned. Never repeat a failed attempt.
2. Form a new hypothesis that the journal doesn't rule out.
3. Make the change. Run the check.
4. Append to the journal: what you tried, the result, the lesson.
5. Passed: stop, summarize what worked. Failed: go to step 1.
6. Cap at 6 cycles.
The rule: every cycle must try something the journal hasn't.
If you can't think of one, say so and stop. That's not failure,
that's the journal telling you to get a human.
Generated by Thread Navigator
Press β + S to quick-export
