Kaaiser Loop

Start KAAISER autonomous iteration loop with optional PRD-driven task management

CuervoDoesIt updated 6mo ago
Claude CodeGeneric
View source ↗
---
name: kaaiser-loop
description: Start KAAISER autonomous iteration loop with optional PRD-driven task management
arguments: [<prompt>] [--prd <prd-path>] [--max-iterations N] [--completion-promise TEXT] [--domain DOMAIN] [--phase PHASE]
allowed_tools: ["Bash", "Read", "Write", "Edit", "Glob", "Grep", "TodoWrite"]
mode: bypassPermissions
---

# KAAISER Loop - Knowledge-Aware Adaptive Iteration with Extended Reasoning

Enhanced autonomous coding loop with:
- **PRD Integration**: Virtual kanban board for structured task management
- **Adaptive Prompts**: Context-aware prompts that evolve with each iteration
- **Reflection Memory**: Learn from failures across iterations and sessions
- **Pattern Learning**: Cross-session strategies for common error types

## Arguments

**Input**: $ARGUMENTS

Parse the arguments:
- `prompt`: The main task/goal (if not using PRD mode)
- `--prd <path>`: Path to PRD JSON file (enables PRD-driven mode, default: `.claude/prd.json`)
- `--max-iterations N`: Maximum iterations (default: 10, max: 50)
- `--completion-promise TEXT`: Custom completion marker (default: "DONE")
- `--domain DOMAIN`: Task domain for pattern matching (e.g., "web", "api", "cli")
- `--phase PHASE`: Current phase (e.g., "setup", "implement", "test")

## Operating Modes

### Mode 1: PRD-Driven (Recommended)

When `--prd` is provided or `.claude/prd.json` exists:

1. Load PRD and display kanban status
2. Automatically select highest-priority task with met dependencies
3. Work through tasks, marking each complete with `<task-done id="..."/>`
4. Continue until all tasks are done or max iterations reached

**Start with PRD**:

/kaaiser-loop --prd .claude/prd.json --max-iterations 30


### Mode 2: Goal-Driven (Simple)

When only a prompt is provided:

1. Work toward the single goal
2. Mark complete with `<done/>` when finished

**Start with goal**:

/kaaiser-loop "Create an Express server with user authentication" --max-iterations 10


## Instructions

### Step 1: Parse Arguments and Determine Mode

Check if `--prd` flag is present or if `.claude/prd.json` exists.

### Step 2: Initialize State

Create the state file at `.claude/kaaiser-loop.state.json`:

```json
{
  "active": true,
  "sessionId": "<generate-unique-id>",
  "iteration": 0,
  "maxIterations": <parsed or 10>,
  "goal": "<prompt or PRD title>",
  "completionPromise": "<parsed or DONE>",
  "domain": "<parsed or null>",
  "phase": "<parsed or null>",
  "startedAt": "<ISO timestamp>",
  "consecutiveFailures": 0,
  "progressMarkers": [],
  "prdPath": "<path if PRD mode>",
  "currentTaskId": null,
  "taskIterationStart": null
}

Step 3: Display Initial Status (PRD Mode)

If in PRD mode, display the kanban board showing:

  • All phases and tasks
  • Current status of each task
  • Which task will be worked on first

Step 4: Begin First Iteration

Start working on:

  • PRD Mode: The first eligible task (highest priority, dependencies met)
  • Goal Mode: The provided goal

Critical Rules

Progress Tracking

Report progress with:

<progress>What you accomplished this iteration</progress>

Error Reporting

When errors occur, wrap them:

<error>
Error message and stack trace here
</error>

Then provide a reflection:

{
  "errorType": "specific_error_category",
  "severity": "low|medium|high|critical",
  "rootCause": "Clear explanation",
  "whatToAvoid": ["failed approaches"],
  "potentialFixes": ["strategies to try"],
  "fixApplied": "which fix you're applying"
}

Task Completion (PRD Mode)

When a task is complete:

<task-done id="p1-t1">Optional notes about completion</task-done>

The hook will:

  1. Mark the task as done in the PRD
  2. Select the next eligible task
  3. Continue the loop

Full Completion

When ALL work is done:

<done/>

The Hook Handles Everything

The stop hook at .claude/hooks/stop/kaaiser-loop.ts automatically:

  • Detects <done/> → Cleans up and stops
  • Detects <task-done> → Updates PRD, selects next task
  • Detects <error> → Extracts for reflection prompts
  • Increments iteration and injects learnings
  • Builds adaptive prompts with kanban view

Example Workflow

User: /kaaiser-loop --prd .claude/prd.json --max-iterations 20

Claude: [Reads PRD, shows kanban]

📋 PRD: E-Commerce Platform [0%]

⏳ Phase 1: Core Setup
  ⬚ 🔴 p1-t1: Initialize project
  ⬚ 🟡 p1-t2: Configure database

⏳ Phase 2: Features
  ⬚ 🔴 p2-t1: User auth
  ⬚ 🟡 p2-t2: Dashboard

Starting with task p1-t1: Initialize project...

[Works on task]

<progress>Created package.json and installed dependencies</progress>
<task-done id="p1-t1">Project initialized with TypeScript config</task-done>

[Hook detects, updates PRD, continues to p1-t2]

...continues until all done or max iterations...

<done/>

Now parse "$ARGUMENTS" and begin the KAAISER loop! ```

Maintain Kaaiser Loop?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Kaaiser Loop on getagentictools](https://getagentictools.com/loops/cuervodoesit-kaaiser-loop-knowledge-aware-adaptive-iteration-with-extended-reaso?ref=badge)
npx agentictools info loops/cuervodoesit-kaaiser-loop-knowledge-aware-adaptive-iteration-with-extended-reaso

The second line is the CLI lookup for this page — handy in READMEs and docs.