Home › Agent workflows › Refactor prompt file (Copilot)
Refactor prompt file (Copilot)
A Copilot prompt file (/refactor) for behavior-preserving refactors in small verified steps with tests run between them.
GitHub CopilotAgent workflows
How to use
Save this as .github/prompts/refactor.prompt.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
Note: Review and test before use. Provided as is, without warranty. See Terms.
.github/prompts/refactor.prompt.mdDownload ---
description: Refactor the selected code without changing behavior
agent: agent
argument-hint: what to improve (optional)
---
Refactor ${selection} (or ${file} if nothing is selected). Goal from me: ${input:goal:What should improve? e.g. readability, split function, remove duplication}
Rules:
- Behavior must not change. Public function signatures and exported names stay the same unless I said otherwise.
- First find the tests that cover this code and run them. If coverage is missing, add characterization tests that capture current behavior before refactoring.
- Work in small steps (extract function, rename, simplify conditionals with early returns, remove duplication, split modules). Run the tests after each step.
- Use editor rename/move refactorings so all references update; then search for string references (configs, docs).
- Don't fix unrelated bugs, reformat untouched code, or upgrade dependencies. List anything you noticed as follow-ups.
- Delete dead code you've proven unused instead of commenting it out.
Finish with: a short list of what changed, confirmation that tests pass (command and result), and follow-up suggestions.