Automated Dead Code Cleanup Plan for Codex Repositories

Get a systematic plan to identify and safely remove unused exports and dead code from your codebase using characterization tests to prevent regressions.

Agent prompt for ChatGPT

Prompt

Prompt
You are a Senior Software Engineer specializing in codebase maintenance and refactoring. Your task is to design a safe, automated cleanup plan for removing unused exports and dead code from a repository. Follow these rules: 1. Create an audit table mapping every exported symbol to its usage count across the directory. 2. Mandate the creation of a characterization test covering the current behavior of any module before modifications occur. 3. Define a three-phase removal process: Audit, Test, and Prune. 4. Prioritize internal-only utilities before public-facing APIs. 5. Include a specific step for verifying side effects in modules with no direct references. Output format: 1. Executive Summary of the cleanup strategy. 2. Audit Table: Symbol Name, File Path, Usage Count, Status. 3. Characterization Test Checklist. 4. Phased Execution Roadmap. This is not legal or professional advice; consult with your lead architect before executing destructive deletions in production codebases. Ask me these 3 questions first: 1. What is the primary programming language of the codebase? 2. Are there any known reflection-based calls or dynamic imports that static analysis might miss? 3. Do you currently have a CI pipeline that runs integration tests?

Example output

Example for: a legacy TypeScript project with 50,000 lines of code. ## Executive Summary The strategy focuses on risk-mitigation by treating unused code as a potential dependency. We will utilize static analysis to identify candidates for removal, verify their behavior via characterization tests, and perform a staged deletion to ensure no hidden dependencies exist. ## Audit Table | Symbol Name | File Path | Usage Count | Status |
| --- | --- | --- | --- |
| formatCurrency | utils/money.ts | 0 | Candidate |
| validateUser | auth/guard.ts | 12 | Keep |
| legacyAuth | auth/legacy.ts | 0 | Candidate |
| parseQuery | lib/query.ts | 4 | Keep | ## Characterization Test Checklist - [ ] Identify all entry points to the module. - [ ] Record current output for 5 diverse input sets. - [ ] Create a snapshot test in the existing test suite. - [ ] Execute tests to confirm current baseline state. ## Phased Execution Roadmap 1. Phase 1: Static Analysis. Run dependency tree mapping to confirm zero-usage across all branches. 2. Phase 2: Isolation. Move candidate files to a quarantine folder for 48 hours to monitor runtime errors. 3. Phase 3: Verification. Run the characterization tests after commenting out the exports. 4. Phase 4: Pruning. Permanently remove files only after successful CI passes with zero regressions. This is not legal or professional advice; consult with your lead architect before executing destructive deletions in production codebases.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces a rigorous audit table before any code is deleted.
  • Prioritizes safety by requiring characterization tests first.
  • Structures the cleanup into clear, actionable phases.

Use this prompt when preparing to refactor a large or legacy codebase to remove technical debt. Paste this into ChatGPT or Codex. Ensure you have your project directory structure accessible for reference.

Common edits

  • Adjust the characterization test requirements based on your specific testing framework.
  • Add a specific phase for performance benchmarking if the codebase is latency-sensitive.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Codex

Sync Test Factories and Fixtures with Database Migrations

This prompt updates your test factories, JSON fixtures, and contract tests to match new database schema changes, ensuring your test suite remains consistent with production code.

Coding

Port a Function or Module to Another Language With Tests Proving Same Behavior

Lists the source code's behaviors and edge cases, writes tests in the target language first, ports the code idiomatically, and gives a table of library mappings and semantics that differ.

Refactor Monolithic God Classes into Clean Services

Get a step-by-step plan to break a large monolithic class into smaller, testable services while preserving the original public API behavior.

Cursor Characterization-Test-First Refactor of a Legacy Module

Has Cursor lock in current behavior with characterization tests before restructuring a legacy module in small steps, so you can decide whether the refactor preserved behavior and is safe to merge.

Generate API Client Patches from OpenAPI Schema Diffs

This prompt analyzes OpenAPI diffs to generate precise code patches and unit test assertions for your API client SDK.

Perform Static Call Graph Trace Before Modifying Code

Generate a clear visual map of function calls and file dependencies to identify exactly where your changes will ripple before you type a single line of code.