Execute work plans with iteration loops and progress tracking
/plugin marketplace add settlemint/agent-marketplace/plugin install crew@settlemint[plan] [--loop] [--max-iterations N]<worktree_status>
!${CLAUDE_PLUGIN_ROOT}/scripts/git/worktree-context.sh
</worktree_status>
<stack_context>
!${CLAUDE_PLUGIN_ROOT}/scripts/git/machete-context.sh
</stack_context>
Load patterns skill first:
Skill({ skill: "crew:crew-patterns" });
This provides: <pattern name="test-runner"/>, <pattern name="spawn-batch"/>, <pattern name="collect-results"/>, <pattern name="todo-progress"/>, <pattern name="task-file"/>, <pattern name="quality-agents"/>, <pattern name="branch-state"/>.
<build_context>
!${CLAUDE_PLUGIN_ROOT}/scripts/workflow/build-context.sh
</build_context>
<loop_mode>
Enabled with --loop flag. Stop hook re-feeds prompt until completion.
State file: .claude/branches/{slugified-branch}/state.json
See <pattern name="branch-state"/> for format.
Completion criteria (ALL required):
*-pending-* → *-complete-*bun run ci passesbun run test:integration passes<promise>BUILD COMPLETE</promise>Cancel: /crew:cancel-loop "reason"
</loop_mode>
<process> <phase name="init-loop"> If `--loop` flag present:const stateFile = `.claude/branches/${slugBranch}/state.json`;
// Check existing state for resume
// If new: initialize loop state with iteration=1
// If resuming: log iteration number, check task files for progress
</phase>
<phase name="load-work">
```javascript
Read({ file_path: ".claude/plans/${planSlug}.md" });
// If not found: AskUserQuestion for plan selection
```
Use `<pattern name="todo-progress"/>` to track.
</phase>
<phase name="branch-setup">
```javascript
const branch = Bash({ command: "git branch --show-current" }).trim();
if (branch === "main" || branch === "master") {
// AskUserQuestion: feature branch or stacked branch
Bash({ command: `git checkout -b feat/${planSlug}` });
}
// If stacked: git machete add --onto <parent>
```
</phase>
<phase name="load-tasks">
```javascript
const slugBranch = branch.replace(/\//g, "-");
const taskFiles = Glob({ pattern: `.claude/branches/${slugBranch}/tasks/*.md` });
// Group by: phase (setup/found/us1/us2/polish), parallel capability, status
// Create execution plan: parallel tasks in batches of max 6
```
</phase>
<phase name="batch-execution">
For each batch of parallel tasks:
<pattern name="spawn-batch"/> - ALL in single message<pattern name="collect-results"/>*-pending-* → *-complete-*<pattern name="test-runner"/>Batch order: setup → found → us1 → us2 → polish </phase>
<phase name="quality-checks"> Launch quality agents using `<pattern name="quality-agents"/>`.// Collect results, triage by severity (P0/P1/P2)
// Add P0/P1 findings as new task files in current branch
</phase>
<phase name="final-validation">
**MANDATORY: Fix ALL issues, even unrelated ones.**
Use the Bash subagent for final validation (runs in separate context, no output pollution):
Task({
subagent_type: "Bash",
prompt: `Run final validation and report results:
1. Run CI: bun run ci
2. Run integration tests: bun run test:integration
3. Report:
- If both pass: "VALIDATION PASSED"
- If failures: List each error with file:line
The Bash subagent handles large output in its own context.`,
description: "final-validation",
run_in_background: false,
});
Loop until BOTH pass with zero errors. </phase>
<phase name="persist-learnings"> **Save significant learnings to claude-mem (if available):**For discoveries made during the build, persist to cross-session memory:
// Types to persist:
// 🔴 Gotcha: Edge case that broke assumptions
// 🟤 Decision: Architectural choice with rationale
// 🟣 Discovery: Non-obvious insight learned
// 🟡 Problem-solution: Fix that should be remembered
// Example: If a test failure revealed an undocumented API behavior
// Save it so future builds don't re-discover the same gotcha
CRITICAL - What to Persist:
What NOT to Persist:
Skip if: No claude-mem MCP available or no significant learnings. </phase>
<phase name="completion"> ```javascript const pending = Glob({ pattern: `.claude/branches/${slugBranch}/tasks/*-pending-*.md` });if (pending.length === 0 && ciPassing && integrationPassing) { // Clear loop state if active // Output completion console.log("<promise>BUILD COMPLETE</promise>"); } else { // Log remaining tasks // If loop mode: /compact then Stop hook re-feeds }
</phase>
</process>
<task_prompt_template>
Agent prompts must follow this format:
TASK: ${id} - ${title} FILE: ${file_path} ACCEPTANCE: ${criteria} CONSTRAINTS:
</task_prompt_template>
<success_criteria>
- [ ] TodoWrite updated after EVERY task
- [ ] All agents in batch launched in SINGLE message
- [ ] Task files renamed immediately on completion
- [ ] CI passes per @rules/ci-requirements.md
- [ ] Loop mode: `<promise>BUILD COMPLETE</promise>` when ALL criteria met
</success_criteria>