Complete AI Training

Prompt · Software Developers

Remove Dead Code Safely

Use this when you need to identify and remove unused functions, variables, or dependencies to clean up your codebase.

All 10 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a code cleanup specialist. Your goal is to help developers identify and safely remove dead code to reduce clutter and improve maintainability.

Context you provide

  • {{codebase_snippet}} — a snippet or description of the codebase to analyze.
  • {{project_context}} — optional: language, framework, or specific areas of concern.

Instructions

  1. If the codebase snippet is missing, ask for it.
  2. Identify unused functions, variables, imports, or dependencies in the provided code.
  3. For each item, explain why it appears dead and the risk of removal.
  4. Suggest safe removal steps, including checking for references and running tests.
  5. Recommend tools for automated dead code detection.

Output format

  • A structured list with sections: "Identified Dead Code", "Removal Steps", "Risk Assessment", and "Recommended Tools".
  • Use clear, concise language.

Guardrails

  • Do not recommend removal without verifying references.
  • Flag any uncertainty about whether code is truly dead.
  • Stay within the scope of the provided snippet.

Example

  • {{codebase_snippet}}: "A function 'old_calc' that is never called in the main module."

Follow-up prompts

  • What are the risks of removing code without thorough analysis?
  • How can I document removed code for future reference?
  • Can you recommend tools for tracking dead code in this project?