Refactor legacy code

From aj-geddes/useful-ai-prompts · View interactive version

Refactor legacy code is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Modernize and improve legacy codebases while maintaining functionality. Use when you need to refactor old code, reduce technical debt, modernize deprecated patterns, or improve code maintainability without breaking existing behavior.

How to use this skill

Skill file

Refactor Legacy Code

Table of Contents

Overview

This skill helps you systematically refactor legacy code to improve maintainability, readability, and performance while preserving existing functionality. It follows industry best practices for safe refactoring with comprehensive testing.

When to Use

Quick Start

First, analyze the legacy code to understand:

# Review the codebase structure
tree -L 3 -I 'node_modules|dist|build'

# Check for outdated dependencies
npm outdated  # or pip list --outdated, composer outdated, etc.

# Identify code complexity hotspots
# Use tools like:
# - SonarQube for code smells
# - eslint for JavaScript
# - pylint for Python
# - RuboCop for Ruby

Reference Guides

Detailed implementations in the references/ directory:

| Guide | Contents |

|---|---|

| Code Assessment | Code Assessment |

| Establish Safety Net | Establish Safety Net |

| Incremental Refactoring | Incremental Refactoring |

| Modernize Patterns | Modernize Patterns |

| Reduce Dependencies | Reduce Dependencies, Documentation |

| Complete Refactoring Example | Complete Refactoring Example |

| Benefits Achieved | Benefits Achieved |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.