recursive-handoff
Recursive Handoff
Run the same prompt repeatedly with fresh context until a finish condition is met.
When to Use
- Long-running tasks that would exhaust context
- Repetitive operations (process items one by one, migrate in batches)
- Polling/waiting for external state changes
- Any task where "keep doing X until Y" applies
Required Parameters
1. Finish Condition
You MUST get a finish condition from the user before starting.
The condition must be verifiable programmatically (file check, command output, grep result, API response, etc.)
Examples:
- "All files in
src/legacy/have been processed" - "No more TODO comments exist in the codebase"
- "The API returns status 200"
- "The queue is empty"
2. Hard Limit (default: 20)
Maximum iterations before stopping. Prevents runaway loops.
How It Works
┌─────────────────────────────────────────┐
│ Thread 1: Check condition → not met │
│ Do work → handoff │
└─────────────────┬───────────────────────┘
│
┌─────────────────▼───────────────────────┐
│ Thread 2: Check condition → not met │
│ Do work → handoff │
└─────────────────┬───────────────────────┘
│
┌─────────────────▼───────────────────────┐
│ Thread 3: Check condition → MET │
│ STOP (no handoff) │
└─────────────────────────────────────────┘
Each iteration:
- Check iteration count - stop if limit reached
- Check finish condition
- If met → stop, report completion
- If not met → do one unit of work → handoff to continue
The Handoff Prompt Template
RECURSIVE TASK - Iteration [N] of [LIMIT]
## Finish Condition
[CONDITION]
## How to Check
[COMMAND OR METHOD TO VERIFY CONDITION]
## If Limit Reached or Condition Met
Stop. Report: "✅ Complete: [summary]" or "⚠️ Limit reached after [N] iterations"
Do NOT handoff.
## If Condition NOT Met
### Task
[WHAT TO DO THIS ITERATION]
### After Completing Work
Handoff with follow: true, incrementing iteration count:
[PASTE THIS PROMPT WITH N+1]
Example: Generic Processing Loop
User: "Process all items in the queue"
Finish condition: Queue is empty
Handoff prompt:
RECURSIVE TASK - Iteration 1 of 20
## Finish Condition
Queue is empty
## How to Check
[command to check queue length]
If result is 0, condition is met.
## If Limit Reached or Condition Met
Stop. Report completion status.
Do NOT handoff.
## If Condition NOT Met
### Task
1. Get next item from queue
2. Process it
3. Remove from queue
### After Completing Work
Handoff with follow: true, goal:
[THIS PROMPT WITH ITERATION 2 of 20]
Starting the Loop
Once setup is complete, invoke handoff with follow: true:
handoff
goal: [THE FULL HANDOFF PROMPT]
follow: true
The loop continues autonomously until finish condition is met or limit is reached.
More from sebastiaanwouters/dotagents
flyctl
Deploy and manage apps on Fly.io using flyctl CLI. Triggers on: fly deploy, fly.io, flyctl, deploy to fly. Handles launch, deploy, scale, secrets, volumes, databases.
79teacher
Guide learning and deep understanding through proven methodologies (Socratic, Feynman, Problem-Based). Use when user says "help me understand", "teach me", "explain this", "learn about", "socratic", "feynman", "problem-based", "I don't understand", "confused about", "why does", or wants to truly grasp a concept.
77chef
Telegram communication for AI agents. ALL methods are BLOCKING. Use for user interviews, status updates, and feedback collection.
34bitwarden
Retrieves API keys, passwords, secrets from Bitwarden vault using bw CLI. Triggers on missing env variables, missing API keys, missing secrets, "secret not found", "env not set", or "use bw".
29librarian
Use for code research that needs dependency internals, upstream implementation examples, or external prior art. Always delegate to a subagent that investigates with opensrc and web search, then return only distilled findings, versions, paths, and links.
28frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications. Generates creative, polished code that avoids generic AI aesthetics.
28