Files
claude-plugins/plugins/workflow/commands/cleanup.md
Claude Agent 45e28e7e94 feat(workflow): Add workflow plugin v1.0.0
Git workflow, code quality, context management and testing commands:
- commit, push, pr, issue - git operations
- simplify, refactor, verify, check - code quality
- catchup, onboard, save, cleanup - context management
- test, format, sync - development utilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 15:23:48 +00:00

2.8 KiB

description: Remove unused code, imports, and dead code argument-hint: [path] - Optional path to cleanup (defaults to recent changes)

Code Cleanup

Pre-computed Context

Recently Modified Files: !git diff --name-only HEAD~5 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py)$' | head -15

TypeScript Config: !cat tsconfig.json 2>/dev/null | grep -E '"(noUnused|strict)"' | head -5 || echo "No tsconfig.json"

ESLint Unused Rules: !cat .eslintrc* eslint.config.* 2>/dev/null | grep -i unused | head -3 || echo "No ESLint config"


Instructions

You are cleaning up unused code from the codebase.

What to Remove

1. Unused Imports

// Remove these
import { unusedFunction } from './utils';  // never used
import * as _ from 'lodash';  // never used

Detection:

# TypeScript/ESLint
npx eslint --rule 'no-unused-vars: error' --rule '@typescript-eslint/no-unused-vars: error' .

# Or use ts-prune for exports
npx ts-prune 2>/dev/null

2. Unused Variables

// Remove
const unusedConfig = { ... };  // declared but never read
function helper(used, unused) { return used; }  // unused parameter

3. Dead Code

// Remove unreachable code
function process() {
  return result;
  console.log('never runs');  // dead code
}

// Remove commented-out code
// function oldImplementation() { ... }  // delete, use git history

4. Unused Exports

// If not imported anywhere, consider removing
export function neverImported() { ... }

Use ts-prune to find unused exports:

npx ts-prune 2>/dev/null | head -20

Automated Tools

ESLint Auto-fix

npx eslint --fix --rule 'no-unused-vars: error' .

TypeScript Strict Mode

Enable in tsconfig.json:

{
  "compilerOptions": {
    "noUnusedLocals": true,
    "noUnusedParameters": true
  }
}

Python

# Find unused imports
autoflake --remove-all-unused-imports --in-place -r . 2>/dev/null

# Or with ruff
ruff check --select F401 --fix . 2>/dev/null

Manual Review

For each file in the target path:

  1. Read the file
  2. Identify unused:
    • Imports at the top
    • Variables declared but not used
    • Functions defined but not called
    • Commented-out code blocks
  3. Remove with Edit tool
  4. Verify no errors introduced

Safety Rules

  1. Don't remove exports that might be used externally (public APIs)
  2. Check for side effects - some imports run code on load
  3. Preserve intentional unused - parameters with _ prefix
  4. Run tests after cleanup to verify nothing broke

Report

## Cleanup Report

### Removed
- 15 unused imports
- 3 unused variables
- 2 dead code blocks
- 45 lines of commented code

### Files Cleaned
- src/utils.ts: -12 lines
- src/api/client.ts: -8 lines