A repository-aware agent skill for refactoring legacy code without casually changing its behavior.
Its enforced sequence is:
- inspect the repository and record the baseline;
- add retained characterization tests that pass on unchanged production code;
- when the target is an API, resolve whether to preserve v1 in place or leave v1 untouched and add v2;
- refactor in small verified batches;
- report exact evidence and any remaining risk.
The skill deliberately prioritizes precise naming and locality. It does not equate clean code with more files, smaller methods, interfaces, patterns, or abstraction layers.
Copy the folder to:
<repository>/.agents/skills/clean-code/
Copy the folder to:
$HOME/.agents/skills/clean-code/
Place the complete clean-code directory in the client's configured skills directory. Keep SKILL.md at the root of the skill folder.
Explicit invocation in Codex:
$clean-code Refactor the legacy order-pricing module without changing behavior.
The description also supports implicit routing for requests about legacy cleanup, maintainability, naming, technical debt, and behavior-preserving refactoring.
clean-code/
├── SKILL.md
├── README.md
├── REFERENCES.md
├── LICENSE
├── agents/
│ └── openai.yaml
├── references/
│ ├── api-versioning.md
│ ├── characterization-tests.md
│ ├── refactoring-heuristics.md
│ └── verification-and-reporting.md
├── evals/
│ ├── evals.json
│ └── trigger-queries.json
└── scripts/
└── validate_skill.py
SKILL.md contains the mandatory workflow. Supporting references are loaded only when their step is reached, keeping the primary instructions focused.
From the skill directory:
python3 scripts/validate_skill.pyThe validator checks frontmatter, naming, required files, local links, evaluation fixtures, and OpenAI metadata without third-party packages.
- Production behavior is characterized before production edits.
- Characterization tests are retained as legacy regression tests.
- API versioning is an explicit decision gate after tests and before implementation.
- Side-by-side v2 work leaves v1 production files untouched.
- Refactoring and behavior changes remain separate.
- Names, cohesion, and local comprehension take priority over arbitrary size metrics.
- Verification results distinguish passing checks, pre-existing failures, new failures, and commands not run.
This skill is not primarily for:
- greenfield implementation;
- debugging a behavior defect;
- broad dependency upgrades;
- formatting-only changes;
- architecture diagrams or educational explanations;
- intentional breaking API migrations without a behavior-preserving refactor scope.
See REFERENCES.md for the source material that informed the workflow.
