refactor
यह क्या करती है
यह आपके एजेंट को मौजूदा कोड की बनावट छोटे, टेस्ट किए गए चरणों में सुधारने में मदद करती है, बिना उसका व्यवहार बदले। यह उन डेवलपर्स के लिए है जो पुराने कोड को साफ़ करना चाहते हैं या तकनीकी कर्ज़ सुरक्षित तरीके से कम करना चाहते हैं।
कब इस्तेमाल करें
- ✓जब आप गंदे या पुराने कोड को बिना उसका व्यवहार बदले साफ़ करना चाहें।
- ✓जब कोड की खराब बनावट के संकेत हटाने हों, जैसे दोहराया गया या बहुत लंबा फ़ंक्शन।
- ✓जब कोई भी बदलाव करने से पहले रीफ़ैक्टरिंग योजना को मंज़ूरी देनी हो।
Skill का लिंक
https://github.com/luongnv89/claude-howto/blob/main/03-skills/refactor/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“क्या आप इस पुराने बिलिंग मॉड्यूल को सुरक्षित तरीके से रीफ़ैक्टर करने में मदद कर सकते हैं, पहले एक योजना दिखाकर जिसे मैं मंज़ूर कर सकूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट कोड को समझता है, टेस्ट कवरेज जाँचता है, खराब बनावट के संकेत ढूँढता है और एक योजना लिखता है। फिर वह एक-एक छोटा बदलाव करता है और हर चरण पर आपकी मंज़ूरी माँगता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Code Refactoring Skill
A systematic approach to refactoring code based on Martin Fowler's Refactoring: Improving the Design of Existing Code (2nd Edition). This skill emphasizes safe, incremental changes backed by tests.
"Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure." — Martin Fowler
Core Principles
- Behavior Preservation: External behavior must remain unchanged
- Small Steps: Make tiny, testable changes
- Test-Driven: Tests are the safety net
- Continuous: Refactoring is ongoing, not a one-time event
- Collaborative: User approval required at each phase
Workflow Overview
Phase 1: Research & Analysis
↓
Phase 2: Test Coverage Assessment
↓
Phase 3: Code Smell Identification
↓
Phase 4: Refactoring Plan Creation
↓
Phase 5: Incremental Implementation
↓
Phase 6: Review & Iteration
Phase 1: Research & Analysis
Objectives
- Understand the codebase structure and purpose
- Identify the scope of refactoring
- Gather context about business requirements
Questions to Ask User
Before starting, clarify:
- Scope: Which files/modules/functions need refactoring?
- Goals: What problems are you trying to solve? (readability, performance, maintainability)
- Constraints: Are there any areas that should NOT be changed?
- Timeline pressure: Is this blocking other work?
- Test status: Do tests exist? Are they passing?
Actions
- Read and understand the target code
- Identify dependencies and integrations
- Document current architecture
- Note any existing technical debt markers (TODOs, FIXMEs)
Output
Present findings to user:
- Code structure summary
- Identified problem areas
- Initial recommendations
- Request approval to proceed
Phase 2: Test Coverage Assessment
Why Tests Matter
"Refactoring without tests is like driving without a seatbelt." — Martin Fowler
Tests are the key enabler of safe refactoring. Without them, you risk introducing bugs.
Assessment Steps
Check for existing tests
# Look for test files find . -name "*test*" -o -name "*spec*" | head -20Run existing tests
# JavaScript/TypeScript npm test # Python pytest -v # Java mvn testCheck coverage (if available)
# JavaScript npm run test:coverage # Python pytest --cov=.
Decision Point: Ask User
If tests exist and pass:
- Proceed to Phase 3
If tests are missing or incomplete: Present options:
- Write tests first (recommended)
- Add tests incrementally during refactoring
- Proceed without tests (risky - requires user acknowledgment)
If tests are failing:
- STOP. Fix failing tests before refactoring
- Ask user: Should we fix tests first?
Test Writing Guidelines (if needed)
For each function being refactored, ensure tests cover:
- Happy path (normal operation)
- Edge cases (empty inputs, null, boundaries)
- Error scenarios (invalid inputs, exceptions)
Use the "red-green-refactor" cycle:
- Write failing test (red)
- Make it pass (green)
- Refactor
Phase 3: Code Smell Identification
What Are Code Smells?
Symptoms of deeper problems in code. They're not bugs, but indicators that the code could be improved.
Common Code Smells to Check
See references/code-smells.md for the complete catalog.
Quick Reference
| Smell | Signs | Impact |
|---|---|---|
| Long Method | Methods > 30-50 lines | Hard to understand, test, maintain |
| Duplicated Code | Same logic in multiple places | Bug fixes needed in multiple places |
| Large Class | Class with too many responsibilities | Violates Single Responsibility |
| Feature Envy | Method uses another class's data more | Poor encapsulation |
| Primitive Obsession | Overuse of primitives instead of objects | Missing domain concepts |
| Long Parameter List | Methods with 4+ parameters | Hard to call correctly |
| Data Clumps | Same data items appearing together | Missing abstraction |
| Switch Statements | Complex switch/if-else chains | Hard to extend |
| Speculative Generality | Code "just in case" | Unnecessary complexity |
| Dead Code | Unused code | Confusion, maintenance burden |
Analysis Steps
- **Automated
अक्सर पूछे जाने वाले सवाल
क्या यह व्यवहार बदलता है?
स्किल कहती है कि व्यवहार वही रहना चाहिए। रीफ़ैक्टरिंग में केवल अंदरूनी बनावट बदलती है।
क्या इसके लिए टेस्ट चाहिए?
स्किल पहले टेस्ट कवरेज जाँचती है और हर बदलाव के लिए टेस्ट को सुरक्षा जाल की तरह इस्तेमाल करती है।
क्या यह बिना पूछे कोड बदल देगी?
नहीं। स्किल कहती है कि हर चरण पर उपयोगकर्ता की मंज़ूरी ज़रूरी है।
जानकारी
लेखक का मूल विवरण
Systematic code refactoring based on Martin Fowler's methodology. Use when users ask to refactor code, improve code structure, reduce technical debt, clean up legacy code, eliminate code smells, or improve code maintainability. This skill guides through a phased approach with research, planning, and safe incremental implementation.
repo: luongnv89/claude-howto
लोकप्रियता
- GitHub स्टार
- 46k
- रैंकिंग में स्थान
- #6324
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
lesson-quiz
46kClaude Code के एक ट्यूटोरियल पाठ पर 10 सवालों की क्विज़ लेती है, आपके जवाब अंक देती है, और दोहराने लायक विषय बताती है।
self-assessment
46kClaude Code की 10 सुविधा-क्षेत्रों पर क्विज़ देती है, फिर विषय-वार अंक और यह बताने वाला सीखने का रास्ता कि आगे क्या पढ़ें।
blog-draft
46kआपके विचारों और स्रोतों से ब्लॉग पोस्ट का ड्राफ़्ट बनाने में आपके एजेंट का चरण-दर-चरण मार्गदर्शन करती है, काम के साथ-साथ संस्करण दर्ज करते हुए।
claude-md
46kयह आपके एजेंट को CLAUDE.md फ़ाइल बनाने या सुधारने में मदद करती है, जो प्रोजेक्ट के बारे में बताती है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।