From metapowers
Fix a bug by coordinating a debugger, coder, and tester through investigation, root cause analysis, regression TDD, code review, and PR creation. Use when the user wants to fix a bug from beads or GitHub issues.
How this skill is triggered — by the user, by Claude, or both
Slash command
/metapowers:implement-fixThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Fix the bug described in beads issue `$ARGUMENTS` by systematically reproducing and investigating the issue, performing root cause analysis, writing regression tests that fail before the fix, implementing the fix, and gating on PR approval.
Fix the bug described in beads issue $ARGUMENTS by systematically reproducing and investigating the issue, performing root cause analysis, writing regression tests that fail before the fix, implementing the fix, and gating on PR approval.
flowchart TB
subgraph phase0 ["Phase 0: Prepare"]
bd_show["bd show issue"]
claimable{"Claimable?"}
error["Error: not claimable"]
gh_link["Verify GH ↔ Beads\nlinked"]
bd_show --> claimable
claimable -- "no" --> error
claimable -- "yes" --> gh_link
end
gather["Phase 1\nGather Context\n(Explorer Agent)"]
subgraph phase2 ["Phase 2: Investigation"]
invest_setup["Create team, subtasks,\nbranch & worktree"]
invest_agent["Launch Debugger\nAgent"]
repro["Reproduce Bug"]
investigate["Investigate Root Cause\n(logs, code analysis,\nbisection, tracing)"]
rca["Root Cause Analysis\nRecord in GH + Beads"]
rca_ok{"Root cause\nidentified?"}
inconclusive["Summarize research\nin GH + Beads\nNotify user & STOP"]
plan["Plan of Action\nCreate child bead issues"]
invest_setup --> invest_agent
invest_agent --> repro
repro --> investigate
investigate --> rca
rca --> rca_ok
rca_ok -- "no" --> inconclusive
rca_ok -- "yes" --> plan
end
subgraph phase3 ["Phase 3: Regression TDD"]
tdd_setup["New branch & worktree"]
tdd_agents["Launch Tester +\nCoder Agents\n(parallel)"]
write_tests["Tester: Write Regression\nTests (must FAIL)"]
verify_fail["Verify Tests Fail\n(proving bug exists)"]
fix_code["Coder: Implement Fix\n(tests must PASS)"]
verify_pass["Verify All Tests Pass"]
tdd_setup --> tdd_agents
tdd_agents --> write_tests
write_tests --> verify_fail
verify_fail --> fix_code
fix_code --> verify_pass
end
code_review["Phase 4: Code Review\n3 Review Agents\n(parallel)"]
has_fixes{"MUST FIX\nissues?"}
fix_cycle["Phase 5: Fix Cycle\nDispatch fixes to\nCoder + Tester"]
fix_pr["Phase 6\nCreate Fix PR"]
pr_review{"User Reviews\nFix PR"}
pr_relay["PR Feedback Relay\nAgents read comments,\nfix & reply"]
resolution["Phase 7: Resolution\nClose subtasks"]
cleanup["Phase 8: Cleanup\nShut down agents,\ndelete team & worktrees"]
phase0 --> gather
gather --> phase2
inconclusive --> cleanup
plan --> phase3
verify_pass --> code_review
code_review --> has_fixes
has_fixes -- "yes" --> fix_cycle
fix_cycle -- "re-review" --> code_review
has_fixes -- "no" --> fix_pr
fix_pr --> pr_review
pr_review -- "comments" --> pr_relay
pr_relay --> pr_review
pr_review -- "approved\n& merged" --> resolution
resolution --> cleanup
Ensure the bug is tracked in both beads and GitHub and that the two are linked.
Run bd show $ARGUMENTS and verify:
open, backlog, or todo). If the issue is already in_progress, done, closed, or otherwise not claimable, report an error (see Common Issues) and stop.bug). If it is not a bug, warn the user but proceed if they confirm.Check for a linked GitHub issue:
https://github.com/<owner>/<repo>/issues/<number> or #<number>).gh issue view <number>.gh issue list --search "<bug title>".
If a match is found, link it by updating the beads issue notes: bd update $ARGUMENTS --notes "GitHub: <url>".
If no match is found, create one:
gh issue create --title "<bug title>" --body "Linked to beads issue $ARGUMENTS
<bug description from beads>"
Then link the new GitHub issue URL back to the beads issue notes.
Cross-link: Ensure the GitHub issue body references the beads issue ID, and the beads issue notes contain the GitHub issue URL. Both systems must reference each other.
Invoke the gather-context skill in a separate Explore agent using the Agent tool:
Agent(
description: "Gather context for $ARGUMENTS",
prompt: "/gather-context $ARGUMENTS",
subagent_type: "Explore"
)
This runs in a separate Explore agent context and stores a <task_context> brief in the beads issue notes.
Confirm the agent reports that context was stored in the issue before proceeding to Phase 2.
Create a team via TeamCreate.
Create beads subtasks and link them as children of $ARGUMENTS:
bd create --title="Investigate: Reproduce and diagnose <bug>" --description="Reproduce the bug, investigate root cause, produce RCA" --type=task --priority=1
bd dep add <investigate-id> $ARGUMENTS --type=parent-child
Create an investigation branch and worktree:
git worktree add /tmp/<bug>-investigate -b <bug>/investigate
cd /tmp/<bug>-investigate && pnpm install
Invoke the investigate-bug skill in a debugger agent using the Agent tool:
Agent(
description: "Investigate bug $ARGUMENTS",
prompt: "/investigate-bug $ARGUMENTS",
subagent_type: "metapowers:debugger"
)
This runs in a forked debugger agent context. The debugger will reproduce the bug, investigate the root cause, produce a Root Cause Analysis, commit it to .specs/<bug>/root-cause-analysis.md, and record findings in both beads issue notes and the linked GitHub issue.
Confirm the agent reports that investigation is complete. Close the investigation beads subtask after the agent completes.
Read the RCA from the beads issue notes (<root_cause_analysis> block). Evaluate whether the investigation identified a clear root cause:
If root cause was identified → proceed to Plan of Action below.
If the bug could not be reproduced AND no root cause was identified → the investigation is inconclusive. Do NOT attempt a fix. Instead:
Summarize the research — compile a summary of everything the debugger tried, what was ruled out, and what remains unknown.
Record in beads — update the issue notes with an <investigation_summary> block:
bd update $ARGUMENTS --notes "<investigation_summary>
## Investigation Summary (Inconclusive)
### What was tried
<Summary of reproduction attempts and investigation techniques used>
### What was ruled out
<Hypotheses that were tested and disproven>
### What remains unknown
<Open questions and areas that could not be investigated further>
### Recommendations
<Suggestions for how to make progress — e.g., more data needed, specific logs to enable, environment to test in>
</investigation_summary>"
Record in GitHub — post the summary as a comment on the linked GitHub issue:
gh issue comment <number> --body "## Investigation Summary (Inconclusive)
<contents of the summary>"
Notify the user and STOP — do not proceed to Phase 3. Report:
Investigation for bug
$ARGUMENTSwas inconclusive — root cause could not be determined. Research findings have been recorded in both beads and GitHub. Review the investigation summary to decide next steps (e.g., gather more data, enable logging, try to reproduce in a different environment).
Skip to Phase 8: Cleanup.
If the bug was reproduced but root cause remains unclear — this is also inconclusive. Follow the same steps above, but note in the summary that the bug was successfully reproduced and include the reproduction steps for future reference.
Based on the RCA, create a plan of action and child beads issues:
Document the fix plan in .specs/<bug>/fix-plan.md covering:
Create child beads issues for each unit of work:
bd create --title="Regression tests: <specific test description>" --description="Write failing tests that prove the bug exists. Tests MUST fail before the fix." --type=task --priority=1
bd dep add <test-id> $ARGUMENTS --type=parent-child
bd create --title="Fix: <specific fix description>" --description="Implement the fix. Regression tests must pass after this." --type=task --priority=1
bd dep add <fix-id> $ARGUMENTS --type=parent-child
bd dep add <fix-id> <test-id> --type=blocks
Create as many test and fix tasks as needed — one per distinct area or concern identified in the RCA.
Shut down the debugger agent (it is no longer needed), clean up the investigation worktree, and create a new fix branch from main:
git worktree remove /tmp/<bug>-investigate
git pull origin main
git worktree add /tmp/<bug>-fix -b <bug>/fix
cd /tmp/<bug>-fix && pnpm install
Copy the RCA and fix plan into the worktree if they were committed to the investigation branch:
git checkout <bug>/investigate -- .specs/<bug>/
Launch two agents in parallel (subagent_type: "general-purpose", mode: "bypassPermissions", run_in_background: true). Both work in the same worktree — coordinate via SendMessage to avoid file conflicts.
Tester Agent — writes regression tests FIRST:
The tester's prompt MUST instruct them to:
/tmp/<bug>-fixCoder Agent — implements the fix AFTER tests are ready:
The coder's prompt MUST instruct them to:
/tmp/<bug>-fixtsc --noEmit to verify type safetyThe tester and coder coordinate via SendMessage:
Launch review agents in parallel for the fix. Use subagent_type: "feature-dev:code-reviewer" with run_in_background: true.
Group the 7 review areas into 3 focused agents:
Area 1 — Coding Style:
any, good generics use)Area 5 — Debugging Cruft:
console.log not part of intentional outputArea 6 — Consistent Formatting:
Area 2 — Efficiency and Algorithm Appropriateness:
Area 4 — Robust Error Handling:
Area 3 — Error/Warning Cleanup:
tsc --noEmit and report errors@ts-ignore, @ts-expect-error, as anyArea 7 — Regression Test Coverage:
Each reviewer rates issues as:
Only MUST FIX items are reported (with file:line citations).
CRITICAL: Review Agent 3 MUST execute the test suite and include the output. Test failures are MUST FIX items that get sent back to the fix agents.
cd /tmp/<bug>-fix && git push -u origin <branch>gh pr create including:
PAUSE HERE. Wait for user approval. If the user leaves PR comments, use the PR Feedback Relay process below.
When the user leaves comments on the fix PR, re-launch the coder and tester agents (if not still running) and instruct each to:
gh pr view <pr-number> --comments to read all comments on the PR. Understand what the reviewer is asking for.gh pr comment <pr-number> --body "<response>" to reply on the PR with their resolution. Each agent MUST identify themselves in their reply (e.g., "[Coder Agent] Updated the fix to..." or "[Tester Agent] Added additional regression test for...") so the reviewer knows which agent addressed which feedback.After both agents have addressed all comments, notify the user that the PR has been updated and is ready for re-review.
Once the user approves and merges the PR:
git worktree remove /tmp/<bug>-investigate and git worktree remove /tmp/<bug>-fixgit status shows clean, up to date with origin.bd) for task tracking — never markdown TODOs or TaskCreateisolation: "worktree"isActive flags in team config if TeamDelete failsIssue not claimable — If the issue status is in_progress, done, closed, or any other non-claimable state, report:
Error: Issue
$ARGUMENTShas status<status>and cannot be claimed. Only issues with a claimable status (e.g.,open,backlog,todo) can be fixed.
Do not proceed with the workflow.
Root cause not identified — If the investigation is inconclusive (whether or not the bug was reproduced), do NOT attempt a fix. Summarize the research in beads and GitHub, notify the user, and skip to cleanup. See "Evaluate Investigation Outcome" in Phase 2.
No GitHub issue found — If no matching GitHub issue exists, create one automatically and link it to beads. Do not block on this.
Regression test passes before fix — If a regression test passes on the current (buggy) code, the test is not exercising the buggy code path. The tester MUST investigate and fix the test before proceeding.
npx claudepluginhub galexy/metapowers --plugin metapowersCoordinates diagnosis, test-driven reproduction, root-cause analysis, and targeted fixes for bugs with regression testing.
Step-by-step bug fix workflow: diagnose root cause, implement minimal fix, write regression test. Use when fixing bugs or working on bug report issues.
Fixes GitHub issues using parallel analysis, hypothesis-based root cause analysis, similar issue detection, and prevention recommendations. Use for debugging errors, regressions, bugs, or triaging.