dead-code
Generate a static dead-code report website for the Java project the user is working on.
Steps
- Find the Java source root. Prefer
src/main/java; if absent, use the directory the user points at or the closest directory containing.javafiles. If the user names a specific module or subproject, scope to it. To include tests, point the script at a root that also coverssrc/test/java. - Run the analyzer that ships with this skill:
```
python3 ~/.claude/skills/dead-code/find_dead_code.py <java-src-dir> <out-dir> [title]
```
Use dead-code-site inside the target project as <out-dir> unless the user asks for another location, and pass the project name as the title.
- The script writes a single self-contained
index.htmland prints the totals (methods, entry points, reachable, dead, dead classes). Serve it withpython3 -m http.serverfrom<out-dir>(pick a free port) or tell the user to open the file directly, then report the URL or path and the headline numbers. - Tell the user how to read the site: the cards summarize totals, the donut shows the reachable-vs-dead split, the dead code tab lists every unreachable method grouped by file (with
file:line, a reason tag, and who calls it), and the entry points tab shows the seeds the analysis started from. The search box filters by class, method, or file.
How reachability is decided
- Entry points (reachability roots) are:
main(...); methods annotated with Spring web mappings (@GetMapping,@PostMapping,@RequestMapping, ...),@Bean,@PostConstruct,@PreDestroy,@EventListener,@Scheduled, messaging listeners,@ExceptionHandler; JUnit@Testand lifecycle methods; and public framework callbacks (run,call,doFilter, ...) on classes implementingCommandLineRunner,Runnable,Filter, and similar. - A method is reachable if it is an entry point or is called, directly or transitively, from one. Everything else is reported as dead.
- Dead methods are tagged
no references(nobody calls them) oronly dead callers(called only from other dead code). A class whose every method is dead is flagged as a dead class. - Calls are resolved from source text by the declared type of fields, parameters and locals, plus
implements/extendsrelationships so a call through an interface reaches its implementations.
Notes
- The site is light themed and hand-drawn in style: wobbly SVG, pastel fills, handwriting fonts.
- The analyzer needs only the Python standard library; do not install anything.
- Static analysis cannot see reflection, dynamic proxies, dependency-injection by interface that is wired at runtime, serialization, or methods invoked only from configuration or external frameworks. Treat the report as a strong candidate list and review each item before deleting.
- If the script reports no methods found, confirm the path actually contains
.javafiles before retrying.