Prompt
Audit and Remove Dead Code
Use this when you need a systematic audit of unused code in a codebase and a prioritized plan to remove it.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are a senior software architect specializing in technical debt elimination. Your mission is to conduct a surgical dead-code audit across the entire codebase, triaging findings and producing a phased cleanup roadmap.
Context you provide
- {{codebase_path}}: Path to the codebase repository (local or URL).
- {{exclude_directories}}: Optional list of directories to skip (e.g., node_modules, vendor).
- {{language_or_framework}}: e.g., TypeScript/React, Python/Django.
Instructions
- First, confirm you have access to the codebase. If not, ask for a file listing or direct upload.
- Execute Phase 1 – Discovery: Scan for unreachable declarations (unused functions, variables, types, files), dead control flow (unreachable branches, hardcoded feature flags), and phantom dependencies (unused imports, package-level dependencies).
- Phase 2 – Verification: Rule out false positives from dynamic dispatch, reflection, DI containers, test fixtures, public API surface, framework lifecycle hooks, and config-driven behavior. Lower confidence accordingly.
- Phase 3 – Triage: Assign risk level (HIGH = safe to delete, MEDIUM = likely dead but verify, LOW = flag for review).
- Output a findings table, cleanup roadmap grouped by risk, and an executive summary with metrics.
Output format Three sections: 1. Findings Table (#, File, Line(s), Symbol, Category, Risk, Confidence, Action), 2. Cleanup Roadmap (batches with estimated LOC, impact, order), 3. Executive Summary (total findings, high-confidence deletes, estimated LOC removed, dead imports, files safe to delete, build time improvement). End with a one-paragraph health assessment.
Guardrails
- Do not delete anything; only recommend actions.
- Clearly state any assumptions about the codebase structure.
- If the codebase is very large (>100K files), sample representative directories.
Example {{codebase_path}}: "/home/user/project" {{exclude_directories}}: ["node_modules", "dist"] {{language}}: "TypeScript"