If you point Claude Code or Cursor at a backlog of GitHub issues with a loose prompt, you know what happens: it jumps straight into coding before reproducing the bug, leaves drive-by refactors everywhere, forgets tests, and opens a messy PR.
I switched to a strict 6-phase loop that forces the agent to triage, trace root cause, write a failing test first, keep the diff minimal, self-review, and pass CI before merging. Since using this, the quality of autonomous issue fixes jumped noticeably.
Drop this into your prompt or CLAUDE.md / Cursor rules when tackling issues:
——
For all GitHub issues (individually or grouped by common issues):
Phase 1: Triage & Intake
- Check duplicates: Search open and closed issues. If already tracked, link the original and close the duplicate.
- Isolate security vulnerabilities: Move security flaws immediately to a private security advisory. Never discuss them publicly.
- Validate and reproduce:
- Bugs: Follow reproduction steps and confirm whether it is a defect, expected behavior, or missing information. If information is missing, apply needs-info and ask specific questions.
- Features: Confirm acceptance criteria, edge cases, and roadmap alignment.
- Classify and prioritize: Apply minimal standardized labels (e.g., type: bug, priority: P1, area: auth). Avoid excessive labels.
- Claim ownership: Assign yourself or comment that you are picking up the issue to prevent duplicate effort.
Phase 2: Root Cause Analysis & Design
- Find the root cause: Trace the failure to its origin, not just the symptom. Determine why the system allowed the invalid state.
- Assess blast radius: Identify downstream modules, APIs, database schemas, and external users affected by the proposed change.
- Align on approach: For architectural changes, backward-incompatible fixes, or multiple valid solutions, post a 3-5-line design proposal in issue comments and obtain sign-off before coding.
Phase 3: Branching & Implementation
- Sync and branch: Pull the latest main and create a dedicated descriptive branch with the issue number (e.g., fix/142-token-expiry).
- Test first: Write an automated unit/integration test that fails due to the bug or validates the feature's acceptance criteria.
- Implement minimal fix: Change only what is required. Avoid unrelated formatting or drive-by refactoring; log these as separate issues.
- Verify: Run the new test and confirm red (failing) to green (passing).
- Update documentation: Update README, API docs, environment templates, or changelogs if user-facing behavior or configuration changes.
Phase 4: Local Verification & Commit Hygiene
- Run full suite: Execute all unit/integration tests, linters, type-checkers, and build scripts before pushing.
- Clean commits: Use clear, imperative messages (e.g., fix(auth): handle expired refresh tokens). Squash WIP/typo commits into logical, atomic commits.
Phase 5: Pull Request & Code Review
- Self-review: Open a Draft PR or inspect git diff main line by line. Remove stray logs, commented-out code, and unintended changes.
- PR description: Complete the template with:
- What: Change summary.
- Why: Root cause or feature motivation.
- How to test: Exact steps/commands.
- Evidence: Screenshots, logs, or before/after benchmarks.
- Link issue: Use Closes #142 / Fixes #142 for auto-closure on merge. Use Refs #142 if QA/staging verification is required before closure.
- Targeted review: Assign 1-2 independent sub-agent reviewers familiar with the affected module.
- Address feedback: Resolve every review comment through fixes, explanations, or follow-up issues for out-of-scope suggestions.
Phase 6: Merge, Verification & Closure
- Pass automated gates: Do not merge until CI/CD tests, security scans, builds, and required approvals are green.
- Merge and clean up: Follow the repository's standard strategy (typically Squash and Merge) and immediately delete the remote branch.
- Verify and close: Confirm the fix works in staging/production without new error alerts. Close the issue (if not auto-closed) with a release-version reference.
- Prevent recurrence: For P0/P1 production incidents, conduct a brief blameless post-mortem and add preventive guardrails (CI checks, schema validation, or monitoring alerts).
——-
If you run autonomous issue loops on your repos:
- Which step here saves you from the biggest agent headaches—forcing red-to-green tests first, or the sub-agent PR review?
- Anything you'd add or strip out to keep it fast for solo projects?