• Sign in

Get new prompt packs + offers

Occasional emails. No spam. Unsubscribe anytime.

© 2026 Prompt Chains

Browse packsCoursesFAQPrivacyTerms
  1. Prompts
  2. Tech Tools
  3. Refactor Code for Readability

🧹

Refactor Code for Readability

Clean up code for clarity and structure without changing behavior.

Best with

Claude
Tech ToolsAIAutomation

2 views

1
# CONTEXT:
2
This code works but is hard to read: long functions, unclear names, deep nesting, duplicated logic. I need it cleaner and easier to maintain WITHOUT changing what it does. The risk is a "refactor" that silently alters behavior or over-engineers with needless abstraction.
3
4
# ROLE:
5
You are a staff engineer known for surgical, behavior-preserving refactors and for reviews that make code read like prose. Before writing anything, think step by step: (1) What does this code do, exactly, including edge cases? (2) Which smells hurt readability most (naming, length, nesting, duplication)? (3) What is the smallest set of changes that fixes them while preserving behavior?
6
7
# RESPONSE GUIDELINES:
8
First restate the code's observable behavior in 2-3 lines so we agree it must stay identical. Then apply named refactorings (Extract Function, Rename, Guard Clause, Replace Magic Number) one concern at a time. Keep public signatures stable unless I allow changes.
9
10
# TASK CRITERIA:
11
1. **Behavior-preserving**: same inputs produce same outputs and side effects.
12
2. **Justified**: every change maps to a named smell.
13
3. **No gold-plating**: no new layers, patterns, or config unless they remove real pain.
14
**AVOID**: changing logic, renaming public APIs without flagging it, premature abstraction, clever one-liners that hurt clarity.
15
**FOCUS ON**: intention-revealing names, small functions, early returns, removing duplication.
16
17
# INFORMATION ABOUT ME:
18
- My code: Paste codePPaassttee ccooddee
19
- Language/stack: Insert stackIInnsseerrtt ssttaacckk
20
- Style guide or constraints: Insert or "not specified use idiomatic defaults"IInnsseerrtt oorr ""nnoott ssppeecciiffiieedd uussee iiddiioommaattiicc ddeeffaauullttss""
21
22
# RESPONSE FORMAT:
23
**Behavior (must stay the same):** 2 3 lines22 33 lliinneess
24
**Refactored code:**
25
```LanguageLLaanngguuaaggee
26
Full refactored codeFFuullll rreeffaaccttoorreedd ccooddee
27
```
28
**Changes made:**
29
| # | Change | Smell addressed |
30
|---|--------|-----------------|
31
**Behavior-equivalence note:** Why outputs are unchangedWWhhyy oouuttppuuttss aarree uunncchhaannggeedd

Related prompts

🐛
Debug & Fix Code (Root Cause)

Tech Tools · Text prompt

Find the true defect behind a bug and return corrected, tested code.

Claude

Tech ToolsAI

0

Open

🎫
Support Ticket Classifier

Automation · Text prompt

Auto-labeling inbound support tickets with category, sentiment, urgency, and a human-handoff flag for routing.

Claude

AutomationAI

3

Open

🧭
Sentiment & Intent Extractor

Automation · Text prompt

Turning a single user message into structured sentiment, primary intent, and extracted entities for analytics or routing.

Claude

AutomationAI

0

Open