| name | refactor |
| description | Refactors existing code by identifying language and applying best practices. Use when the user asks to refactor, improve, optimize, or clean up code. |
- Detect the programming language before refactoring — state it in the response
- Refactor when the request includes "refactor", "improve", "optimize", "clean up", or similar
- Preserve original intent and functionality unless the user requests a change
- If code contains duplication, refactor and test before introducing new changes
- Use idiomatic, modern, maintainable patterns for the detected language
- Add or update comments and documentation as appropriate
- Ask clarifying questions if the request is ambiguous
- Provide before/after code examples in the response
- Ensure changes do not break unrelated code in larger files
- Run or suggest relevant tests after refactoring
- Make minimal changes while preserving readability
- Identify contradictory requirements or existing implementations that block the refactor
Examples
JavaScript
function sum(a, b) { return a+b }
function sum(a, b) {
return a + b;
}
Python
def greet(name):return 'Hello, '+name
def greet(name: str) -> str:
"""Return a greeting for the given name."""
return f"Hello, {name}"