Legacy code modernization skill. Characterization tests, golden master, incremental modernization, dependency upgrades, dead code removal. Triggers on: /godmode:legacy, "legacy code", "modernize", "tech debt", "dead code".
From godmodenpx claudepluginhub arbazkhan971/godmodeThis skill uses the workspace's default tool permissions.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Enables AI agents to execute x402 payments with per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents pay for APIs, services, or other agents.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
/godmode:legacy# Assess codebase age and activity
git log --format='%ai' --reverse | head -1
git shortlog -sn --all | head -10
git log --since="6 months ago" --oneline | wc -l
# Check test coverage
ls -d test/ tests/ spec/ __tests__/ 2>/dev/null
npx jest --coverage 2>/dev/null || \
pytest --cov 2>/dev/null || echo "No test runner"
# Audit dependencies
npm audit 2>/dev/null || pip-audit 2>/dev/null
npm outdated 2>/dev/null || pip list --outdated 2>/dev/null
# Find complexity hotspots
find . -name "*.ts" -o -name "*.py" -o -name "*.js" \
| xargs wc -l 2>/dev/null | sort -rn | head -10
LEGACY ASSESSMENT:
Language: <detected>, Age: <from git>
Size: <files, LOC>
Contributors: <active/total>
Test coverage: <% or "none">
Dependencies: <total>, <outdated>, <EOL>, <vulns>
Dead code: <estimated LOC>
Change confidence: HIGH | MEDIUM | LOW | NONE
CONFIDENCE LEVELS:
Tests + CI + Types = HIGH
Tests only = MEDIUM
No tests = LOW
Nothing = NONE
IF confidence == NONE: add characterization tests first
IF vulns > 0: prioritize security patches
IF EOL deps > 0: flag for urgent migration planning
IF files > 500 LOC: identify god classes to extract
Code Archaeology:
The most critical step. Tests before any changes.
TEST STRATEGIES:
| Strategy | When to Use |
|-------------------|--------------------------|
| Characterization | Capture current behavior |
| Golden Master | Complex outputs (HTML) |
| Approval Testing | Snapshots as approval |
CHARACTERIZATION TEST:
Run code with known input
Record actual output as expected value
Test PASSES today by definition
Test FAILS if behavior changes
THRESHOLDS:
Critical paths: 100% must have tests before change
Min characterization tests per module: 5
Golden master update: requires UPDATE_GOLDEN=true
IF test captures a bug: document, fix separately
PRIORITY ORDER:
P0 (urgent): Security — patch vulns, fix auth
P1 (high): Stability — tests on critical paths
P2 (medium): Maintainability — extract god classes
P3 (normal): Performance — optimize hot paths
P4 (low): Modernization — upgrade frameworks
SAFE REFACTORING TECHNIQUES:
Extract Method, Extract Class
Replace Conditional with Polymorphism
Introduce Parameter Object
Wrap External Dependency
Sprout Method/Class (new tested code from legacy)
THRESHOLDS:
Max change size per PR: 200 lines
Each change must be independently revertable
IF change breaks characterization test: revert
ORDER: security vulns → PATCH → MINOR → MAJOR
RULES:
PATCH: safe to batch, apply all at once
MINOR: one at a time, read changelog
MAJOR: one at a time, read migration guide
THRESHOLDS:
IF dep has known CVE: upgrade within 48 hours
IF dep is EOL: plan migration within 2 weeks
IF major upgrade breaks > 5 tests: pause, plan
Run full test suite between each major upgrade
DETECTION (require 2+ signals):
Static analysis: ESLint no-unused, Ruff
Coverage analysis: 0% coverage = likely dead
Dependency analysis: depcheck/madge
Git history: untouched for > 1 year
Runtime tracking: instrumented but never called
PROCESS:
1. Identify with static analysis
2. Verify with git log (last touched date)
3. Confirm with runtime tracking if available
4. Remove in dedicated commit
5. Deploy and monitor for errors
6. IF errors: revert immediately
THRESHOLDS:
Require 2+ signals before removing
File untouched > 2 years: likely dead
Export with 0 importers: likely dead
LEGACY MODERNIZATION REPORT:
Confidence: <before> → <after>
Critical issues: <vulns, EOL deps>
Phase 1: characterization tests + fix vulns
Phase 2: replace deprecated, remove dead code
Phase 3: upgrade major deps, add types
Commit: "legacy: <action> — <target> (<impact>)"
Never ask to continue. Loop autonomously until done.
1. Git history: activity, contributors, age
2. Test coverage: test dirs, config, run coverage
3. Dependency health: audit, outdated, deprecated
4. Complexity: files > 500 LOC, circular deps
5. Confidence: Tests+CI+Types=HIGH, None=NONE
Print: Legacy: {files} modernized. Dead: {removed}. Tests added: {N}. Deps upgraded: {M}. Confidence: {before} -> {after}. Status: {status}.
timestamp project language age_years loc coverage_pct confidence vulns deprecated dead_loc verdict
KEEP if: existing tests pass AND characterization
tests cover changed code AND no behavior change
DISCARD if: tests break OR behavior changed
OR dead code removal causes errors
On discard: revert, add more tests, retry.
STOP when ALL of:
- Characterization tests cover modified paths
- Dead code removed and verified
- Dependencies upgraded to supported versions
- No behavior changes unless approved