Skip to main content
command CX Codex

cleanup · superclaude-org — Claude Code command: what it does, how to install

The cleanup command for Claude Code finds dead code, removes unused imports, and tidies project structure without breaking public APIs.

MIT ★ 23,950 updated 2026-09-27

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/cleanup.md
Open on GitHub

What cleanup does

The command works through a structured five-stage cycle: analyze targets, pick specialized personas, execute cleanups, test for regressions, and deliver a final summary. Unused imports, empty blocks, and symbols lacking any references get cleared automatically. Whenever an item touches external exports, test utilities, or configuration values, the tool pauses and requests explicit approval.

Execution relies on standard file tools like Read, Grep, Glob, and MultiEdit, tracking multi-file jobs via TodoWrite. If configured, sequential and context7 MCP servers supply step-by-step dependency reasoning and framework patterns; missing servers trigger a graceful switch to native model logic and web documentation.

What it helps with

  • strip unused imports and redundant type annotations
  • detect and purge zero-reference dead code
  • reorganize project files while validating dependencies

Example prompts for the agent

  • /sc:cleanup src/ --type code --safe
  • /sc:cleanup --type imports --preview
  • /sc:cleanup --type all --interactive

How to install cleanup

Manually: put the files in place

.claude/commands/cleanup.md

Call it with /cleanup. For all projects use ~/.claude/commands/

Questions about cleanup

How to install cleanup in Claude Code?

Place the command specification file into .claude/commands/cleanup.md.

What does cleanup do?

It discovers unreachable code, removes orphaned imports, and reorganizes project structures while guarding against regressions.

Are sequential and context7 MCP servers mandatory?

No, they act as preferred tooling: the workflow automatically falls back to native model reasoning and web search if either server is absent.

Source text

cleanup.md · MIT
---
name: cleanup
description: "Systematically clean up code, remove dead code, and optimize project structure"
category: workflow
complexity: standard
mcp-servers: [sequential, context7]
personas: [architect, quality, security]
---

# /sc:cleanup - Code and Project Cleanup

## Triggers
- Code maintenance and technical debt reduction requests
- Dead code removal and import optimization needs
- Project structure improvement and organization requirements
- Codebase hygiene and quality improvement initiatives

## Usage
```
/sc:cleanup [target] [--type code|imports|files|all] [--safe|--aggressive] [--interactive]
```

## Behavioral Flow
1. **Analyze**: Assess cleanup opportunities and safety considerations across target scope
2. **Plan**: Choose cleanup approach and activate relevant personas for domain expertise
3. **Execute**: Apply systematic cleanup with intelligent dead code detection and removal
4. **Validate**: Ensure no functionality loss through testing and safety verification
5. **Report**: Generate cleanup summary with recommendations for ongoing maintenance

Key behaviors:
- Multi-persona coordination (architect, quality, security) based on cleanup type
- Framework-specific cleanup patterns via Context7 MCP integration
- Systematic analysis via Sequential MCP for complex cleanup operations
- Safety-first approach with backup and rollback capabilities

## MCP Integration
- **Sequential MCP**: Auto-activated for complex multi-step cleanup analysis and planning
- **Context7 MCP**: Framework-specific cleanup patterns and best practices
- **Persona Coordination**: Architect (structure), Quality (debt), Security (credentials)
- **Availability fallback**: The MCP servers named here are preferred tooling, not hard requirements — when one is not installed, degrade gracefully (native reasoning in place of Sequential, official docs via web lookup in place of Context7, native tools otherwise) instead of routing work to absent servers.

## Tool Coordination
- **Read/Grep/Glob**: Code analysis and pattern detection for cleanup opportunities
- **Edit/MultiEdit**: Safe code modification and structure optimization
- **TodoWrite**: Progress tracking for complex multi-file cleanup operations
- **Task**: Delegation for large-scale cleanup workflows requiring systematic coordination

## Key Patterns
- **Dead Code Detection**: Usage analysis → safe removal with dependency validation
- **Import Optimization**: Dependency analysis → unused import removal and organization
- **Structure Cleanup**: Architectural analysis → file organization and modular improvements
- **Safety Validation**: Pre/during/post checks → preserve functionality throughout cleanup

## Examples

### Safe Code Cleanup
```
/sc:cleanup src/ --type code --safe
# Conservative cleanup with automatic safety validation
# Removes dead code while preserving all functionality
```

### Import Optimization
```
/sc:cleanup --type imports --preview
# Analyzes and shows unused import cleanup without execution
# Framework-aware optimization via Context7 patterns
```

### Comprehensive Project Cleanup
```
/sc:cleanup --type all --interactive
# Multi-domain cleanup with user guidance for complex decisions
# Activates all personas for comprehensive analysis
```

### Framework-Specific Cleanup
```
/sc:cleanup components/ --aggressive
# Thorough cleanup with Context7 framework patterns
# Sequential analysis for complex dependency management
```

## Boundaries

**Will:**
- Systematically clean code, remove dead code, and optimize project structure
- Provide comprehensive safety validation with backup and rollback capabilities
- Apply intelligent cleanup algorithms with framework-specific pattern recognition

**Will Not:**
- Remove code without thorough safety analysis and validation
- Override project-specific cleanup exclusions or architectural constraints
- Apply cleanup operations that compromise functionality or introduce bugs

## AUTO-FIX VS APPROVAL-REQUIRED

**Auto-fix (applies automatically)**:
- Unused imports removal
- Dead code with zero references
- Empty blocks removal
- Redundant type annotations

**Approval Required (prompts user first)**:
- Code with indirect references
- Exports potentially used externally
- Test fixtures/utilities
- Configuration values

**Safety Threshold**:
- If code has ANY usage path, prompt user
- If code affects public API, prompt user
- If unsure, prompt user

© SuperClaude-Org · MIT · SuperClaude-Org/SuperClaude_Framework

Similar slash commands

All slash commands for Code review and refactoring →

cleanup by other authors comes first.

cleanup carlrannaberg cleanup finds disposable debug scripts, test files, and generated reports from Claude Code sessions and prompts before removing them. CX Codex +1 ★ 763repo stars absolute-simplify dhruvjainin absolute-simplify — a skill for Claude Code and Cursor that simplifies code, flattens nesting, and removes dead code. Runs autonomously on git changes or target paths. CX Codex +1 336installs launchdarkly-flag-cleanup launchdarkly launchdarkly-flag-cleanup — a skill for Claude Code, Codex, and Cursor. Guides the safe removal of completed LaunchDarkly feature flags while preserving existing production behavior. CX Codex +1 4,200installs gsd-cleanup open-gsd gsd-cleanup — a skill for Claude Code and other environments that archives phase directories from completed milestones. It runs to clean up the workspace from accumulated planning data. CX Codex +1 573installs cleanup-implementer alfredoperez cleanup-implementer executes a single repository cleanup work packet. It edits assigned files, runs target checks, and never touches git write operations. CX Codex ★ 110repo stars code-refactoring akillness The code-refactoring skill turns a refactoring request into a behavior-aware plan with clear guardrails, reviewable slices, and a defined next step. CX Codex +1 552installs absolute-prune dhruvjainin absolute-prune — a cleanup skill for Claude Code that sweeps repositories for dead code and unreferenced dependencies. Runs on green main branches using static analyzer evidence. CX Codex +1 170installs

From the same set56

The whole set →
explain A command to explain code, system architecture, and concepts at the right level of depth. Helps you understand unfamiliar code or teach concepts to others. CX Codex +1 ★ 23,950repo stars index index scans project architecture to build structured knowledge bases, API references, or README files with cross-references. CX Codex +1 ★ 23,950repo stars troubleshoot troubleshoot diagnoses runtime errors, build failures, performance bottlenecks, and deployment bugs. It inspects the system state and never modifies files unless passed --fix. CX Codex +1 ★ 23,950repo stars spawn spawn — a command that breaks down large multi-domain operations into hierarchical task plans with dependencies and delegation. Analyzes scope, decomposes work, and assigns executors—it plans rather than implements. CX Codex +1 ★ 23,950repo stars deep-research-agent The deep-research-agent subagent investigates complex questions, checks sources, and turns findings into a cited report. Use it for current topics or when information needs careful synthesis. CX Codex ★ 23,950repo stars improve improve removes technical debt, tunes execution speed, and patches vulnerabilities in your project. Useful for component refactoring and enforcing code standards. CX Codex +1 ★ 23,950repo stars estimate This command estimates development time, effort, or complexity and returns a breakdown with risks. Use it to scope work before implementation begins. CX Codex +1 ★ 23,950repo stars implement The /sc:implement command coordinates feature development in Claude Code using specialist personas and MCP tools. It handles planning, code generation, and test prep. CX Codex +1 ★ 23,950repo stars

Project sponsors

Companies that keep this analytics open