From deslop
Scans a Python directory for AI-generated code bloat ("slop") across 6 categories: over-defensive code, premature abstractions, dead weight, verbose patterns, structural bloat, and documentation/logging noise. Uses weighted scoring (1.5x for structural categories) and systematic verification (caller counts, data tracing, parameter tax). Calculates slop density and offers to auto-fix. Trigger phrases: "deslop", "scan for slop", "reduce slop", "clean up slop", "slop check", "find slop", "remove slop from directory".
How this skill is triggered — by the user, by Claude, or both
Slash command
/deslop:deslopThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Scan `$ARGUMENTS` (or the current working directory if omitted) for AI-generated code bloat, calculate a weighted slop density score, and offer to auto-fix.
Scan $ARGUMENTS (or the current working directory if omitted) for AI-generated code bloat, calculate a weighted slop density score, and offer to auto-fix.
If $ARGUMENTS is provided, treat it as a directory path (absolute or relative to cwd). Verify it exists. If not provided, use the current working directory. Store as TARGET_DIR.
Use Glob with these patterns rooted at TARGET_DIR:
Include:
**/*.py — Python source files**/*.yaml, **/*.yml, **/*.toml, **/*.json, **/*.cfg — config filesExclude (skip entirely):
**/evaluation/data/****/*.lock**/*.pyc**/*.md**/few_shot_examples/**/*.json and similar data-directory JSON**/__pycache__/****/outputs/****/.venv/**, **/node_modules/**Remove any file matching:
tests/ or test/ at any depthtest_*.py or *_test.py at any depthconftest.py filesNote: Test files are excluded from scanning but are still included as search targets during Grep-based caller-count verification in Step 2b.
For each remaining file, count the number of non-empty lines. Sum to get total_lines.
Print: Scanning N files (P Python, C config) in TARGET_DIR. Total non-empty lines: T.
Exit criteria: Complete list of files to scan, with line counts collected.
Read each file in full using the Read tool. Scan the full file contents against the AI Slop Pattern Taxonomy below. Every non-empty line in every file is eligible for slop detection.
For each finding, record:
S1, S2, S3, ... (sequential across all files)1.0x (Cat 1, 4, 6) or 1.5x (Cat 2, 3, 5) — Config excluded from scoringRead output line numbers)Before finalizing any finding, apply the relevant verification technique(s). A finding that fails verification must be discarded.
Caller count verification — Required for: one-caller wrappers (Cat 2), zero-caller code (Cat 3), delegation chains (Cat 5).
Use Grep to search the entire project (including test files) for call sites of the function/class. Count unique callers (not just matches — deduplicate by call site). A function called from 2+ distinct locations is NOT a one-caller wrapper. A function called from tests only may still be dead weight if it has no production callers.
Data tracing — Required for: unused parameters (Cat 3), configuration mirage (Cat 2). Trace each parameter from its declaration through the function body. Does the parameter's value influence the return value or a side effect? If yes, it is not dead weight. For "configuration" constants, check whether any code path reads the value dynamically (not just at import time).
Parameter tax analysis — Required for: intermediate data structures (Cat 2), pre-computed state (Cat 3). Count how many lines exist solely to build, pass, or unpack the intermediate structure. If removing the structure would eliminate more lines than it creates, it is dead weight. If the structure is used in 2+ distinct contexts, it earns its keep.
Call chain depth mapping — Required for: delegation chains (Cat 5). Map the call chain from the public API entry point to the actual logic. If there are ≥2 intermediate functions that only delegate (add no logic, no error handling, no branching), the chain is a finding. If any intermediate function adds meaningful behavior, the chain is justified.
Guard reachability check — Required for: unreachable guards (Cat 1), redundant isinstance (Cat 1).
Check the type annotation and all callers. If every caller passes a non-None value and the type hint is non-Optional, the None guard is unreachable. If the type is Any or Optional, the guard is justified.
Attribute access count — Required for: wrapper classes (Cat 2), intermediate data structures (Cat 2). Count how many unique attributes/methods of the wrapper are accessed by external code. If only 1-2 attributes are used, the wrapper is over-engineered. If 3+ attributes are meaningfully used, it may earn its keep.
If there are more than 30 Python files, use the Task tool to parallelize analysis across file groups.
Exit criteria: All files analyzed. Findings list complete with IDs, pattern names, categories, weights, code snippets, and line-saved estimates. All findings have passed systematic verification.
See references/pattern-catalog.md for full before/after code examples for every pattern.
if x is not None on values that cannot be None (required params with non-Optional types)try/except around operations that cannot raise the caught exceptionisinstance() on values whose type is statically known.get() on dicts where the key is guaranteed to existtry/except that catches exceptions and returns a default value, silently hiding errors that should propagateif condition: return True else: return False instead of return conditionstr.join()dict() / list() constructor instead of {} / [] literallen(x) == 0 / len(x) > 0 instead of truthiness checkelse after return / raise / continueif nesting that could be flattened with guard clausesCalculate:
raw_slop_lines: sum of estimated lines saved across all findingsweighted_slop_lines: sum of lines_saved * weight for each finding (Config findings excluded)total_lines: sum of non-empty lines across all scanned files (from Step 1)slop_density: (weighted_slop_lines / total_lines) * 100Interpret the score:
| Slop Density | Rating |
|---|---|
| 0–5% | Excellent — minimal slop |
| 5–15% | Good — minor cleanup possible |
| 15–30% | Needs work — significant bloat |
| 30%+ | Heavy slop — major cleanup needed |
If no findings, output:
Directory looks clean. N files scanned (T total lines), no significant slop detected.
And stop. Do not proceed to Steps 4–5.
## Slop Analysis: <directory-path>
### Score
- **Slop density: XX%** (<rating>) — weighted
- Files scanned: N (T total non-empty lines)
- Raw slop lines: R | Weighted slop lines: W
- Potential reduction: T → T-R lines (YY% smaller)
### Findings (ranked by weighted lines saved, highest first)
**S1** — **<Pattern Name>** — Cat <N> (<weight>) — `file.py:10-25` — **~15 lines saved**
> <description of the slop>
```python
# Current (slop)
<offending code>
# Suggested (idiomatic)
<replacement code>
S2 — ...
| Category | Weight | Findings | Raw Lines | Weighted Lines |
|---|---|---|---|---|
| 1. Over-defensive code | 1.0x | 2 | 15 | 15.0 |
| 2. Premature abstraction | 1.5x | 1 | 8 | 12.0 |
| 3. Dead weight | 1.5x | 1 | 10 | 15.0 |
| 4. Verbose patterns | 1.0x | 4 | 12 | 12.0 |
| 5. Structural bloat | 1.5x | 0 | 0 | 0.0 |
| 6. Documentation noise | 1.0x | 1 | 3 | 3.0 |
| Subtotal | 9 | 48 | 57.0 | |
| Config slop (unweighted) | — | 1 | 3 | — |
## Step 4: Auto-Fix (Plan Mode)
After presenting the report, call `EnterPlanMode` with a plan that includes:
1. The full findings table from Step 3
2. A changes list: file, line range, what to change, finding ID, weight
3. Execution order: by file (minimize file opens), within each file by line number **descending** (avoid offset drift from earlier edits shifting later line numbers)
4. Apply Category 6 (documentation noise) fixes last — they are lowest risk and lowest impact
5. Verification plan: the project's verification suite (e.g., `pre-commit run --all-files`)
**Do not proceed until the user explicitly approves the plan.**
After plan approval, execute:
1. **Read** each file before editing (mandatory)
2. **Apply fixes** using the Edit tool, working from bottom to top within each file
3. **Run pre-commit**: `pre-commit run --all-files` (or project equivalent)
4. If pre-commit fails, fix lint/format/type issues and re-run (max 3 iterations)
5. If pre-commit still fails after 3 iterations, stop and report the failures
**Exit criteria:** All approved fixes applied. Pre-commit passes (or remaining failures reported after 3 iterations).
## Step 5: Report Results
| # | File | Finding | Weight | Lines Saved |
|---|---|---|---|---|
| 1 | foo.py | S1: Removed unreachable guard | 1.0x | -12 |
| 2 | bar.py | S3: Inlined one-caller helper | 1.5x | -8 |
Never auto-commit. Leave that to the user.
## Important Guidelines
- **Full-file scanning** — Scan every non-empty line in every eligible file. All slop in the scanned directory is in scope, regardless of when it was introduced.
- **Works without git** — This skill does not require a git repository. It operates on filesystem paths only. Never invoke `git` or `gh` commands.
- **Documentation noise IS in scope** — Category 6 covers comments that restate the code, docstrings that just repeat the function signature, redundant logging, and empty docstring sections. However, useful documentation (explains *why*, documents non-obvious behavior, describes complex algorithms) is NOT slop. When in doubt, leave it.
- **Caller count is mandatory** — For Categories 2, 3, and 5, you MUST run `Grep` to verify caller counts before finalizing any finding. A finding without caller-count verification is invalid. Search the entire project including test files.
- **Weighted scoring** — Categories 2 (Premature Abstraction), 3 (Dead Weight), and 5 (Structural Bloat) carry 1.5x weight because structural issues are harder to detect and cause more long-term harm than surface-level verbosity.
- **Delete-then-reason test** — For any finding you're uncertain about: mentally delete the code and ask "what breaks?" If nothing breaks and no information is lost, it's slop. If something breaks or the code serves a documented purpose, it's not.
- **Structural awareness** — For Categories 2, 3, and 5 (the 1.5x-weighted categories), every finding must include a verification note explaining what technique was used and what the result was. Findings without verification notes are invalid.
- **Absolute standard** — Judge against ideal Python idioms, not surrounding codebase style. The goal is to write the best possible Python, not to match existing patterns that may themselves be sloppy.
- **Preserve functionality** — Every suggested change must be behavior-preserving. Never remove error handling at system boundaries.
- **Python + config** — Analyze `.py` files for code slop; flag noise in config files.
- **Read before editing** — Always read the full file before making any changes (during the fix phase).
- **Never fabricate findings** — Only flag patterns you can verify from the actual file contents. If you're unsure whether something is slop, leave it alone.
- **Respect system boundaries** — Input validation on user input, external APIs, and public interfaces is NOT slop.
- **Test files excluded from scanning** — Test files are excluded at discovery time (Step 1) and are never scanned. However, test files ARE included in `Grep` searches during verification (Step 2b) to get accurate caller counts.
- **Minimal changes** — Only change code that matches a slop pattern. Don't "improve" unrelated code.
- **Bottom-to-top editing** — When applying fixes within a file, work from the highest line number to the lowest to prevent offset drift.
npx claudepluginhub zaffnet/deslop.it --plugin deslopDetects codebase bloat via progressive analysis tiers covering dead code, duplication, complexity, doc bloat, AI-generated patterns, dependencies, and git history. For maintenance, refactoring prep, and pre-release cleanup.
Detects and strips AI-generated slop from code: simplifies unnecessary complexity, removes rotten comments, checks design patterns. Runs on git changes or paths before PRs.
Detects and auto-fixes AI slop in code (debug leftovers, placeholders, hardcoded credentials) using a three-phase certainty scan, safely applying only deterministic HIGH fixes and verifying with tests.