/java-refactor
Suggests and applies version-gated Java refactorings. Use when user asks to "refactor this", "clean up this code", "modernize this Java", "simplify this", "extract method", "improve this class", or "make this more idiomatic".
$ npx -y skills add ducpm2303/claude-java-plugins --skill java-refactor --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/java-refactor
Context preview
The summary Claude sees to decide when to auto-load this skill.
Suggests and applies version-gated Java refactorings. Use when user asks to "refactor this", "clean up this code", "modernize this Java", "simplify this", "extract method", "improve this class", or "make this more idiomatic".
SKILL.md
java-refactor.SKILL.mddescription: Suggests and applies version-gated Java refactorings. Use when user asks to "refactor this", "clean up this code", "modernize this Java", "simplify this", "extract method", "improve this class", or "make this more idiomatic".
argument-hint: "[paste code or select in editor]"
Refactor the Java code I've selected or provided. Follow these steps:
Step 1 — Detect Java version
Check `pom.xml` (`<java.version>` or `<maven.compiler.source>`) or `build.gradle` (`sourceCompatibility`). If not found, ask: "What Java version are you targeting? (8, 11, 17, 21, or other)"
Step 2 — Apply safe refactorings (all Java versions)
These refactorings are safe regardless of Java version:
- **Extract method:** if a method is longer than 20 lines or has a distinct sub-step, extract it with a descriptive name
- **Rename for clarity:** rename variables, methods, or classes with unclear names
- **Remove duplication:** identify repeated logic blocks and extract to a shared method
- **Replace magic literals:** replace inline numbers/strings with named `static final` constants
- **Simplify conditionals:** replace nested if/else chains with early returns or ternary where clearer
- **Remove dead code:** delete unreachable branches, unused variables, unused imports
Step 3 — Apply version-gated refactorings (only if target version supports it)
State the minimum Java version required for each suggestion:
- **Java 8+ — Replace anonymous classes with lambdas:** e.g., `new Comparator<String>() { ... }` → `(a, b) -> a.compareTo(b)`
- **Java 8+ — Replace imperative loops with streams:** e.g., for-each + list.add → `list.stream().filter(...).collect(Collectors.toList())`
- **Java 8+ — Use Optional instead of null returns:** e.g., `return null` → `return Optional.empty()`
- **Java 9+ — Use List.of / Map.of:** e.g., `new ArrayList<>(Arrays.asList(...))` → `List.of(...)`
- **Java 10+ — Use var for local variables:** where the type is obvious from the right-hand side
- **Java 16+ — Replace data classes with records:** e.g., a class with only final fields, a constructor, and getters → `record`
- **Java 17+ — Replace instanceof + cast chains with pattern matching:** e.g., `if (obj instanceof String) { String s = (String) obj; }` → `if (obj instanceof String s)`
Output format
For each refactoring: 1. **What:** one sentence describing the change 2. **Why:** one sentence explaining the benefit 3. **Before:** the original code snippet 4. **After:** the refactored code snippet 5. **Java version required:** (e.g., "Java 8+" or "All versions")
Then offer: "Want me to apply these changes to the file?"
Next Steps
After completing refactoring:
- If tests don't exist for the refactored code → suggest running `/java-test` to generate tests
- If the refactoring changed public API signatures → suggest running `/java-docs` to update Javadoc
- Remind the user to run their build: `mvn compile -q` or `./gradlew build -q`
Read more
description: Suggests and applies version-gated Java refactorings. Use when user asks to "refactor this", "clean up this code", "modernize this Java", "simplify this", "extract method", "improve this class", or "make this more idiomatic". argument-hint: "[paste code or select in editor]"
Refactor the Java code I've selected or provided. Follow these steps:
Step 1 — Detect Java version
Check `pom.xml` (`<java.version>` or `<maven.compiler.source>`) or `build.gradle` (`sourceCompatibility`). If not found, ask: "What Java version are you targeting? (8, 11, 17, 21, or other)"
Step 2 — Apply safe refactorings (all Java versions)
These refactorings are safe regardless of Java version:
- **Extract method:** if a method is longer than 20 lines or has a distinct sub-step, extract it with a descriptive name
- **Rename for clarity:** rename variables, methods, or classes with unclear names
- **Remove duplication:** identify repeated logic blocks and extract to a shared method
- **Replace magic literals:** replace inline numbers/strings with named `static final` constants
- **Simplify conditionals:** replace nested if/else chains with early returns or ternary where clearer
- **Remove dead code:** delete unreachable branches, unused variables, unused imports
Step 3 — Apply version-gated refactorings (only if target version supports it)
State the minimum Java version required for each suggestion:
- **Java 8+ — Replace anonymous classes with lambdas:** e.g., `new Comparator<String>() { ... }` → `(a, b) -> a.compareTo(b)`
- **Java 8+ — Replace imperative loops with streams:** e.g., for-each + list.add → `list.stream().filter(...).collect(Collectors.toList())`
- **Java 8+ — Use Optional instead of null returns:** e.g., `return null` → `return Optional.empty()`
- **Java 9+ — Use List.of / Map.of:** e.g., `new ArrayList<>(Arrays.asList(...))` → `List.of(...)`
- **Java 10+ — Use var for local variables:** where the type is obvious from the right-hand side
- **Java 16+ — Replace data classes with records:** e.g., a class with only final fields, a constructor, and getters → `record`
- **Java 17+ — Replace instanceof + cast chains with pattern matching:** e.g., `if (obj instanceof String) { String s = (String) obj; }` → `if (obj instanceof String s)`
Output format
For each refactoring: 1. **What:** one sentence describing the change 2. **Why:** one sentence explaining the benefit 3. **Before:** the original code snippet 4. **After:** the refactored code snippet 5. **Java version required:** (e.g., "Java 8+" or "All versions")
Then offer: "Want me to apply these changes to the file?"
Next Steps
After completing refactoring:
- If tests don't exist for the refactored code → suggest running `/java-test` to generate tests
- If the refactoring changed public API signatures → suggest running `/java-docs` to update Javadoc
- Remind the user to run their build: `mvn compile -q` or `./gradlew build -q`
A Claude Code plugin marketplace with 3 focused plugins for Java developers. All plugins support Java 8 through Java 21 and tailor advice to your target Java version.
Other skills on claude-java-plugins.
- /java-adr
Creates, lists, and manages Architecture Decision Records for Java projects. Use when user asks to "create an ADR", "document this decision", "write an architecture decision", "add ADR", "list decisions", "show ADRs", or "record this architectural choice".
Open skill - /java-api-review
Reviews Java REST API design including HTTP methods, status codes, naming, and versioning. Use when user asks to "review my API", "check REST design", "is this good REST", "review endpoints", "API design review", "check my controller", or "review HTTP API".
Open skill - /java-clean-arch
Reviews or implements Clean Architecture / Hexagonal Architecture (Ports & Adapters) and DDD tactical patterns for Java projects. Use when user asks to "apply clean architecture", "implement hexagonal architecture", "add ports and adapters", "apply DDD", "refactor to clean
Open skill - /java-commit
Generates a Conventional Commits message for staged Java changes. Use when user asks to "write a commit message", "help me commit", "what should my commit say", "summarize my changes", "draft a commit", or "create commit message".
Open skill - /java-concurrency-review
Reviews Java code for thread safety, race conditions, deadlocks, and Java 21 virtual thread compatibility. Use when user asks to "review concurrency", "is this thread safe", "check for race conditions", "concurrency issues", or "virtual thread compatible".
Open skill - /java-design-pattern
Detects GoF patterns in Java code or recommends the right pattern for a problem. Use when user asks to "what pattern is this", "detect design patterns", "suggest a pattern", "should I use factory", "which design pattern", or "recommend a pattern for".
Open skill

