Codebase Cleanup
Overview
Remove clutter while preserving all functional behavior. Cleanup only - no refactoring or redesign.
When to Use
- Preparing code for production commit
- Pre-merge cleanup passes
- Removing accumulated debug artifacts
- Dead code audits
- Security and configuration reviews before release
When NOT to use: Refactoring, redesign, or functional improvements.
Core Principles
- Be conservative. If unsure whether code is used, flag it instead of deleting.
- Preserve git history readability. Group related changes logically.
- Do not refactor working logic. Cleanup only.
Quick Reference
| Category |
Remove |
Keep/Convert |
Flag for Review |
| Dead code |
No references, commented-out blocks, unreachable |
- |
Reflection/dynamic calls, test-only refs |
| Debug |
print(), console.log(), debugger, hardcoded test values |
Useful debug → structured logging |
- |
| Imports |
Unused |
- |
- |
| Comments |
Restates obvious, outdated, inline changelogs |
Explains "why", warnings, external refs |
- |
| Temp names |
temp, test, debug, foo, xxx |
- |
- |
1. Dead Code Removal
Delete
- Functions, classes, methods with no references
- Commented-out code blocks (except those marked
NOTE: or KEEP:)
- Unused imports and dependencies
- Unreachable code (after
return, in impossible branches)
Flag for Review (Do Not Delete)
- Code possibly invoked via decorators, reflection, or dynamic calls
- Functions referenced only in tests
- Any code you are <90% confident is safe to remove
2. Debug Artifact Cleanup
Remove
print(), console.log(), debugger statements
- Hardcoded test values (e.g.,
user_id = 12345)
- Temporary variable names:
temp, test, debug, foo, xxx
- Completed
TODO / FIXME comments
Convert (Do Not Remove)
- Useful debug output → structured logging with appropriate log levels
3. Code Organization
Import Order
- Standard library
- Third-party packages
- Local/project imports
(Separate groups with a blank line)
Remove
- Duplicate code blocks (Flag if behavior differs slightly)
- Redundant type annotations that add no clarity
- Excessive blank lines (max two consecutive)
4. Documentation Audit
Remove
- Comments that restate obvious code behavior
- Outdated or misleading comments
- Inline changelog notes (git handles history)
Keep
- Explanations of why, not what
- Warnings about non-obvious behavior
- Links to issues, specs, or external references
Generate/Update
- Add or update docstrings for public modules, classes, and functions
- Follow project documentation standards
5. Security & Configuration Check
Verify Absence Of
- Hardcoded credentials, API keys, tokens, or passwords
- Internal URLs, IPs, or hostnames
- Personal data or PII in fixtures
Confirm Presence Of
- Environment variable usage for secrets
- Proper
.gitignore entries (logs, env files, caches, secrets)
6. Linting & Formatting Pass
After cleanup, run project-configured linters and formatters. Fix violations introduced by cleanup, but do not refactor functional logic.
General Approach
- Run linters with project configuration
- Apply safe auto-fixes
- Flag any new rule suppressions added during cleanup
- Fix violations caused by cleanup
- Do not perform large-scale rewrites to satisfy linters
Python Example
ruff check --fix . # Lint + auto-fix
ruff format . # Format
isort . # Import sorting
pylint <modified_modules> # Additional checks
JavaScript/TypeScript Example
eslint --fix .
prettier --write .
Linting Rules of Engagement
- No new ignore comments (
# noqa, // eslint-disable) without justification
- If a lint rule conflicts with project style, flag rather than override
7. Execution Order
- Read and understand codebase structure
- Identify removal and modification candidates
- Apply changes file-by-file
- Update documentation (docstrings)
- Run linters and formatters
- Final verification: check references and run CI if available
8. Output Requirements
After completing cleanup, provide:
Summary
- Total files reviewed
- Files modified (brief description of changes)
- Approximate lines removed
Flagged Items
Recommended Follow-ups
Improvements noticed but outside cleanup scope.
Common Mistakes
| Mistake |
Fix |
| Deleting code called via reflection |
Flag instead of delete; search for string references |
| Removing "unused" test utilities |
Check test files before removing |
| Over-cleaning comments |
Keep "why" explanations, warnings, and caveats |
| Refactoring while cleaning |
Separate concerns - cleanup only |
| Batch-committing all changes |
Group related changes for readable git history |
1---2name: codebase-cleanup3description: Use when preparing codebase for production commit, removing dead code, cleaning debug artifacts, auditing security, or performing pre-merge cleanup passes4---56# Codebase Cleanup78## Overview910Remove clutter while preserving all functional behavior. **Cleanup only** - no refactoring or redesign.1112## When to Use1314- Preparing code for production commit15- Pre-merge cleanup passes16- Removing accumulated debug artifacts17- Dead code audits18- Security and configuration reviews before release1920**When NOT to use:** Refactoring, redesign, or functional improvements.2122## Core Principles2324- **Be conservative.** If unsure whether code is used, **flag it** instead of deleting.25- **Preserve git history readability.** Group related changes logically.26- **Do not refactor working logic.** Cleanup only.2728## Quick Reference2930| Category | Remove | Keep/Convert | Flag for Review |31|----------|--------|--------------|-----------------|32| Dead code | No references, commented-out blocks, unreachable | - | Reflection/dynamic calls, test-only refs |33| Debug | `print()`, `console.log()`, `debugger`, hardcoded test values | Useful debug → structured logging | - |34| Imports | Unused | - | - |35| Comments | Restates obvious, outdated, inline changelogs | Explains "why", warnings, external refs | - |36| Temp names | `temp`, `test`, `debug`, `foo`, `xxx` | - | - |3738## 1. Dead Code Removal3940### Delete41- Functions, classes, methods with **no references**42- Commented-out code blocks *(except those marked `NOTE:` or `KEEP:`)*43- Unused imports and dependencies44- Unreachable code (after `return`, in impossible branches)4546### Flag for Review (Do Not Delete)47- Code possibly invoked via decorators, reflection, or dynamic calls48- Functions referenced only in tests49- Any code you are **<90% confident** is safe to remove5051## 2. Debug Artifact Cleanup5253### Remove54- `print()`, `console.log()`, `debugger` statements55- Hardcoded test values (e.g., `user_id = 12345`)56- Temporary variable names: `temp`, `test`, `debug`, `foo`, `xxx`57- Completed `TODO` / `FIXME` comments5859### Convert (Do Not Remove)60- Useful debug output → structured logging with appropriate log levels6162## 3. Code Organization6364### Import Order651. Standard library662. Third-party packages673. Local/project imports6869(Separate groups with a blank line)7071### Remove72- Duplicate code blocks *(Flag if behavior differs slightly)*73- Redundant type annotations that add no clarity74- Excessive blank lines (max two consecutive)7576## 4. Documentation Audit7778### Remove79- Comments that restate obvious code behavior80- Outdated or misleading comments81- Inline changelog notes (git handles history)8283### Keep84- Explanations of **why**, not **what**85- Warnings about non-obvious behavior86- Links to issues, specs, or external references8788### Generate/Update89- Add or update docstrings for public modules, classes, and functions90- Follow project documentation standards9192## 5. Security & Configuration Check9394### Verify Absence Of95- Hardcoded credentials, API keys, tokens, or passwords96- Internal URLs, IPs, or hostnames97- Personal data or PII in fixtures9899### Confirm Presence Of100- Environment variable usage for secrets101- Proper `.gitignore` entries (logs, env files, caches, secrets)102103## 6. Linting & Formatting Pass104105After cleanup, run project-configured linters and formatters. Fix violations introduced by cleanup, but do not refactor functional logic.106107### General Approach108- Run linters with project configuration109- Apply safe auto-fixes110- Flag any new rule suppressions added during cleanup111- Fix violations **caused by cleanup**112- Do not perform large-scale rewrites to satisfy linters113114### Python Example115```bash116ruff check --fix . # Lint + auto-fix117ruff format . # Format118isort . # Import sorting119pylint <modified_modules> # Additional checks120```121122### JavaScript/TypeScript Example123```bash124eslint --fix .125prettier --write .126```127128### Linting Rules of Engagement129- No new ignore comments (`# noqa`, `// eslint-disable`) without justification130- If a lint rule conflicts with project style, **flag rather than override**131132## 7. Execution Order1331341. Read and understand codebase structure1352. Identify removal and modification candidates1363. Apply changes file-by-file1374. Update documentation (docstrings)1385. Run linters and formatters1396. Final verification: check references and run CI if available140141## 8. Output Requirements142143After completing cleanup, provide:144145### Summary146- Total files reviewed147- Files modified (brief description of changes)148- Approximate lines removed149150### Flagged Items151152| File | Line(s) | Concern |153|------|---------|---------|154155### Recommended Follow-ups156Improvements noticed but outside cleanup scope.157158## Common Mistakes159160| Mistake | Fix |161|---------|-----|162| Deleting code called via reflection | Flag instead of delete; search for string references |163| Removing "unused" test utilities | Check test files before removing |164| Over-cleaning comments | Keep "why" explanations, warnings, and caveats |165| Refactoring while cleaning | Separate concerns - cleanup only |166| Batch-committing all changes | Group related changes for readable git history |