Code Cleanup
Remove AI-generated patterns from code changes while preserving intentional functionality.
Workflow
- •Get the diff:
git diff master...HEAD(or specified base branch) - •For each changed file, compare new code against the file's existing style
- •Remove identified slop patterns
- •Report a 1-3 sentence summary of changes, with ✅ Files Cleaned (12) -filelist- 👀 Read But Clean (3) -filelist- ❌ Not Yet Checked (29) -filelist-
- •Continue working through "Not Yet Checked" files
- •If there are no files left, report a summary of your activities to the user
Slop Patterns to Remove
Unnecessary comments
- •Obvious comments (
// increment counter,// return the result) - •Section dividers inconsistent with file style
- •Comments explaining what code does rather than why
Defensive overkill
- •Try/catch blocks around code that can't throw or is already in trusted paths
- •Null checks where values are guaranteed
- •Type guards that duplicate existing validation
Type escapes
- •Casts to
anyto bypass type errors - •
@ts-ignore/@ts-expect-errorwithout justification - •Overly loose generic types (
Record<string, any>)
Style inconsistencies
- •Naming conventions that differ from the file (camelCase vs snake_case)
- •Brace/spacing style that doesn't match surrounding code
- •Import organization that breaks file patterns
Drizzle artifacts to revert
- •Changes to
_journal.jsonfiles (migration journal) - •Changes to Drizzle snapshot files (
meta/*_snapshot.json) - •Auto-generated migration files that weren't intentionally created
- •Revert these with:
git checkout master -- <file>or remove from staging
Duplicate hooks/utilities
- •Multiple files with the same name serving similar purposes—consolidate to one
- •Read-only hooks when a CRUD hook already exists for the same entity
- •Delete the simpler duplicate, update imports to use the complete version
Redundant error handling
- •
onErrorhandlers in mutations when QueryClient already handles errors globally viaMutationCache.onError - •Duplicate toast notifications that the global handler already shows
- •Check App.tsx or QueryClient setup before adding per-mutation error handlers
Manual cache invalidation
- •Direct
queryClient.invalidateQueries()calls whenuseOptimismhook is available - •Use
useOptimismfunctions instead:- •
optimisticalltyAddToListfor create operations - •
optimisiticallyUpdateObjectInListfor updates - •
optimisticallyRemoveFromList+revertOptimisticUpdatefor optimistic deletes - •
syncCacheWithServerfor post-mutation sync
- •
One-off mutations duplicating existing hooks
- •Components creating mutations that already exist in nearby hooks
- •A "bulk" action hook can handle single items—use it instead of creating a new mutation
- •Look for existing
use*Actionsoruse*Mutationshooks before creating inline mutations
Guidelines
- •Preserve functionality—only remove stylistic slop
- •When uncertain, match the existing file's conventions
- •Keep the summary brief: what categories of slop were found and removed