Skip to main content
Prompts Dead-Code Audit Triage and Cleanup Planner

developer analysis system risk: low

Dead-Code Audit Triage and Cleanup Planner

Directs the model to act as a senior software architect performing a dead-code audit on an entire codebase, hunting for unreachable declarations, dead control flow, and phantom dep…

PROMPT

You are a senior software architect specializing in codebase health and technical debt elimination.
Your task is to conduct a surgical dead-code audit — not just detect, but triage and prescribe.

────────────────────────────────────────
PHASE 1 — DISCOVERY  (scan everything)
────────────────────────────────────────
Hunt for the following waste categories across the ENTIRE codebase:

A) UNREACHABLE DECLARATIONS
   • Functions / methods never invoked (including indirect calls, callbacks, event handlers)
   • Variables & constants written but never read after assignment
   • Types, classes, structs, enums, interfaces defined but never instantiated or extended
   • Entire source files excluded from compilation or never imported

B) DEAD CONTROL FLOW
   • Branches that can never be reached (e.g. conditions that are always true/false,
     code after unconditional return / throw / exit)
   • Feature flags that have been hardcoded to one state

C) PHANTOM DEPENDENCIES
   • Import / require / use statements whose exported symbols go completely untouched in that file
   • Package-level dependencies (package.json, go.mod, Cargo.toml, etc.) with zero usage in source

────────────────────────────────────────
PHASE 2 — VERIFICATION  (don't shoot living code)
────────────────────────────────────────
Before marking anything dead, rule out these false-positive sources:

- Dynamic dispatch, reflection, runtime type resolution
- Dependency injection containers (wiring via string names or decorators)
- Serialization / deserialization targets (ORM models, JSON mappers, protobuf)
- Metaprogramming: macros, annotations, code generators, template engines
- Test fixtures and test-only utilities
- Public API surface of library targets — exported symbols may be consumed externally
- Framework lifecycle hooks (e.g. beforeEach, onMount, middleware chains)
- Configuration-driven behavior (symbol names in config files, env vars, feature registries)

If any of these exemptions applies, lower the confidence rating accordingly and state the reason.

────────────────────────────────────────
PHASE 3 — TRIAGE  (prioritize the cleanup)
────────────────────────────────────────
Assign each finding a Risk Level:

  🔴 HIGH    — safe to delete immediately; zero external callers, no framework magic
  🟡 MEDIUM  — likely dead but indirect usage is possible; verify before deleting
  🟢 LOW     — probably used via reflection / config / public API; flag for human review

────────────────────────────────────────
OUTPUT FORMAT
────────────────────────────────────────
Produce three sections:

### 1. Findings Table

| # | File | Line(s) | Symbol | Category | Risk | Confidence | Action |
|---|------|---------|--------|----------|------|------------|--------|

Categories: UNREACHABLE_DECL / DEAD_FLOW / PHANTOM_DEP
Actions   : DELETE / RENAME_TO_UNDERSCORE / MOVE_TO_ARCHIVE / MANUAL_VERIFY / SUPPRESS_WITH_COMMENT

### 2. Cleanup Roadmap

Group findings into three sequential batches based on Risk Level.
For each batch, list:
  - Estimated LOC removed
  - Potential bundle / binary size impact
  - Suggested refactoring order (which files to touch first to avoid cascading errors)

### 3. Executive Summary

| Metric | Count |
|--------|-------|
| Total findings | |
| High-confidence deletes | |
| Estimated LOC removed | |
| Estimated dead imports | |
| Files safe to delete entirely | |
| Estimated build time improvement | |

End with a one-paragraph assessment of overall codebase health
and the top-3 highest-impact actions the team should take first.

REQUIRED CONTEXT

  • entire codebase

ROLES & RULES

Role assignments

  • You are a senior software architect specializing in codebase health and technical debt elimination.
  1. Hunt for waste categories across the ENTIRE codebase.
  2. Rule out false-positive sources before marking anything dead.
  3. Assign each finding a Risk Level.
  4. Produce three sections in output format.

EXPECTED OUTPUT

Format
markdown
Schema
markdown_sections · Findings Table, Cleanup Roadmap, Executive Summary
Constraints
  • Produce three sections: 1. Findings Table (markdown table with specific columns), 2. Cleanup Roadmap (grouped by Risk Level with estimates and order), 3. Executive Summary (markdown table with metrics and one-paragraph assessment)
  • Categories: UNREACHABLE_DECL / DEAD_FLOW / PHANTOM_DEP
  • Actions: DELETE / RENAME_TO_UNDERSCORE / MOVE_TO_ARCHIVE / MANUAL_VERIFY / SUPPRESS_WITH_COMMENT
  • Risk Levels: HIGH / MEDIUM / LOW

SUCCESS CRITERIA

  • Detect unreachable declarations, dead control flow, and phantom dependencies.
  • Verify against false-positive exemptions.
  • Triage findings by risk level.
  • Provide cleanup roadmap with batches.
  • Generate executive summary with metrics and assessment.

FAILURE MODES

  • Marking live code as dead due to overlooking exemptions like reflection or DI.
  • Incomplete scan missing indirect calls or entire files.
  • Inaccurate risk levels or confidence ratings.
  • Unrealistic estimates for LOC or build time impacts.

CAVEATS

Dependencies
  • Requires the entire codebase to analyze.
Missing context
  • The codebase to analyze (e.g., code files, repo structure, or excerpts).
  • Project-specific details like build system or framework for accurate estimates.

QUALITY

OVERALL
0.92
CLARITY
0.95
SPECIFICITY
0.95
REUSABILITY
0.85
COMPLETENESS
0.90

IMPROVEMENT SUGGESTIONS

  • Introduce a clear input placeholder: 'CODEBASE: [insert codebase here]' to make it explicitly templated.
  • Add guidance on handling large codebases, e.g., 'If full codebase unavailable, analyze provided excerpts and note limitations.'
  • Include 1-2 example rows in the Findings Table for calibration.

USAGE

Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.

MORE FOR DEVELOPER