home/roleplay/ch08-cleanup

Ch08 Cleanup

GPTClaudeGemini··1,068 copies·updated 2026-07-14
ch08-cleanup.prompt
# Chapter 8 prompts — Clean Up the Mess Claude Made

**Hour block: hours 35-40** of the book's 48-hour build.

> **Access requirement:** every prompt below is pasted into an interactive Claude
> Code terminal session, and Claude Code requires Pro or higher — the free plan
> does not include it (ch03:31). This repository never runs any of these prompts,
> and neither does its CI. They are documentation, not executable code.

**The full pack, with every prompt transcribed verbatim: [`prompts/ch08-cleanup.md`](../../prompts/ch08-cleanup.md)**
The pack is the source of truth for exact prompt text; this page is the guide to
navigating it.

## What this chapter's prompts do

Claude doesn't remember what it built three conversations ago, so a project built
over many sessions accumulates dead code, duplicate utilities, and a file structure
that drifted from whatever plan it started with. This chapter's prompts find and
remove dead code (with a guard prompt that catches dynamically-used code before
it's deleted), consolidate duplicate functions, reorganize the file tree, split
oversized components (and just as importantly, decide when *not* to split one),
run three safe mechanical refactors, and audit CLAUDE.md itself for staleness. It
closes with a 23-minute monthly routine meant to run every month going forward, not
just once.

## When you use them

Hours 35-40, after the app is functional (Chapter 3), styled (Chapter 4), and
secured and tested (Chapter 7). Before you start, count your files
(`find src -name "*.ts" -o -name "*.tsx" | wc -l`) and write the number down — the
chapter's checkpoints measure against that baseline. Run each cleanup prompt in a
fresh conversation, and run `npm test` after every step that touches code.

## Index of every prompt in the pack

| # | Prompt | Cite | What it does |
|---|---|---|---|
| 1 | Scan for dead code | ch08:26-78 | Lists unused imports, orphaned files, and uncalled functions with file paths and line numbers |
| 2 | ⭐ The dynamic-usage guard | ch08:56-59 | Checks whether a flagged "dead" function is actually used dynamically before you delete it |
| 3 | Delete confirmed dead code | ch08:66-68 | Deletes only the items you confirmed — "do not touch anything I did not confirm" |
| 4 | Find duplicate utilities | ch08:80-136 | Groups functions/components that do the same thing across different files, with a keep/delete recommendation per group |
| 5 | Merge duplicates | ch08:105-106 | Merges a duplicate group into one canonical file and updates every import |
| 6 | Reorganize the file structure | ch08:138-197 | Moves components, utilities, and types into the book's standard Next.js folder layout |
| 7 | Split oversized components | ch08:201-248 | Splits any component over 100 lines into smaller, focused pieces |
| 8 | Split-or-leave verdict | ch08:224-240 | Asks Claude to judge each oversized file as "multiple concerns, split" or "one cohesive feature, leave it" |
| 9 | Extract constants | ch08:250-285 | Pulls magic numbers and hardcoded strings into named constants |
| 10 | Type-inference cleanup | ch08:250-285 | Removes redundant type annotations, adds explicit ones where inference currently falls back to `any` |
| 11 | Organize imports | ch08:250-285 | Groups imports (external, then local, then relative) and removes unused ones |
| 12 | CLAUDE.md audit | ch08:287-333 | Removes stale rules and references to deleted files, adds established patterns, keeps it under 30 lines |
| 13 | Measure the impact | ch08:372-391 | Adds a "last modified" timestamp to a task card as a before/after file-read comparison |
| 14 | ⭐ The monthly cleanup one-shot | ch08:404-411 | Runs dead-code removal, duplicate merging, structure check, and CLAUDE.md update in order, showing findings before changing anything |

14 prompts.

## The signature prompts

### The dead-code prompt (ch08:33-39)

when to use it

Community prompt sourced from the open-source GitHub repo regardo911/claude-code-beginners (MIT). A "Ch08 Cleanup" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

roleplaycommunitygeneral

source

regardo911/claude-code-beginners · MIT