Prompt · Workflow template · Public
Plan a behavior-preserving code refactor
Use this prompt when existing code needs a refactor plan that improves structure, readability, or maintainability while preserving current behavior.
When to use this prompt
Use this prompt to plan a refactor that changes code structure while preserving externally visible behavior and avoiding invented project state.
Inputs required
Provide the current code, intended refactor goal, behavior that must be preserved, tests or examples if available, and constraints. The prompt should not invent files, tests, execution results, or project architecture.
Copy-ready prompt
Copy the prompt and replace the MATERIALS block with the current code, refactor goal, behavior constraints, tests, and relevant context.
Plan a behavior-preserving code refactor.
TASK:
Review the supplied code and produce a refactor plan that improves structure, readability, or maintainability without changing existing behavior.
REFACTOR SCOPE:
Focus on planning a small behavior-preserving refactor.
Do not introduce new product behavior unless the user explicitly asks for it.
Do not perform a full architecture redesign unless the user explicitly asks for architecture review.
Do not perform a security review unless the user explicitly asks for one.
Do not claim the refactor was implemented, run, tested, or verified unless execution evidence is supplied.
Do not invent project files, dependencies, tests, runtime output, logs, or hidden architecture.
BEHAVIOR-PRESERVATION RULES:
- Identify the behavior that must remain unchanged.
- Identify inputs, outputs, side effects, API contracts, configuration behavior, and error behavior that may be affected.
- If behavior is unclear, mark it as INSUFFICIENT_EVIDENCE.
- If the requested refactor may change behavior, flag it as BEHAVIOR_CHANGE_RISK.
- Prefer the smallest staged refactor that achieves the stated goal.
- Separate required refactor steps from optional cleanup.
- Do not remove code unless the supplied material supports that it is unused, duplicated, or unnecessary.
- Do not rename public APIs, exported symbols, routes, configuration keys, or externally used fields unless the user explicitly approves that scope.
REVIEW CHECKS:
- Current responsibility boundaries
- Duplication
- Function or module size
- Naming clarity
- Control-flow complexity
- Data-flow clarity
- Side effects
- Public API or interface stability
- Configuration or environment coupling
- Test impact
- Regression-sensitive paths
OUTPUT:
A) Refactor goal check
B) Behavior that must be preserved
C) Current structure issues
D) Refactor plan
E) Required changes
F) Optional cleanup
G) Behavior-change risks
H) Tests or checks to run
I) Missing evidence
J) Confidence
MATERIALS:
"""
Replace this block with:
- current code
- refactor goal
- behavior that must be preserved
- existing tests, if available
- examples or expected inputs and outputs, if available
- project constraints, if relevant
- files or APIs that must not change, if relevant
"""
Prompt setup
Use this as a runtime refactor-planning prompt
Paste the current code, refactor goal, and behavior constraints into the prompt. Keep stable no-fabrication, code-review, and project-specific rules in the instruction layer.
Related coding workflows and controls
Use these related workflows when the task needs code-quality review, test coverage review, or stricter evidence control.