Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add aj-geddes/useful-ai-prompts --skill refactor-legacy-codegit clone --depth 1 https://github.com/aj-geddes/useful-ai-promptsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/aj-geddes/useful-ai-prompts/refactor-legacy-code)<a href="https://agentmods.dev/skills/aj-geddes/useful-ai-prompts/refactor-legacy-code"><img src="https://agentmods.dev/badge/skills/aj-geddes/useful-ai-prompts/refactor-legacy-code/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/aj-geddes/useful-ai-prompts/refactor-legacy-code"><img src="https://agentmods.dev/badge/skills/aj-geddes/useful-ai-prompts/refactor-legacy-code.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- Socket pass
- Snyk pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00046 | $0.00675 |
| Opus 5.5 | $0.00018 | $0.00270 |
| Sonnet 5.5 | $0.00009 | $0.00135 |
| Haiku 4.5 | $0.00005 | $0.00068 |
Grade A, and why
refactor-legacy-code scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 87 lines — stays where its author put it; the contents beside it link to each section on GitHub.
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
- Modernizing outdated code patterns or deprecated APIs
- Reducing technical debt in existing codebases
- Improving code readability and maintainability
- Extracting reusable components from monolithic code
- Upgrading to newer language features or frameworks
- Preparing code for new feature development
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
- Refactor incrementally: Small, testable changes
- Run tests frequently: After each refactoring step
- Commit often: Create logical, atomic commits
- Keep existing tests passing: Don't break functionality
- Use IDE refactoring tools: Safer than manual edits
- Review code coverage: Ensure tests cover refactored code
- Document decisions: Why, not just what
- Seek peer review: Fresh eyes catch issues
What ships with it
9 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
- references/benefits-achieved.md 438 B
- references/code-assessment.md 686 B
- references/complete-refactoring-example.md 3.0 KB
- references/establish-safety-net.md 776 B
- references/incremental-refactoring.md 2.1 KB
- references/modernize-patterns.md 1.1 KB
- references/reduce-dependencies.md 922 B
- scripts/scaffold-tests.sh 574 B runs code
- templates/test-template.js 541 B runs code
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2mo ago First seen · 87 lines · 46 tokens per session scan A 698f3d32b347
refactor-legacy-code is a skill published in the GitHub repository aj-geddes/useful-ai-prompts (376 stars, last pushed 8mo ago), licensed MIT. It adds 46 tokens to every session and 675 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
refactor-legacy-code compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| refactor-legacy-codeaj-geddes/useful-ai-prompts | Skill | 376 | 8mo ago | MIT | A | 46 | Claude Code, Codex |
| autoreviewopenclaw/clawhub | Skill | 9.5k | yesterday | MIT | A | 17 | Claude Code, Codex |
| agent-teams-simplify-and-hardenLeoYeAI/openclaw-master-skills | Skill | 2.2k | 6d ago | MIT | A | 115 | Claude Code, Codex |
| omh-code-reviewrlaope/oh-my-hermes | Skill | 5.2k | yesterday | MIT | A | 48 | Claude Code, Codex |
| revdiff-planumputun/revdiff | Skill | 945 | yesterday | MIT | A | 84 | Claude Code |
| explore-unknownsdzhng/skills | Skill | 1.4k | 2d ago | MIT | A | 162 | Claude Code, Codex |
| re0-mergeLilMGenius/paperthin | Skill | 1.4k | 4d ago | MIT | A | 70 | Claude Code |