skills/do-refactor/SKILL.md
Execute a refactoring epic on a single branch, implementing all issues sequentially with CI verification after each. Use when user types /do-refactor or asks to execute a refactoring plan.
npx skillsauth add jamesc/skills do-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Execute a refactoring epic on a single branch, implementing all child issues sequentially. Each issue is a commit (or small group of commits), CI is verified after each, and a PR is created early and updated incrementally.
Key Philosophy: Refactoring epics block other work, so execute them quickly on one branch with continuous CI validation. Ship the whole epic as a single PR to minimize disruption. If any issue breaks CI, fix it before moving to the next.
Identify the epic: Ask the user for the Epic ID (e.g., BT-XXX) or accept it from the command.
Load the epic and child issues: Fetch the epic and all child issues from Linear:
streamlinear-cli get BT-XXX
# Then fetch child issues (use graphql for parent/child relationships)
streamlinear-cli graphql "query { issue(id: \"<epic-uuid>\") { children { nodes { id identifier title description priority state { name } labels { nodes { name } } relations { nodes { type relatedIssue { identifier state { name } } } } } } } }"
Build an ordered list respecting dependencies (blocked issues come after their blockers). If no explicit ordering, use: high priority first, smallest first (S before M before L).
Validate prerequisites:
agent-ready (have acceptance criteria, files to modify)needs-spec, STOP and tell the user which ones need specificationIn Progress, STOP — another agent is already working on itDone (skip those)git status --porcelain must be emptyCreate the branch: One branch for the entire epic:
git fetch origin main
git checkout -b refactor/BT-XXX origin/main
Use refactor/BT-XXX naming convention (epic ID, not individual issue IDs).
Verify baseline CI passes:
just ci
If baseline CI fails, STOP — don't start refactoring on a broken main.
Execute issues sequentially: For each child issue (in dependency order):
a. Pick up the issue (invoke the pick-issue skill with the issue ID):
/pick-issue BT-YYY
This loads the issue context, sets it to In Progress, reads acceptance criteria, and identifies files to modify. Review the safety principles:
b. Implement the refactoring:
c. Verify tests pass:
just test
If tests fail:
just test until it passesjust clippy && just fmtd. Review the changes (invoke the review-code skill):
/review-code
This runs a multi-pass code review against main. Fix any issues found before committing. Re-run just test if changes were made.
e. Commit with issue ID:
git add -A
git commit -m "refactor: <description> BT-YYY"
One commit per issue (or a small group if the issue has distinct phases like "add tests" then "refactor").
f. Complete the issue:
streamlinear-cli update BT-YYY --state Done
g. Create or update the PR:
After the FIRST issue: Create the PR immediately (no auto-merge — human review required):
git push -u origin HEAD
gh pr create --title "Refactor: <epic title> BT-XXX" --body "<PR body>"
Do NOT use --auto-merge or enable auto-merge. Refactoring PRs must be reviewed by a human.
After subsequent issues: Push to update the existing PR:
git push
Add a PR comment summarising what was just completed:
✅ **BT-YYY: <issue title>** — Done
- <brief summary of changes>
- CI: passing
- Progress: X/Y issues complete
Handle failures gracefully: If an issue cannot be completed:
Recoverable (fix and continue):
git fetch origin main && git merge origin/main, resolve, re-run CIBlocking (stop and ask):
needs-spec or acceptance criteria are unclearWhen stopping:
streamlinear-cli update BT-YYY --state "Backlog"
streamlinear-cli comment BT-YYY "Blocked: <explanation>"
Final verification: After all issues are complete:
# Ensure we're up to date with main
git fetch origin main
git merge origin/main
# If conflicts, resolve them
# Final CI run on the complete refactoring
just ci
Update the PR: Edit the PR body with the final summary:
## Refactor: <Epic Title> (BT-XXX)
### Issues Completed
- ✅ BT-YY1: <title> — <one-line summary>
- ✅ BT-YY2: <title> — <one-line summary>
- ...
### Changes Summary
- **Files changed:** X
- **Lines added/removed:** +N / -M
- **CI status:** All passing
### Safety Verification
- [ ] All existing tests pass without modification (behavioral preservation)
- [ ] Each commit leaves CI green (incremental delivery)
- [ ] No behavioral changes — structure only (or explicitly noted)
### Testing
- `just ci` passes on final state
- Each intermediate commit verified with `just test`
Update the epic: Mark the epic as Done (or note remaining issues):
# If all child issues complete:
streamlinear-cli update BT-XXX --state Done
# If some issues remain:
streamlinear-cli update BT-XXX --state "In Progress"
streamlinear-cli comment BT-XXX "Partial completion: X/Y issues done. Remaining: BT-YYY, ..."
Notify the user: Summary of what was accomplished:
## Refactoring Complete
**Epic:** BT-XXX — <title>
**PR:** #NNN
**Issues completed:** X/Y
**Branch:** refactor/BT-XXX
**Status:** Ready for review
One branch, one PR, entire epic. This minimises disruption:
refactor: description BT-YYYMerge origin/main into the refactoring branch:
Do NOT rebase — merge preserves commit history and is safer for large refactorings.
Update the PR body (not just comments) as issues complete. The PR body should always reflect current state:
Before marking the epic complete, verify:
just ci passes on the final stateunwrap() added on user inputtools
Find the next logical piece of work. Use when user types /whats-next or asks what they should work on next, or wants recommendations for the next task.
development
Use when navigating code, finding references, looking up definitions, understanding types, or tracing call hierarchies in TypeScript, Rust, or Beamtalk (.bt) files. Prefer LSP over Grep/Glob for any navigation task where symbol semantics matter.
data-ai
Find and update Linear issues that need labels, blocking relationships, or metadata. Use when user says '/update-issues' with criteria like 'no labels', 'missing agent-ready', 'needs size', etc.
data-ai
Sync modified skills and agents back to the repo and create a PR. Use when user types /sync-skills or wants to save in-session skill improvements.