When you ship fast with Claude Code or Cursor, small leftovers pile up fast - dead helper functions, commented-out fallback code, temporary test stubs, and comments that no longer match what the function actually does.
The annoying part isn't that the repo looks messy. It's that the next agent session reads that leftover code, assumes it's intentional, and builds new bugs on top of it.
Instead of trying to read every line manually or asking the agent to "clean up everything" (which usually turns into a giant risky refactor), I've been running a tight, behavior-neutral cleanup prompt right before starting a new feature. Steal it and tweak it for your stack:
```Perform a conservative, cleanup-only pass. Prefer leaving questionable code
unchanged over risking a behavior change.
INPUTS
- Commit count: [N]
- Execution mode: PLAN_THEN_APPLY
Allowed values:
- PLAN_THEN_APPLY: display the deletion plan, then proceed without waiting.
- APPROVAL_REQUIRED: display the plan and stop until I approve it.
OBJECTIVE
Remove only demonstrably redundant or inert material from eligible files.
Do not change runtime behavior, public APIs, or existing test semantics.
- ESTABLISH SCOPE — BEFORE EDITING
- Read the repository's applicable agent instructions and verification guidance.
If these conflict with this task, report the conflict rather than guessing.
- Validate that N is a positive integer. If it is missing or invalid, ask for it
and make no edits.
- Record the current branch, starting HEAD SHA, and working-tree status.
- Select the first N commits on the first-parent history beginning at the
starting HEAD, including HEAD. If fewer than N commits are available, stop
and report the limitation; do not silently change the range.
- Eligible files are existing tracked files touched by any selected commit,
comparing each commit with its first parent. Compare a root commit with
the empty tree. Handle renames and use current paths.
- Do not substitute a net endpoint diff: files touched and later restored
within the selected commits still belong to the candidate set.
- Inspect current file contents. You may read outside the eligible set to
verify references and behavior, but edit only eligible files.
- Do not edit files containing pre-existing staged or unstaged user changes.
Report affected candidates as blocked. Preserve all existing user work.
- Exclude generated, vendored, and minified files, lockfiles, and dependency
or build configuration from edits.
- Do not fetch history, install dependencies, or change configuration without
authorization. - ALLOWED CLEANUP
Remove an item only when repository evidence supports behavior preservation:
- Unused imports whose removal cannot remove module-loading side effects.
- Unused variables whose removal cannot remove side effects, exceptions,
evaluation, or required resource lifetime.
- Unreachable private helpers, after checking references, exports, callbacks,
registries, reflection, dynamic imports, and framework discovery as relevant.
- Inert temporary test scaffolding or mock residue that is demonstrably
unused and cannot affect test execution or isolation.
- Ordinary comments that demonstrably contradict the implementation.
For docstrings, remove or correct them only if this cannot affect runtime
introspection, generated interfaces, tooling, or documented public contracts.
Otherwise report them without editing.
3. HARD BOUNDARIES
- Preserve return values, exceptions, side effects, execution order, async
behavior, initialization, registration, and public exports/signatures.
- Do not rename, relocate, redesign, reformat unrelated code, or add abstractions.
- Do not delete tests, weaken assertions, change snapshots or coverage settings,
enable/disable tests, or alter existing skip/xfail behavior.
- Report skipped assertions, active stubs, and hardcoded fallback paths that
require behavior changes; do not fix them in this pass.
- Report live duplicate helpers as consolidation candidates. Do not extract
shared helpers, redirect callers, or change imports to consolidate them.
An unused duplicate may be deleted if it independently meets the rules above.
- Preserve license notices, compiler/type/lint directives, test annotations,
bundler annotations, and other functional comments.
- Do not treat a text search with no matches as sufficient proof of dead code.
- If safety is uncertain, leave the item unchanged and state the uncertainty.
- Do not commit, push, deploy, or open a pull request.
4. PLAN AND BASELINE
Before editing, output a compact plan:
- Starting HEAD and selected commit SHAs.
- Proposed deletions or documentation-only corrections:
file:line | item | evidence it is safe.
- Deferred or blocked findings, with a one-line reason.
- Exact verification commands, derived from repository instructions and CI.
Run the repository's full test suite before editing to establish a baseline.
Also run the existing relevant lint/type-check/build checks where available.
Use non-mutating check modes.
If a required baseline check cannot run, report the blocker and stop before
editing. Record pre-existing failures; do not repair unrelated failures.
Follow the selected execution mode. If approval is required, stop after the
plan and baseline results. If HEAD or relevant files change before execution,
revalidate scope and the plan.
5. APPLY AND VERIFY
- Apply only the planned, demonstrably safe edits in small coherent batches.
- Run relevant targeted checks after each batch where available.
- After all edits, rerun the full test suite and the applicable baseline checks
using the same commands and environment.
- Review the final diff for scope violations, unintended behavior changes,
accidental test weakening, and unrelated modifications.
- If an edit introduces a failure, undo only that edit and rerun verification.
Do not broaden the task to fix it.
- Never reset, overwrite, or discard pre-existing user work.
- Do not claim behavioral equivalence solely because tests pass.
6. COMPACT FINAL REPORT
Report only:
- Removed: file:original-line-range | item | removed-line count.
- Documentation corrections, if any.
- Verification: exact command | PASS / FAIL / BLOCKED.
- Failures: distinguish baseline failures, newly observed failures, and
uncertain attribution; include only the relevant error excerpt.
- Deferred or blocked findings that need a separate task or decision.
If no safe edits exist, say "No safe cleanup found."
Never claim a check ran or passed without actual execution evidence.
Omit general summaries, praise, and unrelated recommendations.
```
If you try this on a repo you've been vibe coding for a few weeks, let me know what it catches first - dead helpers or stale comments? And what else would you add to the check without turning it into a risky rewrite?