Removes AI-generated code smells from a SINGLE file while preserving functionality. For multiple files, call in PARALLEL per file.
日本語の概要は準備中です。原文の説明を表示しています。
Remove AI-generated code smells (slop) from branch changes or an explicit file list. Locks behavior with regression tests FIRST, then runs categorized cleanup via parallel `deep` agents in batches of 5, then verifies with quality gates. Covers 10 slop categories including performance equivalences, excessive complexity (object annotations, if/elif variant chains), and oversized modules (250+ pure LOC with mandatory modular refactoring). MUST USE when the user asks to "remove slop", "clean AI code", "deslop", "clean up AI-generated code", "remove AI slop", or wants to clean up AI-generated patterns from recent changes. Triggers - "remove ai slops", "clean ai code", "deslop", "cleanup AI generated", "remove AI slop", "clean up AI-generated code", "strip slop", "ai-slop cleanup".
インストール方法を見るインストールする前に、エージェントに与えられる指示の中身を確認できます。
This skill may include examples copied from the OpenCode or Codex harness. In Claude Code, do not call OpenCode/Codex-only tools such as task(...), call_omo_agent(...), spawn_agent(...), background_output(...), wait_agent(...), team_*(...), send_message(...), followup_task(...), or close_agent(...) literally. Translate those examples to Claude Code native tools:
| OpenCode / Codex example | Claude Code tool to use |
|---|---|
task(subagent_type="explore", ...) / call_omo_agent(...) / spawn_agent(agent_type="explorer", ...) | the Task tool (spawn a subagent of the matching type) |
task(subagent_type="plan"/"oracle", ...) / spawn_agent(agent_type="plan"/"reviewer", ...) | the Task tool with the planner/reviewer subagent, or the Skill tool |
task(category="...", ...) | the Task tool (general-purpose subagent) or run the work inline |
background_output(...) / wait_agent(...) | await the subagent's return value / the system completion notification |
team_*(...) / send_message/followup_task/close_agent | run multiple Task subagents and synthesize their results |
When translating load_skills=[...], invoke the requested skills with the Skill tool or pass their names in the spawned subagent's prompt. If a code block below conflicts with this section, this section wins.
merge-base main (no arguments needed)Cleans AI-generated slop from a bounded set of changed files while strictly preserving behavior. Locks behavior with regression tests first, then runs a categorized multi-pass cleanup, then verifies with quality gates and a critical review. Reverts and direct-edits when verification fails.
The core safety invariant: behavior is locked by green tests before a single line is removed. A checklist alone is not safety; a passing regression test is.
The agent looks for these nine categories. The first three are stylistic, the next three are structural, the next two are about hidden cost, and the last is about behavior coverage.
Obvious comments — comments restating code, trivial docstrings, section dividers, commented-out code, vague TODOs/Notes.
# given, # when, # then, # when/then).Over-defensive code — null checks for guaranteed values, try/except around code that cannot raise, isinstance checks for statically typed params, default values for required params, backward-compat shims, redundant validation duplicated at multiple layers, broad exception catching (except Exception/except BaseException in Python, empty catch {} or catch (e) { console.error(e) } without narrowing in TypeScript/JavaScript).
main(), HTTP handler) with explicit logging + re-raise is acceptable.except Exception → catch the specific exception you expect. Empty catch {} → add instanceof narrowing or re-throw. catch (e) { log(e) } → narrow with instanceof, handle known cases, re-throw unknown.Excessive complexity — deep nesting (>3 levels), nested ternaries, complex boolean expressions (combine 4+ predicates), long parameter lists (>5 args without a struct/dataclass/object), god functions (>50 lines doing many things), overly clever one-liners that sacrifice readability, if/elif/else chains for type/enum/literal discrimination (must be match/case + assert_never), object used as a type annotation (must be Protocol, TypeVar, or explicit union).
if/else for boolean conditions and range checks (not variant discrimination).match/case with assert_never on the wildcard. object annotations → Protocol (structural), TypeVar (generic), or union (known variants).Needless abstraction — pass-through wrappers, single-use helpers, speculative indirection ("we might need this later"), interfaces with one implementer where the interface adds no testability win, factory functions that just call a constructor.
Boundary violations — wrong-layer imports (UI importing DB driver), leaky responsibilities (handler doing business logic that belongs in a service), hidden coupling (module A reads module B's private state), side effects in pure-named functions.
Dead code — unused imports, unused private functions/methods, unreachable branches, stale feature flags, debug leftovers (console.log, print(...), dbg!), removed-but-still-referenced code.
Duplication — copy-pasted branches with trivial differences, redundant helpers that do the same thing in two places, repeated literal/magic-number sequences.
Performance equivalences (behavior-preserving optimizations) — changes that are provably equivalent in semantics but cheaper in time/space:
list(...) when only iterated once → generator)join.length / len() recomputed inside loop → cacheHard rule: only apply when behavior equivalence is obvious. Do NOT change algorithms with subtle correctness implications. Do NOT micro-optimize hot paths without a benchmark. If in doubt, SKIP.
awk '!/^[[:space:]]*$/ && !/^[[:space:]]*(#|\/\/)/' <file> | wc -l.When found, do NOT just flag it. Execute a full modular refactoring:
check-no-excuse-rules.py recursively on scope to list all violations.utils.py, helpers.py, common.py, part_1.py).__init__.py re-exports (re-exports ONLY, no logic in __init__.py).check-no-excuse-rules.py again — every file must be ≤250 pure LOC. Run tests, typecheck, lint.Forbidden escapes:
foo_1.py, foo_2.py) — split by what each file DOES.utils.py, helpers.py, service.py).KEEP: genuinely self-contained single-responsibility scripts (e.g., a standalone CLI checker). Opt out with # noqa: SIZE_OK in first 5 lines and a comment explaining why.
A pass is complete only when all applicable gates are green. Skip gates that are genuinely N/A for the project (e.g., no security scanner configured), and report N/A explicitly — do not silently skip.
| Gate | Tool | Pass condition |
|---|---|---|
| Regression tests | project's test runner | all green |
| Lint | project's linter | zero errors (warnings OK if pre-existing) |
| Typecheck | lsp_diagnostics on changed files + project type-checker | zero new errors |
| Unit/integration tests | project's test runner | all green (pre-existing failures noted, not introduced) |
| Static/security scan | project's scanner | zero new findings, or N/A if not configured |
Create todos for all phases below. Mark in_progress one at a time.
If file paths were passed as arguments, that is the scope. Otherwise:
git diff $(git merge-base main HEAD)..HEAD --name-only
Filter out: deleted files, binary files, generated/vendored files (node_modules/, dist/, target/, lockfiles). List the final scope.
For each in-scope source file:
git grep / project test conventions to find related test files.If you cannot establish a green baseline (e.g., test runner is broken), STOP and report. Do not proceed with cleanup on unverified ground.
Produce an explicit plan before spawning the removal agents:
File: src/foo.py
Categories: dead code, excessive complexity, performance
Order: dead code → complexity → performance
Risk: medium (touches caching layer)
File: src/bar.py
Categories: obvious comments, over-defensive
Order: comments → defensive
Risk: low
Order rule (safest → riskiest): comments → dead code → defensive → duplication → complexity → abstraction/boundary → performance → tests → oversized-modules. This minimizes blast radius of any one change.
deep agents in batches of 5Files are processed by deep category agents with the ai-slop-remover skill loaded, batched 5 at a time in parallel. The deep category gives the agent enough thoroughness to correctly evaluate the 9 categories and respect the KEEP rules without slipping into surface fixes; the 5-wide batch is the sweet spot — more than 5 creates result-merging noise and context contention, fewer wastes parallelism.
Batching protocol (strict):
task calls in a single message, every one with run_in_background=true.<system-reminder> notifications as each task finishes.background_output(task_id=...).Never launch all files at once when there are more than 5; never launch them serially when more than one remains in the current batch.
Per-file invocation (one of the 5 in a batch):
task(
category="deep",
load_skills=["ai-slop-remover"],
run_in_background=true,
description="Slop removal: {filename}",
prompt="""
Remove AI slops from: {file_path}
In addition to your default categories (obvious comments, over-defensive code, spaghetti nesting), also evaluate these categories:
- Excessive complexity: god functions, long parameter lists, complex booleans, nested ternaries
- Needless abstraction: pass-through wrappers, single-use helpers, speculative indirection
- Boundary violations: wrong-layer imports, leaky responsibilities, hidden coupling
- Dead code: unused imports, unreachable branches, stale flags, debug leftovers
- Duplication: copy-paste branches, redundant helpers
- Performance equivalences: O(n²)→O(n) via set lookup, hoist computation out of loops, eager→lazy collections, batch redundant calls, cache repeated len()/length
Apply changes in this order (safest → riskiest): comments → dead code → defensive → duplication → complexity → abstraction/boundary → performance → oversized-modules.
Hard constraints:
- Behavior MUST be preserved. When equivalence is not obvious, SKIP.
- Do NOT change public API signatures.
- Do NOT remove type hints.
- Do NOT introduce new abstractions or dependencies.
- Diff stays minimal and scoped to slop removal.
Report changes grouped by category. For each change, give before/after, why-slop, why-safe.
For each skipped issue, give reason.
"""
)
Batch failure handling: if a deep agent in a batch fails or times out, do NOT block the remaining 4 in that batch. Collect the successful results, mark the failed file for retry in a later batch (single retry max), and continue. If retry also fails, escalate that file under "Issues Found & Fixed" in the final report.
Run the five quality gates listed above. Then walk the critical review checklist:
Safety:
Behavior:
Quality:
If any gate fails or any checklist item flips:
git checkout the affected file (or use git diff + targeted Edit to revert just the problematic hunk).If you fail three times on the same file, STOP and escalate to the user with: the file, what you tried, what failed, your hypothesis. Do not keep editing.
AI SLOP REMOVAL REPORT
======================
Scope: [branch diff vs merge-base main / explicit file list]
Files: [N files]
- path/to/file1.ts
- path/to/file2.py
Behavior Lock:
- Existing coverage: [N files already covered]
- Tests added: [M new regression tests at path/to/test_X.py]
- Baseline status: GREEN
Cleanup Plan:
- path/to/file1.ts: [dead code → complexity → performance]
- path/to/file2.py: [comments → defensive]
Per-File Results:
path/to/file1.ts
- Dead code: 3 removed (lines X-Y, A-B, C)
- Excessive complexity: 1 simplified (nested ternary at L42 → if/else)
- Performance: 1 (line N: list scan → set lookup, O(n²)→O(n), behavior identical)
- Skipped (preserved): 2 (defensive null check at boundary; commented WHY at L88)
path/to/file2.py
- Obvious comments: 5 removed
- Over-defensive: 1 simplified (redundant isinstance on typed param)
Quality Gates:
- Regression tests: PASS (12 tests, 0 failed)
- Lint: PASS
- Typecheck (lsp_diagnostics + project): PASS (0 new errors on changed files)
- Unit/integration tests: PASS (45 tests, 0 failed)
- Static/security scan: N/A (not configured)
Critical Review:
- Safety: PASS
- Behavior: PASS
- Quality: PASS
Issues Found & Fixed:
- [None] OR [Issue description → Fix applied]
Remaining Risks / Deferred:
- [None] OR [e.g., "boundary violation in module X flagged but not refactored — needs human judgment"]
Final Status: CLEAN | ISSUES FIXED | REQUIRES ATTENTION
N/A and why. If a check failed and you could not fix it, say so. Never claim PASS without evidence.lsp_diagnostics, the test runner, and direct file reads until the result is grounded.まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Removes AI-generated code smells from a SINGLE file while preserving functionality. For multiple files, call in PARALLEL per file.
日本語の概要は準備中です。原文の説明を表示しています。
Use when Codex needs to understand or respond to automatic comment-checker feedback emitted after an edit-like PostToolUse hook.
日本語の概要は準備中です。原文の説明を表示しています。
MUST USE for any real runtime debugging across ANY language or binary — crashes, silent failures, wrong responses, stuck processes, memory leaks, async misbehavior, unexplained timing, reverse engineering. Runs a hypothesis-driven loop: form ≥3 hypotheses, investigate in parallel, after 2 failed rounds spawn Oracles from orthogonal angles, confirm root cause, lock with a failing test, fix minimally, QA by actually USING the system, scrub artifacts. The actual HOW lives in `references/` — READ THEM. Triggers: 'debug this', 'why is X not working', 'hanging', 'attach a debugger', 'reverse engineer', 'pwndbg', 'gdb', 'lldb', 'node inspect', 'tsx debug', 'pdb', 'dlv', 'delve', 'rust-gdb', 'set a breakpoint', 'context window exploded', 'why is the response empty', 'attach the debugger', 'debug it', 'why is this happening', 'trace this bug', 'reproduce and fix', 'silent failure', 'HTTP 200 but empty', 'why did it stop', 'inspect the binary', 'reverse engineering', 'playwright'.
日本語の概要は準備中です。原文の説明を表示しています。
Designer-turned-developer who crafts stunning UI/UX even without design mockups
日本語の概要は準備中です。原文の説明を表示しています。
(builtin) Initialize hierarchical AGENTS.md knowledge base
日本語の概要は準備中です。原文の説明を表示しています。
Use when Codex needs language-server diagnostics, definitions, references, symbols, or rename safety checks in the current workspace.
日本語の概要は準備中です。原文の説明を表示しています。