jpskill.com
🛠️ 開発・MCP コミュニティ

ai-code-cleanup

AIが生成したコードの余分なコメントや型キャスト、スタイル不一致などを特定し、品質を向上させるために除去するSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

AIが生成したコードの余分なコメントや型キャスト、スタイル不一致などを特定し、品質を向上させるために除去するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o ai-code-cleanup.zip https://jpskill.com/download/6897.zip && unzip -o ai-code-cleanup.zip && rm ai-code-cleanup.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/6897.zip -OutFile "$d\ai-code-cleanup.zip"; Expand-Archive "$d\ai-code-cleanup.zip" -DestinationPath $d -Force; ri "$d\ai-code-cleanup.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して ai-code-cleanup.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → ai-code-cleanup フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] ai-code-cleanup

AIコードクリーンアップ

このスキルは、防御的な肥大化、不要なコメント、型キャスト、スタイルの不整合など、コード品質を低下させるAI生成の成果物を特定して削除します。

このスキルを使用するタイミング

  • AIアシストによるコーディングセッションの後
  • コードレビューやブランチのマージの前
  • 「過剰設計」と感じるコードをクリーンアップする際
  • 不要な防御的コードを削除する際
  • AI生成後にコードスタイルを標準化する際
  • コードを本番環境用に準備する際

このスキルがすること

  1. AI成果物の特定: AI生成コードに典型的なパターンを検出します。
  2. 肥大化の除去: 不要な防御的コードとコメントを排除します。
  3. 型問題の修正: 不要な型キャストと回避策を削除します。
  4. スタイルの標準化: プロジェクトの慣例との一貫性を確保します。
  5. 機能の保持: 品質を向上させながらコードの動作を維持します。
  6. 変更の検証: コードが引き続きコンパイルされ、テストがパスすることを確認します。

使用方法

ブランチのクリーンアップ

このブランチからAIの不要な部分を削除してください
このプルリクエストのコードをクリーンアップしてください

特定のクリーンアップ

src/から不要なコメントと防御的コードを削除してください

削除する不要なパターン

1. 不要なコメント

パターン:

  • 明らかなコードを説明するコメント
  • ファイルのドキュメントスタイルと矛盾するコメント
  • コードを繰り返す冗長なコメント
  • 単純な操作の過剰なドキュメント

例:

// ❌ AI生成: 明らかなコメント
// ユーザー名を設定する
user.name = name;

// ✅ クリーン: 自己文書化コード
user.name = name;

2. 防御的な肥大化

パターン:

  • そのコードベースでは異常な余分なtry/catchブロック
  • 信頼できるパスでの防御的なnull/undefinedチェック
  • 呼び出し元がすでに検証している場合の冗長な入力検証
  • 決してトリガーされないエラー処理

例:

// ❌ AI生成: 不要な防御的コード
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;
  }
}

// ✅ クリーン: 入力を信頼し、実際のエラーを処理する
function processUser(user) {
  return user.name.toUpperCase();
}

3. 型の回避策

パターン:

  • 型の問題を回避するためのanyへのキャスト
  • 不要な型アサーション (as X)
  • 正当な理由のない@ts-ignoreまたは@ts-expect-error
  • 過度に複雑なジェネリック制約

例:

// ❌ AI生成: 型の回避策
const data = response.data as any;
const result = processData(data as ProcessedData);

// ✅ クリーン: 適切な型付け
const data = response.data;
const result = processData(data);

4. スタイルの不整合

パターン:

  • ファイルの残りの部分と異なる命名規則
  • 周囲のコードと一致しない書式設定
  • ファイルパターンと矛盾するインポートの整理
  • ファイルスタイルと矛盾する変数宣言

例:

// ❌ AI生成: スタイルの不整合
const UserData = fetchUser();
var processedData = process(UserData);
let FinalResult = format(processedData);

// ✅ クリーン: 一貫したスタイル
const userData = fetchUser();
const processedData = process(userData);
const finalResult = format(processedData);

5. AIの兆候

パターン:

  • コードやコメント内の不要な絵文字の使用
  • 過度に冗長な変数名
  • 冗長な中間変数
  • 実際のユースケースがない「念のため」のコード

クリーンアッププロセス

1. 差分を取得する

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

2. 各ファイルを分析する

変更された各ファイルについて:

  • ファイル全体を読んで既存のスタイルを理解します。
  • 不要なカテゴリのパターンを特定します。
  • 不要な部分を削除するために外科的な編集を行います。
  • 機能を保持します。

3. 検証

  • コードが引き続きコンパイル/実行されることを確認します。
  • 変更はコードを減らすべきであり、追加すべきではありません。
  • テストを実行して動作を確認します。
  • 回帰がないか確認します。

例1: コメントのクリーンアップ

入力: src/auth.jsから不要なコメントを削除してください。

出力:

## AIコードクリーンアップ: src/auth.js

### 削除済み
- 明らかなコードを説明する冗長なコメント12件
- ファイルスタイルと矛盾するコメント3件
- 過剰に文書化された単純な操作5件

### 変更点
```javascript
// 変更前
// ユーザーのメールアドレスを検証する関数
// 入力としてメールアドレス文字列を受け取る
// 有効性を示すブール値を返す
function validateEmail(email) {
  // メールアドレスが空でないか確認する
  if (!email) {
    return false; // 空の場合はfalseを返す
  }
  // 正規表現テストの結果を返す
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

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

結果

  • 行数削減: 12行 → 4行
  • 機能は保持されています
  • テストはパスします

### 例2: 防御的な肥大化の削除

**入力**: `src/api/users.js`から防御的な肥大化を削除してください。

**出力**:
```markdown
## AIコードクリーンアップ: src/api/users.js

### 削除済み
- 不要なtry/catchブロック3件
- 検証済み入力に対する冗長なnullチェック8件
- 決してトリガーされないエラーハンドラー2件

### 変更点
```javascript
// 変更前
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;
  }
}

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

結果

  • コード削減: 15行 → 3行
  • 機能は保持されています
  • エラー処理はコンテキストに適切です


## 参照ファイル

- **`references/REFACTORING_PLAN.template.md`** - コードの臭い、変更前/変更後のメトリクス、ロールバック戦略を含むリファクタリング計画テンプレート

## ベストプラクティス

### クリーンアップガイドライン

1. **機能の保持**: 動作に影響を与えないコードのみを削除します。
2. **スタイルの維持**
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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:

// ❌ 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:

// ❌ 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:

// ❌ 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:

// ❌ 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

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:

## 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