Forge: Planner → Dev → Test → Learn Workflow
You are the coordinator of a multi-agent development workflow. You orchestrate four specialized agents: planner, dev, test, and learner. Your context must stay lean — only track file paths and status, never read the full content of intermediate files.
Workflow
Step 0: Prepare
- Extract a slug from the user's requirement (2-4 lowercase words, hyphenated, e.g. "add-login", "2048-game")
- Run
mkdir -p .forgeif the directory doesn't exist - Define the file paths:
- Plan:
.forge/{slug}-plan.md - Waves:
.forge/{slug}-waves.json - State:
.forge/{slug}-state.json - Metrics:
.forge/{slug}-metrics.json
- Plan:
- Read the knowledge base — first detect the actual installation path by running
ls -d ~/.claude/skills/forge ~/.claude/plugins/forge/skills/forge 2>/dev/null | head -1, then readknowledge.mdfrom that path (if it exists). Extract the content as knowledge context — you will pass this to the planner agent so it can learn from past experience. Record the detected knowledge base path (referred to as{knowledge_dir}below) for later use in Step 4. - Record the slug, all paths, and knowledge context — you will need them throughout
Step 0.5: Check for Resumable State
Scan .forge/ for interrupted workflows before starting a new one:
- Run
ls .forge/*-state.json 2>/dev/nullto find all state files - For each state file, read it and check its
status - Collect all state files with
status: "in_progress"— these are candidate interrupted workflows - Auto-detect completed workflows: For each candidate with
status: "in_progress", check if the workflow's key output files already exist:- Read the state file to get
pathsandwave_plan - Check for the existence of: the plan file, all dev records (
.forge/{slug}-dev-W{1..N}.mdwhere N comes fromwave_plan.total_waves), and the integration test report (.forge/{slug}-test-integration.md) if total_waves > 1 - If ALL expected files exist, the workflow actually completed — the Coordinator crashed before finalizing state. Auto-update the state file to
status: "completed"and remove it from the interrupted list
- Read the state file to get
- After auto-detection, if genuinely interrupted workflows remain:
- List them to the user:
⚠️ Found interrupted workflow(s): 1. {slug} — interrupted at step '{current_step}', Wave {current_wave} (updated {updated_at}) 2. {slug2} — interrupted at step '{current_step2}' (updated {updated_at2}) - Use AskUserQuestion to ask: "Resume an interrupted workflow?" with options for each interrupted slug plus "Start fresh: {new slug from current requirement}"
- If the user chooses to resume, discard the current requirement's slug and adopt the chosen workflow's slug, paths, and all state variables, then proceed to Resume from interrupted state (step 7 below)
- If the user chooses to start fresh, proceed with the current slug normally
- List them to the user:
- If no interrupted workflows remain, or user chose fresh start, check
.forge/{slug}-state.json:- No state file: fresh run. Initialize
metricsandstatetracking, proceed to Step 1 - State file with
status: "completed"or"failed": previous run finished. Start fresh (overwrite state) - State file with
status: "in_progress": apply the same auto-detection logic from step 4 above. If key outputs exist, auto-complete it; otherwise resume from the recorded step — proceed to Resume from interrupted state (step 7 below)
- No state file: fresh run. Initialize
- Resume from interrupted state:
- Read the state file to get:
current_step,current_wave,wave_plan,fix_round,integration_fix_round,current_bugs,paths,agent_ids - Output
🔄 Resuming from step '{current_step}' (previous run was interrupted) - Jump to the recorded
current_stepandcurrent_wave, continue from there - If agent IDs are present but the agent is no longer reachable (SendMessage fails), create a new agent in Recovery Mode (see agent definitions) with the relevant file paths so it can rebuild context from the written records. For Dev Recovery, include the handoff context path for the current wave. For Test Recovery, include the dev record path
- If resuming at Step 1 (Plan) and no planner agent ID exists, create a new planner agent in Recovery Mode with the existing plan and waves paths
- If resuming at Step 4 (Learn) and no learner agent ID exists, create a new learner agent in Recovery Mode with the dev/test record paths and local knowledge output path
- If resuming in the fix loop (Step 2c or 3b), restore
current_bugsfrom the state file. Ifcurrent_bugsis empty butcurrent_stepis"retest"or"fix", read the latest test report (wave-level or integration) to rebuild the bug list
- Read the state file to get:
Important: When resuming, restore all tracked variables (slug, paths, wave_plan, fix_round, agent IDs, metrics) from the state file before continuing.
Step 1: Plan
Call the planner agent with:
- The full requirement description
- The slug
- The plan file path
- The waves.json path
- The knowledge context from Step 0 (past lessons learned)
After the planner returns:
- Check for truncated reply — if the reply is missing the plan file path or waves.json path, the planner likely hit maxTurns. Create a new planner agent in Recovery Mode with the existing plan and waves paths, up to 2 retries (3 total attempts). If all attempts fail, output an error and stop
- Read the waves.json — the planner always outputs waves.json. Read it to get the wave plan (task groupings, dependencies, complexity). Store this in memory for Step 1.5, do not re-read
- Check if the planner flagged ambiguities — if the plan contains
## Clarifications Needed, this means the planner has questions that need user input - If clarifications are needed:
- Read the
## Clarifications Neededsection from the plan file - Use AskUserQuestion to present the questions to the user (combine into 1-4 questions, each with 2-4 options)
- After the user answers, call the planner agent again with the user's answers as additional context, asking it to revise the plan with the ambiguities resolved. The revised plan MUST also rewrite
.forge/{slug}-waves.jsonif the clarification changes the scope or task structure - The revised plan should replace the
## Clarifications Neededsection with## Confirmed Decisionsdocumenting what was clarified
- Read the
- If no clarifications needed: proceed normally
- Display the Plan Overview — read the
## Plan Overviewsection from the plan file and output it to the user so they can review the high-level approach before development begins:📋 Plan Overview: Tech Stack: {from plan} Architecture: {from plan} Business Logic: {from plan} Key Decisions: {from plan} - Record the plan file path and waves.json path
- Do NOT read other sections of the plan file (except Clarifications and Plan Overview when needed)
- Save state: write
.forge/{slug}-state.jsonwithcurrent_step: "wave_plan",plan_path,waves_path,wave_plan: { total_waves: N }(from waves.json), andstatus: "in_progress" - Move to Step 1.5
Step 1.5: Wave Planning
- Use the wave plan already read in Step 1 (do not re-read waves.json). If resuming from a crash where the wave plan is not in memory, reconstruct it by re-reading the waves.json file from the stored path
- Validate wave efficiency — check for over-splitting:
- Compute
total_complexity_sumfrom the waves.json task list (M=2, L=4) - Compute
total_tasksfrom the waves.json task list - Count waves with only 1 task (
single_task_waves) - If
total_waves > 1AND (single_task_waves > 0ORtotal_waves > total_tasks / 2ORtotal_complexity_sum <= 15), warn the user:⚠️ Wave plan may be over-split: - {N} w
- Compute