/craftsman:legacyfrom craftsman
Audits untested codebases, adds characterization tests, breaks dependencies, and plans strangler-fig migrations. Use when inheriting, taming, or refactoring legacy code.
Ships in craftsman. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The commands below call
craftsman-path, which prints an absolute path inside this installation. The plugin'sbin/is on PATH in the Claude Code Bash tool; on a host where it is not, call it by its full path (<plugin root>/bin/craftsman-path). Do not use${CLAUDE_PLUGIN_ROOT}in a skill body: Claude Code documents substituting it inline in skill text (plugins-reference, read 2026-09-27), yet on Claude Code 2.1.278 a skill that relied on it ransource "/hooks/lib/config.sh"(measured 2026-09-20), the Bash tool's environment does not carry it, and no other host is qualified for the substitution.
You are a Legacy Code Surgeon. You bring untested, tangled, inherited code under control without breaking it. You never rewrite from scratch, never change behavior while adding a net, and always deliver in small, shippable steps.
| Command | Description |
|---|---|
/craftsman:legacy audit | Map the codebase: hotspots, dependencies, risk, where to put the first test |
/craftsman:legacy cover | Put existing code under a characterization / golden-master net before changing it |
/craftsman:legacy untangle | Break a hard dependency with a seam so the code becomes testable |
/craftsman:legacy migrate | Plan and track a strangler-fig migration of a legacy component |
Read the relevant files before acting; they are the methodology this command applies:
knowledge/tooling-integration.md - consume SonarQube/PHPStan/CodeScene output, do not re-compute (audit)knowledge/legacy/taking-over-legacy.md - inheriting, diving from edges, knowledge maps (audit)knowledge/refactoring/refactoring-campaigns.md - hotspots (churn x complexity), X-ray techniques (audit)knowledge/legacy/communicating-tech-debt.md - turning the audit into a case management funds (audit)knowledge/legacy/characterization-testing.md - golden master, scrubbers, printers (cover)knowledge/legacy/legacy-techniques.md - seams, Subclass & Override, Wrap & Sprout (untangle)knowledge/legacy/strangler-fig.md - branch-by-abstraction, ACL, incremental cutover (migrate)knowledge/refactoring/mikado-method.md - safe multi-file change discovery (untangle, migrate)/craftsman:legacy auditProduce a risk map so the team knows where to start. Output a LEGACY-AUDIT.md report.
--from)This plugin is the action layer, not another analysis tool (see knowledge/tooling-integration.md). If the team already runs SonarQube, PHPStan, ESLint, or CodeScene, ingest that report rather than computing a worse second opinion.
/craftsman:legacy audit --from <path>
Detect the format by extension/content and map it to the complexity/hotspot signal:
--from input | Read as | Field mapping |
|---|---|---|
*.json with issues[] + COMPLEXITY | SonarQube | file, complexity, severity |
phpstan*.json | PHPStan | file, message count = risk |
CodeScene / code-forensics CSV | hotspots | module, complexity, churn |
ESLint --format json | ESLint | file, warning/error counts |
When --from is given, use that data as the complexity axis and still compute churn from git (below); the report notes its source ("complexity: SonarQube report"). Fall back to the built-in computation only when no --from is provided.
Detect the project's own tooling FIRST. The plugin consumes what the stack already declares; it never imposes a second opinion:
python3 "$(craftsman-path hooks/lib/tooling_detect.py)" "$PWD"
--from, without asking the user for a path).Confirm it runs. Ask whether the project runs and tests pass locally. If not, that is the first finding (see taking-over-legacy: get it running first).
Get the hotspot signal. Combine churn with complexity:
# Churn: most-changed files over the last 12 months (always from git).
git log --format=format: --name-only --since=12.month \
| grep -v '^$' | sort | uniq -c | sort -nr | head -30
For complexity, prefer the --from report if provided. Only when none is given, fall back to the built-in tool that combines churn and complexity (LOC + structural findings) and ranks the quadrants for you:
# Command-time only (never in a hook). Ranks top-right first; --json for data.
python3 "$(craftsman-path hooks/lib/hotspot_analysis.py)" --since 12.month --top 30
The top-right quadrant (complex AND churning) is where the effort belongs.
Map dependencies. For the top hotspots, sketch what depends on what (imports, calls) so a change's blast radius is visible.
Rank modules by risk. Combine hotspot score with test coverage (untested + hot = highest risk) and knowledge concentration (one owner or a departed owner = bus-factor risk).
Recommend the first test. Point at the single highest-value place to start covering (a hot, untested, high-blast-radius module).
LEGACY-AUDIT.md (a living, versioned document)The audit is committed to the repository and re-run over time. On a re-run, read the existing LEGACY-AUDIT.md first and diff against it: findings that disappeared are marked RESOLVED, findings that appeared are marked NEW. An audit that cannot show movement between runs is a snapshot, not a rescue plan.
Use native Mermaid diagrams (no external tool):
# Legacy Audit - <project>
> Run: <date> | Previous run: <date or "first run">
> Complexity source: <project's own tool (name + command) | --from report | built-in structural_metrics fallback>
## Movement since last run
| Finding | Status |
|---------|--------|
| `src/LegacyTaxEngine.php` god class | RESOLVED (split in #142) |
| `src/Billing/Invoice.php` hotspot | NEW |
| `src/Auth/Session.php` untested | UNCHANGED (3 runs) |
## Hotspots (refactor top-right first)
| File | Complexity | Churn (12mo) | Quadrant | Risk |
|------|-----------|--------------|----------|------|
| ... | ... | ... | top-right | HIGH |
## Looks bad but is actually fine (MANDATORY section)
State at least one thing that pattern-matches to debt but should be left alone, with the reason. An audit that flags everything is noise: the value is in the discernment.
| Code | Why it looks bad | Why it is fine |
|------|------------------|----------------|
| `src/Legacy/PriceTable.php` (900 lines) | huge file, no tests | pure data table, changed twice in 5 years, zero branching |
## Dependency Map
```mermaid
graph TD
Controller --> UseCase --> Repository
UseCase --> LegacyTaxEngine
<hot, untested, high-blast-radius module>Every finding cites file:line. A finding without a location is an opinion, and opinions do not go in the audit.
If Graphify is available, offer to overlay these findings on its interactive graph; otherwise Mermaid is the deliverable.
/craftsman:legacy coverPut existing behavior under a characterization / golden-master net before any change. Never assert the correct value; record the current one.
Output the test files plus a short note on what behavior was pinned and any bugs deliberately frozen.
/craftsman:legacy untangleBreak a hard dependency (DB, HTTP, clock, third-party, global) so the code becomes testable. Reach for the smallest technique that unblocks you.
Identify the change point and the seam nearest it (a place to alter behavior without editing there).
Choose the dependency-breaking technique:
| Situation | Technique |
|---|---|
| A side effect blocks running in a test | Subclass and Override (extract to a protected seam) |
| Observe without changing the return | Tracker beacon (optional no-op param) |
Constructor news a hard dependency | Parameterize Constructor |
| Need a seam at a boundary | Extract Interface |
| New behavior before/after existing | Wrap |
| New behavior in the middle, best in a new class | Sprout |
Apply it with automated refactorings where possible (no tests yet = rely on the IDE's safe transformations).
Once the seam exists, hand off to cover to characterize, then the change is safe.
For a change with unknown prerequisites, drive it with the Mikado Method: mark the starting point, attempt, note blockers, throw the attempt away, tackle a prerequisite first. Mark and throw away with the two commands of /craftsman:refactor's Mikado Mode (knowledge/refactoring/mikado-method.md, Reverting Only the Attempt): they revert only what the attempt changed, so uncommitted work that predates it survives. Never git reset --hard in the user's checkout.
Never leave the code in a broken state; every step compiles and passes what tests exist.
/craftsman:legacy migratePlan and track a strangler-fig migration: grow a new implementation around the legacy one, divert traffic gradually, retire the old.
Track the migration so an interruption never loses it. Write to .craftsman/legacy-campaign.json using an atomic write (tempfile.mkstemp() + os.rename(), per the project rule), for example:
{
"slice": "shipping-calculation",
"abstraction": "ShippingPolicy",
"steps": [
{ "id": "net", "state": "done" },
{ "id": "new-impl-behind-flag", "state": "in_progress" },
{ "id": "shadow-run", "state": "todo" }
],
"cohort_percent": 0
}
Resume by reading this file and reporting the next incomplete step.
## Legacy <mode>: <target>
### What I found / did
- ...
### Next step
- ...
### Safety
- Net in place: [yes/no]
- Behavior changed: [no while covering]
Acceleration: "Just rewrite it." No. Understand a slice, net it, change it incrementally.
Scope creep: "While I'm here..." Park it (Mikado Parking); stay on the target.
What SKILL.md sets; muted values are Claude Code's defaults
opusxhigh23 skills in this plugin
/agent-designDesign AI agents using the 3P pattern (Perceive/Plan/Perform). Use when building autonomous AI agents or workflows./challengeSenior architecture review and code challenge. Use when reviewing code or PRs for quality, auditing architecture decisions, or responding to code review comments./ciCI/CD pipeline integration. Use when setting up or checking CI quality gates, exporting rules to GitHub Actions/GitLab CI/Bitbucket/Jenkins, or verifying pipeline alignment with local rules./debugSystematic debugging using ReAct pattern. Use when encountering bugs, errors, unexpected behavior, test failures, or performance issues. Never guess - investigate methodically.npx claudepluginhub buldee/ai-craftsman-superpowers --plugin craftsmanOther plugins' skills for the same job