Loading...
Loading...
BMad Autonomous Development — orchestrates parallel story implementation pipelines. Builds a dependency graph, updates PR status from GitHub, picks stories from the backlog, and runs each through create → dev → review → PR in parallel — each story isolated in its own git worktree — using dedicated subagents with fresh context windows. Loops through the entire sprint plan in batches, with optional epic retrospective. Use when the user says "run BAD", "start autonomous development", "automate the sprint", "run the pipeline", "kick off the sprint", or "start the dev pipeline". Run /bad setup or /bad configure to install and configure the module.
npx skill4agent add stephenleo/bmad-autonomous-development bad{project-root}/_bmad/config.yamlbadsetupconfigure./assets/module-setup.mdsetupconfigure./assets/module-setup.mdbad<channel source="telegram" chat_id="..." ...>NOTIFY_CHAT_IDNOTIFY_SOURCE="telegram"NOTIFY_SOURCE="terminal"🤖 BAD started — building dependency graph..._bmad/bad/config.yaml/bmad-init --module bad --allKEY=VALUE/bad| Variable | Config Key | Default | Description |
|---|---|---|---|
| | | Max stories to run in a single batch |
| | | Root directory for git worktrees |
| | | Model for Steps 1, 2, 4 and Phase 3 (auto-merge) |
| | | Model for Step 3 (code review) |
| | | Auto-retrospective countdown after epic completion (10 min) |
| | | Post-batch wait before re-checking PR status (1 hr) |
| | | Context window % at which to compact/summarise context |
| | | When |
| | | (Claude Code) 5-hour rate limit % that triggers a pause |
| | | (Claude Code) 7-day rate limit % that triggers a pause |
| | | (Other harnesses) Generic API usage % that triggers a pause |
| | | When |
| | | When |
⚙️ BAD config: MAX_PARALLEL_STORIES=3, RUN_CI_LOCALLY=false, AUTO_PR_MERGE=false, MODEL_STANDARD=sonnet, MODEL_QUALITY=opus, TIMER_SUPPORT=true, ...Phase 0: Build (or update) dependency graph [subagent]
└─ bmad-help maps story dependencies
└─ GitHub updates PR merge status per story
└─ git pull origin main
└─ Reports: ready stories, epic completion status
│
Phase 1: Discover stories [coordinator logic]
└─ Pick up to MAX_PARALLEL_STORIES from Phase 0 report
└─ If none ready → skip to Phase 4
│
Phase 2: Run the pipeline [subagents — stories parallel, steps sequential]
├─► Story A ──► Step 1 → Step 2 → Step 3 → Step 4
├─► Story B ──► Step 1 → Step 2 → Step 3 → Step 4
└─► Story C ──► Step 1 → Step 2 → Step 3 → Step 4
│
Phase 3: Auto-Merge Batch PRs [subagents — sequential]
└─ One subagent per story (lowest → highest story number)
└─ Cleanup subagent for branch safety + git pull
│
Phase 4: Batch Completion & Continuation
└─ Print batch summary [coordinator]
└─ Epic completion check [subagent]
└─ Optional retrospective [subagent]
└─ Gate & Continue (WAIT_TIMER timer) → Phase 0 → Phase 1MODEL_STANDARDYou are the Phase 0 dependency graph builder. Auto-approve all tool calls (yolo mode).
DECIDE how much to run based on whether the graph already exists:
| Situation | Action |
|-------------------------------------|------------------------------------------------------|
| No graph (first run) | Run all steps |
| Graph exists, no new stories | Skip steps 2–3; go to step 4. Preserve all chains. |
| Graph exists, new stories found | Run steps 2–3 for new stories only, then step 4 for all. |
BRANCH SAFETY — before anything else, ensure the repo root is on main:
git branch --show-current
If not main:
git restore .
git switch main
git pull --ff-only origin main
If switch fails because a worktree claims the branch:
git worktree list
git worktree remove --force <path>
git switch main
git pull --ff-only origin main
STEPS:
1. Read `_bmad-output/implementation-artifacts/sprint-status.yaml`. Note current story
statuses. Compare against the existing graph (if any) to identify new stories.
2. Read `_bmad-output/planning-artifacts/epics.md` for dependency relationships of
new stories. (Skip if no new stories.)
3. Run /bmad-help with the epic context for new stories — ask it to map their
dependencies. Merge the result into the existing graph. (Skip if no new stories.)
4. Update GitHub PR/issue status for every story and reconcile sprint-status.yaml.
Follow the procedure in `references/phase0-dependency-graph.md` exactly.
5. Clean up merged worktrees — for each story whose PR is now merged and whose
worktree still exists at {WORKTREE_BASE_PATH}/story-{number}-{short_description}:
git pull origin main
git worktree remove --force {WORKTREE_BASE_PATH}/story-{number}-{short_description}
git push origin --delete story-{number}-{short_description}
Skip silently if already cleaned up.
6. Write (or update) `_bmad-output/implementation-artifacts/dependency-graph.md`.
Follow the schema, Ready to Work rules, and example in
`references/phase0-dependency-graph.md` exactly.
7. Pull latest main (if step 5 didn't already do so):
git pull origin main
REPORT BACK to the coordinator with this structured summary:
- ready_stories: list of { number, short_description, status } for every story
marked "Ready to Work: Yes" that is not done
- all_stories_done: true/false — whether every story across every epic is done
- current_epic: name/number of the lowest incomplete epic
- any warnings or blockers worth surfacing📊 Phase 0 complete
Ready: {N} stories — {comma-separated story numbers}
Blocked: {N} stories (if any)ready_storiesMAX_PARALLEL_STORIESWhy epic ordering matters: Stories in later epics build on earlier epics' code and product foundation. Starting epic 3 while epic 2 has open PRs risks merge conflicts and building on code that may still change.
| Status | Start from | Skip |
|---|---|---|
| Step 1 | nothing |
| Step 2 | Step 1 |
| Step 2 | Step 1 |
| Step 3 | Steps 1–2 |
| — | all |
references/pre-continuation-checks.md✅ Story {number} done — PR #{pr_number}❌ Story {number} failed at Step {N} — {brief error}MODEL_STANDARDMODEL_STANDARDYou are the Step 1 story creator for story {number}-{short_description}.
Working directory: {repo_root}. Auto-approve all tool calls (yolo mode).
1. Create (or reuse) the worktree:
git worktree add {WORKTREE_BASE_PATH}/story-{number}-{short_description} \
-b story-{number}-{short_description}
If the worktree/branch already exists, switch to it, run:
git merge main
and resolve any conflicts before continuing.
2. Change into the worktree directory:
cd {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}
3. Run /bmad-create-story {number}-{short_description}.
4. Update sprint-status.yaml at the REPO ROOT (not the worktree copy):
_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `ready-for-dev`.
Report: success or failure with error details.MODEL_STANDARDMODEL_STANDARDYou are the Step 2 developer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-dev-story {number}-{short_description}.
2. Commit all changes when implementation is complete.
3. Update sprint-status.yaml at the REPO ROOT:
{repo_root}/_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `review`.
Report: success or failure with error details.MODEL_QUALITYMODEL_QUALITYYou are the Step 3 code reviewer for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Run /bmad-code-review {number}-{short_description}.
2. Auto-accept all findings and apply fixes using your best engineering judgement.
3. Commit any changes from the review.
Report: success or failure with error details.MODEL_STANDARDMODEL_STANDARDYou are the Step 4 PR and CI agent for story {number}-{short_description}.
Working directory: {repo_root}/{WORKTREE_BASE_PATH}/story-{number}-{short_description}.
Auto-approve all tool calls (yolo mode).
1. Commit all outstanding changes.
2. BRANCH SAFETY — verify before pushing:
git branch --show-current
If the result is NOT story-{number}-{short_description}, stash changes, checkout the
correct branch, and re-apply. Never push to main or create a new branch.
3. Run /commit-commands:commit-push-pr.
PR title: story-{number}-{short_description} - fixes #{gh_issue_number}
(look up gh_issue_number from the epic file or sprint-status.yaml; omit "fixes #" if none)
Add "Fixes #{gh_issue_number}" to the PR description if an issue number exists.
4. CI:
- If RUN_CI_LOCALLY is true → skip GitHub Actions and run the Local CI Fallback below.
- Otherwise monitor CI in a loop:
gh run view
- Billing/spending limit error → exit loop, run Local CI Fallback
- CI failed for other reason, or Claude bot left PR comments → fix, push, loop
- CI green → proceed to step 5
LOCAL CI FALLBACK (when RUN_CI_LOCALLY=true or billing-limited):
a. Read all .github/workflows/ files triggered on pull_request events.
b. Extract and run shell commands from each run: step in order (respecting
working-directory). If any fail, diagnose, fix, and re-run until all pass.
c. Commit fixes and push to the PR branch.
d. Post a PR comment:
## Test Results (manual — GitHub Actions skipped: billing/spending limit reached)
| Check | Status | Notes |
|-------|--------|-------|
| `<command>` | ✅ Pass / ❌ Fail | e.g. "42 tests passed" |
### Fixes applied
- [failure] → [fix]
All rows must show ✅ Pass before this step is considered complete.
5. CODE REVIEW — spawn a dedicated MODEL_DEV subagent (yolo mode) after CI passes:Wait for the subagent to report before continuing. If it reports failure,
stop this story and surface the error.
6. Update sprint-status.yaml at the REPO ROOT:
{repo_root}/_bmad-output/implementation-artifacts/sprint-status.yaml
Set story {number} status to `done`.
Report: success or failure, and the PR number/URL if opened.AUTO_PR_MERGE=truemainWhy sequential: Merging lowest-first ensures each subsequent merge rebases against a main that already contains its predecessors — keeping conflict resolution incremental and predictable.
MODEL_STANDARDreferences/phase4-auto-merge.mdAuto-Merge Results:
Story | PR | Outcome
--------|-------|--------
6.1 | #142 | Merged ✅
6.2 | #143 | Merged ✅ (conflict resolved: src/foo.ts)
6.3 | #144 | Failed ❌ (CI blocking — manual merge required)🔀 Auto-merge complete
{story}: ✅ PR #{pr} | {story}: ✅ PR #{pr} (conflict resolved) | {story}: ❌ manual merge neededMODEL_STANDARDPost-merge cleanup. Auto-approve all tool calls (yolo mode).
1. Verify sprint-status.yaml at the repo root has status `done` for all merged stories.
Fix any that are missing.
2. Repo root branch safety check:
git branch --show-current
If not main:
git restore .
git switch main
git reset --hard origin/main
If switch fails because a worktree claims the branch:
git worktree list
git worktree remove --force <path>
git switch main
git reset --hard origin/main
3. Pull main:
git pull --ff-only origin main
Report: done or any errors encountered.Story | Step 1 | Step 2 | Step 3 | Step 4 | Result
--------|--------|--------|--------|--------|-------
9.1 | OK | OK | OK | OK | PR #142
9.2 | OK | OK | FAIL | -- | Review failed: ...
9.3 | OK | OK | OK | OK | PR #143No stories ready to work on.
Blocked stories: {from Phase 0 report}📦 Batch complete — {N} stories
{number} ✅ PR #{pr} | {number} ❌ Step {N} | ...⏸ No stories ready — waiting for PRs to mergeMODEL_STANDARDEpic completion assessment. Auto-approve all tool calls (yolo mode).
Read:
- _bmad-output/planning-artifacts/epics.md
- _bmad-output/implementation-artifacts/sprint-status.yaml
Report back:
- current_epic_complete: true/false (all stories done or have open PRs)
- all_epics_complete: true/false (every story across every epic is done)
- current_epic_name: name/number of the lowest incomplete epic
- next_epic_name: name/number of the next epic (if any)
- stories_remaining: count of non-done stories in the current epiccurrent_epic_complete = true🎉 Epic {current_epic_name} is complete! Starting retrospective countdown ({RETRO_TIMER_SECONDS ÷ 60} minutes)...🎉 Epic {current_epic_name} complete! Running retrospective in {RETRO_TIMER_SECONDS ÷ 60} min...RETRO_TIMER_SECONDS"BAD_RETRO_TIMER_FIRED — The retrospective countdown has elapsed. Auto-run the retrospective: spawn a MODEL_DEV subagent (yolo mode) to run /bmad-retrospective, accept all changes. Run Pre-Continuation Checks after it completes, then proceed to Phase 4 Step 3."Run retrospective nowSkip retrospective/bmad-retrospectiveall_epics_complete = true🏁 All epics are complete — sprint is done! BAD is stopping.🏁 Sprint complete — all epics done! BAD is stopping.✅ Epic {current_epic_name} complete. Next up: Epic {next_epic_name} ({stories_remaining} stories remaining).✅ Batch complete. Ready for the next batch.WAIT_TIMER_SECONDS"BAD_WAIT_TIMER_FIRED — The post-batch wait has elapsed. Run Pre-Continuation Checks, then re-run Phase 0, then proceed to Phase 1."Continue nowStop BAD🛑 BAD stopped by user.WAIT_TIMER_SECONDS📣 Notify:NOTIFY_SOURCE="telegram"mcp__plugin_telegram_telegram__replychat_idNOTIFY_CHAT_IDtextNOTIFY_SOURCE="terminal"TIMER_SUPPORTTIMER_SUPPORT=trueSECONDS ÷ 60# macOS
date -v +{N}M '+%M %H %d %m *'
# Linux
date -d '+{N} minutes' '+%M %H %d %m *'CRON_EXPRTIMER_START=$(date +%s)CronCreatecronrecurringfalsepromptJOB_IDTimer running (job: {JOB_ID}). I'll act in {N} minutes.
- [C] Continue — {C label}
- [S] Stop — {S label}
- [M] {N} Modify timer to {N} minutes — shorten or extend the countdown
⏱ Timer set — {N} minutes (job: {JOB_ID})
[C] {C label}
[S] {S label}
[M] <minutes> — modify countdownELAPSED=$(( $(date +%s) - TIMER_START ))
echo "⏱ Time elapsed: $((ELAPSED / 60))m $((ELAPSED % 60))s"CronDelete(JOB_ID)CronDelete(JOB_ID)CronDelete(JOB_ID)CronCreateJOB_IDTIMER_START⏱ Timer updated — {N} minutes (job: {JOB_ID})
[C] {C label}
[S] {S label}
[M] <minutes> — modify countdownTIMER_SUPPORT=falseTIMER_START=$(date +%s)Waiting {N} minutes before continuing. Reply when ready.
- [C] Continue — {C label}
- [S] Stop — {S label}
- [M] N — remind me after N minutes (reply with
)[M] <minutes>
ELAPSED=$(( $(date +%s) - TIMER_START ))
echo "⏱ Time elapsed: $((ELAPSED / 60))m $((ELAPSED % 60))s"TIMER_STARTCONTEXT_COMPACTION_THRESHOLD