Ralph's Infinite Loop

Mission: Code the Uncodable without losing your mind.
Level 1: The Problem

The Context Trap

Meet Agent Ralph. Ralph is a brilliant AI coder. But Ralph has a weakness: his "Context Window" (short-term memory) is limited.

Normally, when you chat with an AI, you keep adding history. This causes Context Rot. As the history gets full, the AI gets confused, lazy, or starts hallucinating.

Ralph's Brain Capacity 0%
🤖
"Ready to code! Send instructions."

Objective: Overload Ralph. Keep asking him to code until he breaks.

Level 2: The Mechanic

The Reset Loop

Most tools try to "summarize" old messages to save space. But summarizing code loses critical details (variable names, imports). This causes bugs.

The Ralph Loop takes a radical approach: Don't summarize. Die and Reincarnate.

Instead of one long conversation, we run a bash script that creates a fresh agent for every single step.

The Sacred Scroll (Bash Script)

while true; do # 1. Feed the prompt to a FRESH agent cat PROMPT.md | claude-code # 2. Agent works until it exits # 3. Check if done if grep -q "DONE" status.txt; then break fi # 4. RESTART (Loop) echo "Reincarnating Ralph..." done

Interact: Change the input variable. Notice how the script stays outside the AI? The AI doesn't control the loop. The Loop controls the AI.

Level 3: External Memory

If Ralph dies, how does he remember?

If we reset Ralph every time, he forgets what he just coded. We need External Memory.

We don't use chat history. We use Files.

📄 prd.json (The Plan)

{ "task": "Build Login", "status": "TODO", "next_step": "Create form" }

📝 progress.txt (The Diary)

[LOG] Starting project...

Training Simulation: You are the Agent. Complete a task step, save it to disk, then die.

Current State: Fresh Instance

Level 4: The Simulation

The Infinite Loop in Action

Let's put it all together. You are the Orchestrator (The Bash Loop).

We have a project with 4 tasks. Watch how Ralph wakes up, reads the files to understand context, does one task, saves, and dies. Then repeats.

Task List (prd.json)

  • ⬜ 1. Setup Repo
  • ⬜ 2. Create Database
  • ⬜ 3. Build API
  • ⬜ 4. Write Tests

Current Context Load

0 / 100 Tokens

Terminal Output

Waiting to start loop...