AI Vibing

The Cleanup Prompt: Have Your AI Coding Assistant Delete Dead Code After Every Feature

Quick Win
Skill level
Beginner
Time to implement
20 min
Cost
Under $50 a month
Platform
Instagram
Tools
Claude, Claude Code, Git, Knip
Outcomes
Saves time, Beginner friendly
Last verified
Nov 14, 2026
RA

Rachel

@buildinghappiIG

Original strategy by Rachel. Watch the original on Instagram.

Summary

AI coding assistants make adding features fast, but every feature leaves a little mess behind: unused files, duplicate functions, and code that works but nobody understands. The fix is a cleanup pass after every feature, where you ask the same assistant to find what it just added that should not be there. The creator, a senior software engineer, says this deletion prompt is the most useful one she has ever given Claude, and that it finds something every single time.

Set upWhat you need

  • A project you are building with an AI coding assistant, such as Claude Code, Cursor, or Claude in the browser

  • Git, so every cleanup happens on its own branch and can be undone

  • Your project's tests or a quick manual click-through checklist for the feature you just built

  • Optional: Knip, a free tool that lists unused files, exports, and dependencies in JavaScript and TypeScript projects

  • About 20 minutes per feature

ToolsClaudeClaude CodeGitKnip

Do thisStep by step

  1. 1

    Finish the feature and commit it

    Reel Playbooks addition: before cleaning anything, commit the working feature so you have a safe restore point, then start a branch for the cleanup: git checkout -b cleanup/after-feature. If the cleanup breaks something, you can throw the branch away.

  2. 2

    Run the cleanup prompt

    Ask your assistant to find every piece of dead code, duplicate logic, unused components, or unnecessary complexity it just added to the project. Reel Playbooks addition: a ready-to-paste version: "Review the changes from this feature. List every piece of dead code, duplicate logic, unused component or file, and unnecessary complexity you added. For each item, give the file, why it is safe to remove or simplify, and what could break. Do not change anything yet." Asking for a list first keeps you in control.

  3. 3

    Review the list before deleting

    Reel Playbooks addition: read each item and approve only the ones you understand. Be careful with anything used dynamically (routes, config, environment variables, code called by name), since tools and assistants can misjudge those. Then tell the assistant which items to remove.

  4. 4

    Cross-check with a dead code tool

    Reel Playbooks addition: for JavaScript or TypeScript projects, run npx knip to get an independent list of unused files, exports, and dependencies. Items that both the assistant and Knip flag are the safest to remove.

  5. 5

    Test, review the diff, and merge

    Reel Playbooks addition: run your tests (for example npm test) and click through the feature. Check git diff --stat to see how much was removed; a good cleanup often deletes more lines than it adds. Merge the branch only when everything still works.

  6. 6

    Make it a habit after every feature

    The creator runs this cleanup every time she finishes a feature, because the mess compounds the longer you build. Reel Playbooks addition: save the prompt as a reusable instruction or project rule in your assistant so the cleanup pass takes one message.

Heads upCommon mistakes & tips

  • Ask for a list before any edits. Letting the assistant delete freely in one step can remove code that is used in ways it did not see.

  • Clean up right after the feature, while the context is fresh in the same chat; the assistant knows exactly what it added.

  • Duplicate logic is the sneakiest mess. Ask the assistant to merge duplicates into one shared function rather than deleting one copy.

  • Keep cleanup commits separate from feature commits so you can revert one without the other.

  • Lean code also keeps pages lighter, which helps load speed on sites and web apps.

MeasureHow to know it worked

The assistant returns a concrete list of files and functions, and after cleanup your tests still pass and the feature still works. Over a few features you should see the codebase stay the same size or shrink while features grow, npx knip reports fewer unused items, and new changes get easier because there is less code to read.

ProvenanceSource & adaptation notes

Original

The reel shares one habit: after finishing a feature, ask Claude to find every piece of dead code, duplicate logic, unused components, or unnecessary complexity it just added. The creator says it finds something every time, and explains that AI-built features leave behind unused files, duplicate functions, and hard-to-understand code that piles up the longer you build. No exact prompt text, tools, or safety steps are given, and no linked written source was found.

Reel Playbooks additions

Reel Playbooks additions: the commit and cleanup-branch safety step, a ready-to-paste prompt that asks for a list before edits, review guidance for dynamically used code, cross-checking with Knip, testing and diff review, saving the prompt as a reusable rule, and the tips on duplicates, timing, and separate commits.

AttributionCredit

Original tip by Rachel (@buildinghappi) on Instagram (watch the original reel).

Adapted from @buildinghappi's video; steps expanded by Reel Playbooks.

Watch the original video

Reel Playbooks credits and links to the original creator. See For creators to request changes or removal.

BG