/clean
Comprehensive technical debt cleanup orchestrator with parallel analysis and safe automation
How it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/clean
Context preview
What this command does when you run it.
Comprehensive technical debt cleanup orchestrator with parallel analysis and safe automation
Command definition
clean.mdallowed-tools: Task, Read, Write, Edit, MultiEdit, Bash(rg:*), Bash(fd:*), Bash(bat:*), Bash(jq:*), Bash(gdate:*), Bash(git:*), Bash(eza:*), Bash(wc:*), Bash(head:*), Bash(deno:*), Bash(npm:*), Bash(cargo:*), Bash(go:*)
name: "Clean"
description: "Comprehensive technical debt cleanup orchestrator with parallel analysis and safe automation"
author: "wcygan"
tags: ["workflow","manage"]
version: "1.0.0"
created_at: "2025-07-14T00:00:00Z"
updated_at: "2025-07-14T00:00:00Z"
Context
- Session ID: !`gdate +%s%N 2>/dev/null || date +%s%N 2>/dev/null || echo "$(date +%s)$(jot -r 1 100000 999999 2>/dev/null || shuf -i 100000-999999 -n 1 2>/dev/null || echo $RANDOM$RANDOM)"`
- Target for cleanup: $ARGUMENTS
- Current directory: !`pwd`
- Project languages: !`fd "(package\.json|Cargo\.toml|go\.mod|deno\.json|pom\.xml|build\.gradle)" . -d 3 | head -5 || echo "No build files detected"`
- Git status: !`git status --porcelain | head -10 || echo "No git repository or clean working directory"`
- Current branch: !`git branch --show-current 2>/dev/null || echo "No git repository"`
- Total files: !`fd "\.(js|ts|jsx|tsx|rs|go|java|py|rb|php|c|cpp|h|hpp|cs|kt|swift|scala)" . | wc -l | tr -d ' '` source files
- Modern tools status: !`echo "rg: $(which rg >/dev/null && echo ✓ || echo ✗) | fd: $(which fd >/dev/null && echo ✓ || echo ✗) | bat: $(which bat >/dev/null && echo ✓ || echo ✗)"`
- Recent commits: !`git log --oneline -5 2>/dev/null | head -5 || echo "No git history available"`
Your Task
STEP 1: Initialize technical debt cleanup session and project analysis
- CREATE session state file: `/tmp/cleanup-session-$SESSION_ID.json`
- ANALYZE project structure and codebase complexity from Context section
- DETERMINE cleanup strategy based on project size and technology stack
- VALIDATE modern CLI tools availability (rg, fd, bat are MANDATORY)
# Initialize cleanup session state
echo '{
"sessionId": "'$SESSION_ID'",
"targetProject": "'$ARGUMENTS'",
"detectedLanguages": [],
"cleanupStrategy": "auto-detect",
"safetyLevel": "production",
"itemsProcessed": 0,
"linesRemoved": 0
}' > /tmp/cleanup-session-$SESSION_ID.jsonSTEP 2: Comprehensive technical debt analysis with parallel sub-agent coordination
TRY:
IF codebase_size > 500 files OR project_type == "enterprise":
LAUNCH parallel sub-agents for comprehensive technical debt discovery:
- **Agent 1: Code Quality Analysis**: Identify quality issues and anti-patterns
- Focus: TODO/FIXME comments, linting violations, code smells, deprecated patterns
- Tools: rg for pattern searches, language-specific linters, quality metrics
- Output: Quality debt inventory with severity levels and fix recommendations
- **Agent 2: Dead Code Detection**: Find unused and unreachable code
- Focus: Unused imports, functions, variables, commented-out code, obsolete files
- Tools: rg for usage analysis, fd for orphaned files, dependency analysis
- Output: Dead code manifest with safe removal candidates
- **Agent 3: Duplication Analysis**: Identify code duplication and consolidation opportunities
- Focus: Duplicate functions, redundant type definitions, similar patterns
- Tools: rg for pattern matching, structural analysis, refactoring opportunities
- Output: Duplication report with consolidation recommendations
- **Agent 4: Dependencies & Security**: Analyze dependency health and security issues
- Focus: Deprecated packages, security vulnerabilities, outdated dependencies
- Tools: Package manager analysis, security scanners, version compatibility
- Output: Dependency cleanup plan with security and compatibility priorities
- **Agent 5: Documentation & Comments**: Evaluate documentation quality and relevance
- Focus: Outdated comments, missing documentation, broken links, obsolete examples
- Tools: rg for comment analysis, documentation link checking, currency validation
- Output: Documentation cleanup agenda with content refresh priorities
ELSE:
EXECUTE streamlined cleanup analysis for smaller codebases:
# Streamlined analysis for smaller projects
echo "🔍 Analyzing technical debt in smaller codebase..."
STEP 3: Systematic cleanup execution with safety checkpoints
**Phase 1: Low-Risk Quality Improvements**
FOR EACH low_risk_improvement:
# Create safety checkpoint
echo "📝 Creating safety checkpoint before cleanup phase"
git add -A
git commit -m "checkpoint: before $(date -Iseconds) cleanup session $SESSION_ID" || echo "No changes to commit"
# Apply formatting and linting fixes
echo "🔧 Applying automated code quality improvements..."
**Language-Specific Cleanup Patterns:**
**JavaScript/TypeScript Projects:**
# Remove console.log statements (excluding intentional logging)
rg "console\.(log|debug|warn)" --type typescript -l | while read file; do
echo "Cleaning debug statements in: $file"
# Interactive review of each console statement
done
# Convert var to let/const
rg "\bvar\s+" --type typescript -l | while read file; do
echo "Modernizing variable declarations in: $file"
# Apply var → let/const transformations with validation
done
# Clean up unused imports
if command -v deno >/dev/null; then
echo "🦕 Running Deno linting and formatting"
deno fmt $ARGUMENTS
deno lint $ARGUMENTS
fi
**Rust Projects:**
# Remove unused imports and dead code warnings
if fd "Cargo.toml" . >/dev/null; then
echo "🦀 Cleaning Rust project with cargo tools"
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo check --all
fi
# Clean up TODO/FIXME comments with context
rg "(TODO|FIXME|XXX|HACK)" --type rust --context 2
**Go Projects:**
# Apply Go formatting and cleaning
if fd "go.mod" . >/dev/null; then
echo "🐹 Cleaning Go project with standard tools"
go fmt ./...
go vet ./...
go mod tidy
fi
# Remove unused variables and imports
go run golang.org/x/tools/cmd/goimports -w ./... 2>/dev/null || echo "goimports not avail
Read more
allowed-tools: Task, Read, Write, Edit, MultiEdit, Bash(rg:*), Bash(fd:*), Bash(bat:*), Bash(jq:*), Bash(gdate:*), Bash(git:*), Bash(eza:*), Bash(wc:*), Bash(head:*), Bash(deno:*), Bash(npm:*), Bash(cargo:*), Bash(go:*) name: "Clean" description: "Comprehensive technical debt cleanup orchestrator with parallel analysis and safe automation" author: "wcygan" tags: ["workflow","manage"] version: "1.0.0" created_at: "2025-07-14T00:00:00Z" updated_at: "2025-07-14T00:00:00Z"
Context
- Session ID: !`gdate +%s%N 2>/dev/null || date +%s%N 2>/dev/null || echo "$(date +%s)$(jot -r 1 100000 999999 2>/dev/null || shuf -i 100000-999999 -n 1 2>/dev/null || echo $RANDOM$RANDOM)"`
- Target for cleanup: $ARGUMENTS
- Current directory: !`pwd`
- Project languages: !`fd "(package\.json|Cargo\.toml|go\.mod|deno\.json|pom\.xml|build\.gradle)" . -d 3 | head -5 || echo "No build files detected"`
- Git status: !`git status --porcelain | head -10 || echo "No git repository or clean working directory"`
- Current branch: !`git branch --show-current 2>/dev/null || echo "No git repository"`
- Total files: !`fd "\.(js|ts|jsx|tsx|rs|go|java|py|rb|php|c|cpp|h|hpp|cs|kt|swift|scala)" . | wc -l | tr -d ' '` source files
- Modern tools status: !`echo "rg: $(which rg >/dev/null && echo ✓ || echo ✗) | fd: $(which fd >/dev/null && echo ✓ || echo ✗) | bat: $(which bat >/dev/null && echo ✓ || echo ✗)"`
- Recent commits: !`git log --oneline -5 2>/dev/null | head -5 || echo "No git history available"`
Your Task
STEP 1: Initialize technical debt cleanup session and project analysis
- CREATE session state file: `/tmp/cleanup-session-$SESSION_ID.json`
- ANALYZE project structure and codebase complexity from Context section
- DETERMINE cleanup strategy based on project size and technology stack
- VALIDATE modern CLI tools availability (rg, fd, bat are MANDATORY)
# Initialize cleanup session state
echo '{
"sessionId": "'$SESSION_ID'",
"targetProject": "'$ARGUMENTS'",
"detectedLanguages": [],
"cleanupStrategy": "auto-detect",
"safetyLevel": "production",
"itemsProcessed": 0,
"linesRemoved": 0
}' > /tmp/cleanup-session-$SESSION_ID.jsonSTEP 2: Comprehensive technical debt analysis with parallel sub-agent coordination
TRY:
IF codebase_size > 500 files OR project_type == "enterprise":
LAUNCH parallel sub-agents for comprehensive technical debt discovery:
- **Agent 1: Code Quality Analysis**: Identify quality issues and anti-patterns
- Focus: TODO/FIXME comments, linting violations, code smells, deprecated patterns
- Tools: rg for pattern searches, language-specific linters, quality metrics
- Output: Quality debt inventory with severity levels and fix recommendations
- **Agent 2: Dead Code Detection**: Find unused and unreachable code
- Focus: Unused imports, functions, variables, commented-out code, obsolete files
- Tools: rg for usage analysis, fd for orphaned files, dependency analysis
- Output: Dead code manifest with safe removal candidates
- **Agent 3: Duplication Analysis**: Identify code duplication and consolidation opportunities
- Focus: Duplicate functions, redundant type definitions, similar patterns
- Tools: rg for pattern matching, structural analysis, refactoring opportunities
- Output: Duplication report with consolidation recommendations
- **Agent 4: Dependencies & Security**: Analyze dependency health and security issues
- Focus: Deprecated packages, security vulnerabilities, outdated dependencies
- Tools: Package manager analysis, security scanners, version compatibility
- Output: Dependency cleanup plan with security and compatibility priorities
- **Agent 5: Documentation & Comments**: Evaluate documentation quality and relevance
- Focus: Outdated comments, missing documentation, broken links, obsolete examples
- Tools: rg for comment analysis, documentation link checking, currency validation
- Output: Documentation cleanup agenda with content refresh priorities
ELSE:
EXECUTE streamlined cleanup analysis for smaller codebases:
# Streamlined analysis for smaller projects echo "🔍 Analyzing technical debt in smaller codebase..."
STEP 3: Systematic cleanup execution with safety checkpoints
**Phase 1: Low-Risk Quality Improvements**
FOR EACH low_risk_improvement:
# Create safety checkpoint echo "📝 Creating safety checkpoint before cleanup phase" git add -A git commit -m "checkpoint: before $(date -Iseconds) cleanup session $SESSION_ID" || echo "No changes to commit" # Apply formatting and linting fixes echo "🔧 Applying automated code quality improvements..."
**Language-Specific Cleanup Patterns:**
**JavaScript/TypeScript Projects:**
# Remove console.log statements (excluding intentional logging) rg "console\.(log|debug|warn)" --type typescript -l | while read file; do echo "Cleaning debug statements in: $file" # Interactive review of each console statement done # Convert var to let/const rg "\bvar\s+" --type typescript -l | while read file; do echo "Modernizing variable declarations in: $file" # Apply var → let/const transformations with validation done # Clean up unused imports if command -v deno >/dev/null; then echo "🦕 Running Deno linting and formatting" deno fmt $ARGUMENTS deno lint $ARGUMENTS fi
**Rust Projects:**
# Remove unused imports and dead code warnings if fd "Cargo.toml" . >/dev/null; then echo "🦀 Cleaning Rust project with cargo tools" cargo fmt --all cargo clippy --all-targets --all-features -- -D warnings cargo check --all fi # Clean up TODO/FIXME comments with context rg "(TODO|FIXME|XXX|HACK)" --type rust --context 2
**Go Projects:**
# Apply Go formatting and cleaning if fd "go.mod" . >/dev/null; then echo "🐹 Cleaning Go project with standard tools" go fmt ./... go vet ./... go mod tidy fi # Remove unused variables and imports go run golang.org/x/tools/cmd/goimports -w ./... 2>/dev/null || echo "goimports not avail
A lightweight (~46kB) and comprehensive CLI tool for managing Claude commands, configurations, and workflows.
Repo: kiliczsh/claude-cmd
Other commands on claude-cmd.
- /agent-browser-automation
Automate browser interactions for development testing using Puppeteer MCP
Open command - /agent-prep-merge
Prepare branches for merging across multiple worktrees and coordinate integration
Open command - /agent-persona-accessibility-expert
Transform into accessibility expert for WCAG compliance and inclusive design
Open command - /agent-persona-api-designer
Transform into an API design specialist who creates well-structured, developer-friendly APIs
Open command - /agent-persona-backend-specialist
Transform into backend specialist for scalable API and system design
Open command - /agent-persona-cloud-architect
Cloud architect persona for designing scalable, secure cloud infrastructure using modern cloud-native technologies
Open command

