| name | finalize |
| description | Prepare code for commit by checking for bugs, ensuring consistency, removing debug code, and running checks until green. Use when finishing a feature, before committing, or when asked to "make it green" or "prep for commit".
|
Finalize
Prepare code for commit by systematically checking for issues and running checks until everything passes.
When to Use
Invoke /finalize when:
- Finishing a feature or bug fix
- User asks to "make it green", "prep for commit", or "production ready"
- Before handing code back to user for commit
- After a significant implementation session
Note: This skill prepares code for commit but does NOT create the commit itself.
Before Starting
-
Identify scope - What files were changed in this session?
git diff --name-only HEAD
git diff --cached --name-only
-
Understand context - What was implemented? This informs what edge cases to check.
Phase 1: Bug Check
Review changed files for common bugs and edge cases.
Checklist
Null/Undefined Handling:
Edge Cases:
Logic Errors:
Type Safety:
Phase 1b: Critical Path Review
Configure this section for your project's high-risk areas.
Common critical areas include:
- Authentication/Identity: Token handling, session management, privilege escalation
- Data pipelines: Idempotency, deduplication, ordering guarantees
- External integrations: Rate limits, retry logic, credential handling
- Infrastructure provisioning: State drift, rollback strategy, resource cleanup
Add your project-specific critical areas to CLAUDE.md.
If changes touch critical areas, do multiple passes:
- Pass 1: Structural issues (transactions, error handling, idempotency)
- Pass 2: Logic gaps (edge cases, boundary conditions)
- Pass 3: Recovery scenarios (partial failure, retry, concurrent access)
At Each Database Operation (if applicable)
Trace End-to-End Scenarios
- ✓ Normal flow (happy path)
- ✓ Network retry (API retry with same data)
- ✓ Partial failure (step 1 succeeds, step 2 fails)
- ✓ Race condition (two processes try same operation)
- ✓ Recovery (retry after previous failure)
Phase 2: Consistency Check
Verify code follows project patterns.
Checklist
Naming:
Imports:
Patterns:
Structure:
Phase 3: Production Readiness
Remove debug artifacts and ensure code is production-ready.
Debug Code Removal
Search for and remove:
git diff --name-only HEAD | xargs grep -l "console.log" 2>/dev/null
git diff --name-only HEAD | xargs grep -l "debugger" 2>/dev/null
git diff HEAD | grep "^+" | grep -E "//.*[a-zA-Z]+.*\(|/\*"
Remove these:
console.log() - Remove unless it's intentional production logging
console.debug() - Remove all
console.warn() - Keep only if warning is useful in production
console.error() - Keep if it's error reporting
debugger statements - Remove all
- Commented-out code - Remove unless there's a clear reason
// TODO from this session - Keep and warn user (see below)
- Test data / hardcoded values - Replace with real implementation
Production Logging Guidelines:
console.error() - OK for actual errors that should be visible
- Structured logging (logger.info/warn/error) - OK if using logging framework
- Any other console.* - Remove
TODO Handling
Search for TODOs in changed files:
git diff --name-only HEAD | xargs grep -n "TODO\|FIXME\|XXX\|HACK" 2>/dev/null
Action:
- If TODO was created in this session: Warn user - present the list and ask if they should be addressed or left
- If TODO existed before: Leave as-is
- Never silently remove TODOs
Other Production Checks
Phase 4: Run Tests
Run the test suite to catch regressions:
npm test
If tests fail:
- Identify which tests failed
- Determine if failure is due to:
- Bug in new code → Fix it
- Test needs updating for new behavior → Update test
- Unrelated flaky test → Note and continue
- Re-run tests after fixes
Test Coverage:
- New functionality should have tests
- If no tests exist for changed code, warn user
Phase 5: Make It Green
Run the full check suite and fix issues iteratively.
npm run check
Iteration Loop
1. Run check command
2. If passes → Done!
3. If fails:
a. Identify the failing step (format/lint/typecheck/build)
b. Fix the issues
c. Go to step 1
Common Fixes
Format issues:
- Usually auto-fixed by formatter
- If persisting, check for syntax errors
Lint issues:
- Read the error message carefully
- Common: unused imports, missing dependencies
- Fix: Remove unused code, add missing deps
Type issues:
- Type mismatches: Check expected vs actual types
- Missing properties: Add required fields or make optional
- Import errors: Check package exports
Build issues:
- Usually caused by type errors
- Check for circular dependencies
- Verify all imports resolve
Max Iterations
If after 5 iterations issues persist:
- Stop and report remaining issues
- Ask user for guidance on unresolved problems
Final Report
After all phases complete, present summary:
## Finalize Summary
### Changes Reviewed
- {N} files checked
### Issues Found & Fixed
- Removed {N} console.log statements
- Fixed {N} lint errors
- Fixed {N} type errors
### Warnings
- {N} TODOs remain in code:
- `path/to/file.ts:123` - TODO: description
### Status
✅ All checks passing - Ready for commit
### Files Changed
{list of files modified during finalize}
Checklist
Before completing:
Anti-Patterns
console.log('data:', data)
debugger
logger.error('Failed to process request', { id, error })
git commit -m "..."
Reference Files
- Project conventions:
CLAUDE.md
- Check command:
package.json (or project-specific config)
- Lint config: Project's lint configuration
- Test config: Project's test configuration