This skill guides systematic bug investigation, regression testing, and documentation, generating a formal bugfix report and coordinating branch work.
npx playbooks add skill arjenschwarz/agentic-coding --skill fix-bug
Fix bugs systematically while ensuring proper test coverage and documentation. Simple bugs are fixed directly; complex bugs get multiple competing implementations to find the best solution.
If a T-[number] ticket is mentioned (e.g., T-42), track it throughout the workflow:
T-{number}/bugfix-{bug-name} (no user prompt needed)in-progress status after branch creation. Add a comment: "Starting bugfix — investigating on branch T-{number}/bugfix-{bug-name}"ready-for-review status after the PR is created. Add a comment: "Fix ready for review — PR #{pr-number}"Use mcp__transit__update_task_status with the display ID to update status. Always include a comment when changing status.
If no Transit ticket is mentioned, skip all Transit-related steps.
Determine a concise, descriptive bug name (kebab-case) for the report directory. Derive from the issue description or ask the user if unclear.
When a Transit ticket is present: If the current branch already matches T-{number}/bugfix-* (e.g., in a worktree), skip branch creation. Otherwise, automatically create a branch named T-{number}/bugfix-{bug-name} and switch to it. Do not ask for permission. Move the ticket to in-progress status.
When no Transit ticket is present: Use AskUserQuestion to offer branch naming options:
bugfix/{bug-name} - Standard bugfix branchInvoke the systematic-debugger skill to perform structured root cause analysis:
Capture findings for the bugfix report.
Before implementing the fix, write tests that prove the bug exists:
The tests should:
Do not implement the fix yet. The tests must fail at this point.
Create specs/bugfixes/<bug-name>/report.md using the template in references/report-template.md. At this stage the "Resolution" section will be empty — it gets filled in after the fix is implemented.
Commit everything so far (failing tests + report + any investigation artifacts) using the /commit skill. This creates a clean baseline that competing implementations can branch from.
The commit message should indicate this is the investigation phase, e.g.: T-42: Add investigation report and failing regression tests for {bug-name}
Evaluate the bug's complexity based on the investigation findings. Consider:
Simple bugs (single clear fix, low risk, few files): proceed to Step 8A.
Complex bugs (multiple possible approaches, higher risk, cross-cutting, or subtle root cause): proceed to Step 8B.
Take the complex path when the investigation leaves several plausible fixes or a subtle root cause. It costs three agent runs, so a clear single-cause bug stays on the simple path.
For straightforward bugs:
For complex bugs, spawn multiple agents that independently implement the fix. Each agent works in an isolated worktree branched from the current commit (which has the failing tests).
Write a concise implementation brief that all agents receive. Include:
Launch 3 agents in parallel, each in its own worktree. Use the exact tools specified below — do not substitute different tools or MCP agents for Agents 1 and 2.
Agent 1 — Primary approach: Call the Agent tool (not an MCP tool) with isolation: "worktree" and subagent_type: "general-purpose". This spawns a Claude subagent in an isolated git worktree. Prompt it to implement the fix following the primary approach from the investigation's Phase 4.
Agent 2 — Alternative approach: Call the Agent tool (not an MCP tool) with isolation: "worktree" and subagent_type: "general-purpose". This spawns a Claude subagent in an isolated git worktree. Prompt it to implement the fix using an alternative strategy — if Phase 4 identified alternatives, use one; otherwise instruct it to find its own approach that differs from Agent 1's.
Agent 3 — Kiro (independent perspective): This is the only agent that uses an MCP tool. Call mcp__devtools__kiro-agent with agent: "kiro" and yolo-mode: true. The agent: "kiro" parameter gives Kiro access to all its skills rather than just the default agent. Since Kiro operates in the current working directory, first create a worktree manually for it:
git worktree add ../{repo-name}-worktrees/fix-{bug-name}-kiro -b fix-{bug-name}-kiro HEAD
Then pass a prompt that includes the implementation brief and instructs Kiro to work in the worktree directory, implement the fix, run the regression tests, and run the full test suite.
To be explicit: Agents 1 and 2 use the Agent tool (subagent_type: "general-purpose", isolation: "worktree"). Only Agent 3 uses mcp__devtools__kiro-agent. Do not use mcp__devtools__codex-agent or any other MCP agent tool for Agents 1 and 2.
Each agent's prompt should follow this structure:
You are implementing a fix for a bug. Work in {worktree_path}.
## Bug Summary
{root cause from investigation}
## Your Approach
{specific approach for this agent}
## Failing Tests
The following tests reproduce the bug and must pass after your fix:
{test file paths and how to run them}
## Requirements
1. Implement the fix
2. Run the regression tests — they must pass
3. Run the full test suite — no regressions allowed
4. Run linters/validators: {lint commands}
5. Commit your changes with a descriptive message
After all agents complete, evaluate each solution. Read the diffs and test results from each worktree.
Evaluation criteria (in priority order):
Disqualify any solution where:
If all solutions are disqualified, fall back to Step 8A (implement directly using the best partial solution as guidance).
Write a short comparison report at specs/bugfixes/<bug-name>/solution-comparison.md:
# Solution Comparison: {bug-name}
## Candidates
### Agent 1 (primary approach)
- **Files changed:** {list}
- **Lines changed:** +X / -Y
- **Tests:** {pass/fail}
- **Approach:** {one-line summary}
### Agent 2 (alternative approach)
- **Files changed:** {list}
- **Lines changed:** +X / -Y
- **Tests:** {pass/fail}
- **Approach:** {one-line summary}
### Agent 3 (Kiro — independent perspective)
- **Files changed:** {list}
- **Lines changed:** +X / -Y
- **Tests:** {pass/fail}
- **Approach:** {one-line summary}
## Selected: Agent {N}
**Reason:** {2-3 sentences explaining why this solution was chosen}
Cherry-pick or rebase the winning agent's commits onto the working branch:
# From the main working directory (not a worktree)
git cherry-pick <commit-hash-from-winning-worktree>
If the winning solution has multiple commits, use:
git cherry-pick <first-commit>^..<last-commit>
After integrating, verify everything still works:
Remove all competition worktrees:
git worktree remove ../{repo-name}-worktrees/fix-{bug-name}-kiro
# Agent worktrees are kept when the agent committed; once the winner is integrated,
# remove them with `git worktree remove <path>` and delete their branches
Also delete the temporary branches:
git branch -D fix-{bug-name}-kiro
Review and update any affected documentation:
Update specs/bugfixes/<bug-name>/report.md — fill in the Resolution section now that the fix is implemented. If the complex path was used, reference the solution comparison report.
When a Transit ticket is present, after all checks pass:
/commit skillgh pr create with:Fix T-{number}: {bug-name-in-title-case}ready-for-review status. Add a comment with the PR URL.When no Transit ticket is present, do not commit or create a PR unless asked.
After the PR is created, wait 10 minutes for CI checks and automated reviews to come in, then run the /pr-review-fixer skill to address any feedback from the first round automatically.
Upon completion:
specs/bugfixes/<bug-name>/report.mdspecs/bugfixes/<bug-name>/solution-comparison.mdready-for-reviewWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.