Deslop removes AI-generated code bloat from your branch before committing. It checks the diff against main and cleans up unnecessary comments, defensive code, premature abstractions, and over-engineering that AI agents tend to add.
“Three similar lines of code is better than a premature abstraction.” — Clean up the slop.
Comments that state what the code already saysRemove:
// Increment the countercounter++;// Return the user objectreturn user;// Loop through itemsfor (const item of items) {
Keep:
// Hash password with bcrypt (rounds=10) to prevent timing attacksconst hash = await bcrypt.hash(password, 10);// Use XOR cipher to match legacy API format (remove after v2 migration)const encrypted = xorEncrypt(data);
Defensive Try/Catch
Try/catch blocks for trusted internal code pathsRemove:
// In internal helper functiontry { const result = JSON.parse(jsonString); return result;} catch (error) { console.error('Parse failed:', error); return null;}
Keep:
// For external API calls or user inputtry { const response = await fetch(externalApi); return await response.json();} catch (error) { logger.error('External API failed', error); throw new ExternalServiceError(error);}
Any Casts
Using any to bypass type issues instead of fixing themRemove:
const data = response as any;const value = (input as any).someProperty;
Fix:
const data = response as UserResponse;const value = isInputWithProperty(input) ? input.someProperty : undefined;
Premature Abstractions
Helpers, factories, or abstractions used only onceRemove:
// Used only oncefunction createUserValidator() { return (user: User) => { return user.email && user.name; };}const validator = createUserValidator();if (!validator(user)) { throw new Error('Invalid user');}
Inline:
if (!user.email || !user.name) { throw new Error('Invalid user');}
Deeply Nested Code
Nested conditions that should use early returnsRemove:
function processUser(user: User | null) { if (user) { if (user.isActive) { if (user.email) { return sendEmail(user.email); } } } return null;}
Flatten:
function processUser(user: User | null) { if (!user) return null; if (!user.isActive) return null; if (!user.email) return null; return sendEmail(user.email);}
// Legacy export for backwards compatibilityexport const oldFunctionName = newFunctionName;// Renamed but keeping old referenceconst _deprecatedVar = newVar;// // Removed old implementation// function oldWay() { ... }
Clean:
// Just the new implementationexport const newFunctionName = ...;
Scope Creep
Features, refactoring, or improvements beyond what was requestedRemove:
# Original task: Add login endpoint+ feat: add login endpoint+ feat: add password reset endpoint # Not requested+ refactor: extract auth helpers # Not requested+ docs: add API documentation # Not requested
If you added unrequested features, either:
Remove them (preferred)
Commit separately with justification
Added Documentation on Unchanged Code
Docstrings, type annotations, or comments on code that wasn’t changedRemove:
// File: src/utils/old-code.ts// You only changed one function, but added docs to all functions- function existingFunction() { ... } // Unchanged+ /**+ * Existing function that does X+ * @returns Y+ */+ function existingFunction() { ... } // Still unchanged
Impossible Error Handling
Error handling for scenarios that can’t happen in trusted codeRemove:
// In internal function with typed parametersfunction add(a: number, b: number): number { if (typeof a !== 'number' || typeof b !== 'number') { throw new Error('Parameters must be numbers'); } return a + b;}
Keep:
// Simple and trusts the type systemfunction add(a: number, b: number): number { return a + b;}
User: "Clean up this code before I commit"Claude: Checking for slop in branch diff...Found: 5 obvious commentsBefore:```typescript// Get the user from databaseconst user = await db.users.findOne({ id });// Check if user existsif (!user) { throw new Error('User not found');}// Return the user objectreturn user;
After:
const user = await db.users.findOne({ id });if (!user) { throw new Error('User not found');}return user;
Removed 3 obvious comments. Tests passing.
### Example 2: Premature Abstraction```bashUser: "This feels over-engineered"Claude: Checking for premature abstractions...Found: Helper function used only onceBefore (src/api/users.ts):```typescriptfunction createEmailValidator() { return (email: string) => { const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return regex.test(email); };}const validateEmail = createEmailValidator();if (!validateEmail(user.email)) { throw new Error('Invalid email');}
After:
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;if (!emailRegex.test(user.email)) { throw new Error('Invalid email');}
Removed factory function (used only once). Tests passing.
This is an internal helper with typed input. The try/catch is unnecessary.After:
function formatDate(date: Date): string { return date.toISOString();}
Removed defensive try/catch from internal helpers. Tests passing.
### Example 4: Nested Code```bashUser: "Flatten this nested logic"Claude: Simplifying nested conditions with early returns...Before:```typescriptfunction processOrder(order: Order | null) { if (order) { if (order.isPaid) { if (order.items.length > 0) { if (order.shippingAddress) { return shipOrder(order); } else { throw new Error('No shipping address'); } } else { throw new Error('No items'); } } else { throw new Error('Order not paid'); } } else { throw new Error('No order'); }}
After:
function processOrder(order: Order | null) { if (!order) throw new Error('No order'); if (!order.isPaid) throw new Error('Order not paid'); if (order.items.length === 0) throw new Error('No items'); if (!order.shippingAddress) throw new Error('No shipping address'); return shipOrder(order);}
## Integration with Pro Workflow<CardGroup cols={2}> <Card title="Smart Commit" icon="code-commit" href="/skills/smart-commit"> Run deslop before smart-commit for clean commits </Card> <Card title="Wrap-Up" icon="check-circle" href="/skills/wrap-up"> Wrap-up can trigger deslop during quality check </Card> <Card title="Orchestrate" icon="diagram-project" href="/skills/orchestrate"> Review phase includes deslop before committing </Card> <Card title="Learn Rule" icon="graduation-cap" href="/skills/learn-rule"> Capture patterns: "Don't add obvious comments" </Card></CardGroup>## Configuration### Auto-Deslop Before CommitAdd to CLAUDE.md:```markdown## Before Commits1. Run /deslop to remove AI slop2. Run quality gates3. Commit with /smart-commit