Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Ai Code Cleanup

ASecurity

Remove AI-generated code slop from branches. Use after AI-assisted coding

416 stars
0 votes
0 copies
1 views
Added 2/7/2026
developmentjavascripttypescriptrustgojavabashrefactoringgitapidocumentation

Works with

api

Security Analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned 2/12/2026

$npx -y skills add aiskillstore/marketplace --skill ai-code-cleanup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ai Code Cleanup?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Ai Code Cleanup
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aiskillstore-ai-code-cleanup/badge)](https://www.skillsdirectory.com/skills/aiskillstore-ai-code-cleanup)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: ai-code-cleanup
description: Remove AI-generated code slop from branches. Use after AI-assisted coding
  sessions to clean up defensive bloat, unnecessary comments, type casts, and style
  inconsistencies. Focuses on identifying and removing AI artifacts that degrade code
  quality.
author: Joseph OBrien
status: unpublished
updated: '2025-12-23'
version: 1.0.1
tag: skill
type: skill
---

# AI Code Cleanup

This skill identifies and removes AI-generated artifacts that degrade code quality, including defensive bloat, unnecessary comments, type casts, and style inconsistencies.

## When to Use This Skill

- After AI-assisted coding sessions
- Before code reviews or merging branches
- When cleaning up code that feels "over-engineered"
- When removing unnecessary defensive code
- When standardizing code style after AI generation
- When preparing code for production

## What This Skill Does

1. **Identifies AI Artifacts**: Detects patterns typical of AI-generated code
2. **Removes Bloat**: Eliminates unnecessary defensive code and comments
3. **Fixes Type Issues**: Removes unnecessary type casts and workarounds
4. **Standardizes Style**: Ensures consistency with project conventions
5. **Preserves Functionality**: Maintains code behavior while improving quality
6. **Validates Changes**: Ensures code still compiles and tests pass

## How to Use

### Clean Up Branch

```
Remove AI slop from this branch
```

```
Clean up the code in this pull request
```

### Specific Cleanup

```
Remove unnecessary comments and defensive code from src/
```

## Slop Patterns to Remove

### 1. Unnecessary Comments

**Patterns:**

- Comments explaining obvious code
- Comments inconsistent with file's documentation style
- Redundant comments that restate the code
- Over-documentation of simple operations

**Example:**

```javascript
// ❌ AI-generated: Obvious comment
// Set the user's name
user.name = name;

// ✅ Clean: Self-documenting code
user.name = name;
```

### 2. Defensive Bloat

**Patterns:**

- Extra try/catch blocks abnormal for that codebase
- Defensive null/undefined checks on trusted paths
- Redundant input validation when callers already validate
- Error handling that can never trigger

**Example:**

```javascript
// ❌ AI-generated: Unnecessary defensive code
function processUser(user) {
  try {
    if (user && user.name && typeof user.name === 'string') {
      return user.name.toUpperCase();
    }
    return null;
  } catch (error) {
    console.error(error);
    return null;
  }
}

// ✅ Clean: Trust the input, handle real errors
function processUser(user) {
  return user.name.toUpperCase();
}
```

### 3. Type Workarounds

**Patterns:**

- Casts to `any` to bypass type issues
- Unnecessary type assertions (`as X`)
- `@ts-ignore` or `@ts-expect-error` without legitimate reason
- Overly complex generic constraints

**Example:**

```typescript
// ❌ AI-generated: Type workaround
const data = response.data as any;
const result = processData(data as ProcessedData);

// ✅ Clean: Proper typing
const data = response.data;
const result = processData(data);
```

### 4. Style Inconsistencies

**Patterns:**

- Naming conventions different from rest of file
- Formatting that doesn't match surrounding code
- Import organization inconsistent with file patterns
- Variable declarations inconsistent with file style

**Example:**

```javascript
// ❌ AI-generated: Inconsistent style
const UserData = fetchUser();
var processedData = process(UserData);
let FinalResult = format(processedData);

// ✅ Clean: Consistent style
const userData = fetchUser();
const processedData = process(userData);
const finalResult = format(processedData);
```

### 5. AI Tells

**Patterns:**

- Unnecessary emoji usage in code or comments
- Overly verbose variable names
- Redundant intermediate variables
- "Just in case" code with no actual use case

## Cleanup Process

### 1. Get the Diff

```bash
git diff $(git merge-base HEAD main)..HEAD --name-only
```

### 2. Analyze Each File

For each changed file:

- Read the full file to understand existing style
- Identify patterns from slop categories
- Make surgical edits to remove slop
- Preserve functionality

### 3. Verification

- Ensure code still compiles/runs
- Changes should reduce code, not add more
- Run tests to verify behavior
- Check for any regressions

## Examples

### Example 1: Comment Cleanup

**Input**: Remove unnecessary comments from `src/auth.js`

**Output**:

```markdown
## AI Code Cleanup: src/auth.js

### Removed
- 12 redundant comments explaining obvious code
- 3 comments inconsistent with file style
- 5 over-documented simple operations

### Changes
```javascript
// Before
// Function to validate user email
// Takes email string as input
// Returns boolean indicating validity
function validateEmail(email) {
  // Check if email is not empty
  if (!email) {
    return false; // Return false if empty
  }
  // Return regex test result
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

// After
function validateEmail(email) {
  if (!email) return false;
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
```

### Result

- Lines reduced: 12 → 4
- Functionality preserved
- Tests pass

```

### Example 2: Defensive Bloat Removal

**Input**: Remove defensive bloat from `src/api/users.js`

**Output**:
```markdown
## AI Code Cleanup: src/api/users.js

### Removed
- 3 unnecessary try/catch blocks
- 8 redundant null checks on validated inputs
- 2 error handlers that can never trigger

### Changes
```javascript
// Before
async function getUser(userId) {
  try {
    if (!userId || typeof userId !== 'string') {
      throw new Error('Invalid userId');
    }
    const user = await db.users.findById(userId);
    if (user && user.id) {
      return user;
    }
    return null;
  } catch (error) {
    console.error(error);
    throw error;
  }
}

// After
async function getUser(userId) {
  const user = await db.users.findById(userId);
  return user || null;
}
```

### Result

- Code reduced: 15 lines → 3 lines
- Functionality preserved
- Error handling appropriate for context

```

## Reference Files

- **`references/REFACTORING_PLAN.template.md`** - Refactoring plan template with code smells, before/after metrics, and rollback strategy

## Best Practices

### Cleanup Guidelines

1. **Preserve Functionality**: Only remove code that doesn't affect behavior
2. **Maintain Style**: Follow existing project conventions
3. **Keep Real Errors**: Don't remove legitimate error handling
4. **Test After Changes**: Always verify code still works
5. **Incremental**: Make changes incrementally, test as you go

### What to Keep

- Legitimate error handling
- Necessary type assertions
- Helpful comments that add context
- Defensive code for untrusted inputs
- Style that matches the codebase

### What to Remove

- Obvious comments
- Unnecessary defensive code
- Type workarounds
- Style inconsistencies
- AI-generated artifacts

## Related Use Cases

- Post-AI coding cleanup
- Code review preparation
- Code quality improvement
- Style standardization
- Removing technical debt

Attribution

aiskillstoreaiskillstore
View sourceSee grades on GitHubMore from aiskillstore →
SSkills Directory ProSkills Directory

Get any skill into Claude in one click.

Download any skill as a ZIP for Claude.ai, Claude Desktop, or .claude/skills. $9/mo.

See Pro

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills Directory ProSkills Directory

Get any skill into Claude in one click.

Download any skill as a ZIP for Claude.ai, Claude Desktop, or .claude/skills. $9/mo.

See Pro

Related Skills

Clean Code

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

304955 votes

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

285172 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10341 votes
View all in development →