/shavakan-commands:cleanup-dead-codefrom shavakan-commands
Remove unused imports, functions, variables, commented blocks, unreachable code
Ships in shavakan-commands. Installing the plugin adds it to Claude Code.
Find and safely remove unused code: imports, functions, variables, commented blocks, unreachable code, unused files.
Safety requirements:
Run prerequisite check:
PLUGIN_ROOT="$HOME/.claude/plugins/marketplaces/shavakan"
if [[ ! "$PLUGIN_ROOT" =~ ^"$HOME"/.* ]]; then
echo "ERROR: Invalid plugin root path"
exit 1
fi
PREREQ_SCRIPT="$PLUGIN_ROOT/commands/cleanup/scripts/check-prerequisites.sh"
if [[ ! -f "$PREREQ_SCRIPT" ]]; then
echo "ERROR: Prerequisites script not found"
exit 1
fi
PREREQ_OUTPUT=$(mktemp)
if "$PREREQ_SCRIPT" > "$PREREQ_OUTPUT" 2>&1; then
source "$PREREQ_OUTPUT"
rm "$PREREQ_OUTPUT"
else
cat "$PREREQ_OUTPUT"
rm "$PREREQ_OUTPUT"
exit 1
fi
This exports: TEST_CMD, BACKUP_BRANCH, LOG_FILE
$ARGUMENTS
Identify and remove dead code that clutters the codebase without affecting functionality.
Unused imports - Modules imported but never referenced
Unused functions - Defined but never called, private methods with no references, exported with no external usage
Unused variables - Declared but never read, parameters never used, constants not referenced
Commented code - 5+ consecutive commented lines with code syntax (belongs in git history)
Unreachable code - After return/throw/break, conditional branches that never execute
Unused files - Source files with no imports, test files for deleted features, replaced implementations
Run the tooling probe first to know what's locally available:
"$CLAUDE_PLUGIN_ROOT/cleanup/scripts/probe-tooling.sh"
Then check your tool inventory for LSP MCP capabilities (find_references, document_symbols, workspace_symbols, diagnostics).
Prefer LSP MCP when available. References are authoritative, grep is not.
| Symptom | LSP signal | Linter fallback (from probe) | Grep fallback |
|---|---|---|---|
| Unused function/method | find_references returns 0 (or only the def site) | linter dead-code rule | grep -rn "\bname\b" excluding the def |
| Unused import | LSP diagnostics (unused-import) | linters[lang] (eslint, ruff, pyflakes, golangci-lint) with --fix | n/a |
| Unused export | find_references returns 0 external callers | n/a — linters are file-scoped | grep across repo (unreliable, misses dynamic) |
| Unused parameter | LSP diagnostic | linter | n/a |
| Unused file | workspace_symbols shows no callers | n/a | grep for filename / module path |
If neither LSP MCP nor linters are available, note in the audit that dynamic-dispatch languages have low confidence (eval, reflection, RPC tables, framework conventions like on_* handlers).
Scan codebase for unused code using the strategy chosen above. For each category:
Be cautious with:
find_references is workspace-scoped; external consumers are invisible)on_* handlers)Gate: User must review findings before removal.
Present findings to user with risk assessment:
Remove dead code?
□ Safe - Unused imports + variables (auto-fixable)
□ Low risk - Unused private functions + commented code
□ Needs review - Unused public functions + unused files
□ Custom - Select specific items
□ Cancel
Gate: Get user approval on which categories to remove.
For each approved category:
Remove items using language-specific tools when available (eslint --fix, autoflake). For functions/files, manual removal with careful validation.
Test and commit: Run $TEST_CMD after each category. If passing, commit. If failing, rollback and report which removal broke tests.
Continue safely: Process one category at a time. Stop on test failure.
Gate: Tests must pass before moving to next category.
Summarize: items removed per category, files affected, lines eliminated, code coverage maintained.
Delete the backup branch after successful completion:
git branch -D "$BACKUP_BRANCH"
CRITICAL:
git rm for file removal to preserve historyIf tests fail: Rollback, identify which specific removal caused failure, decide whether to skip that item or investigate why it was actually needed.
Review with code-reviewer agent before pushing:
Use shavakan-agents:code-reviewer to verify removals don't introduce issues.
/shavakan-commands:cleanup - Full repository audit/shavakan-commands:cleanup-comments - Clean up comments/shavakan-commands:cleanup-architecture - Refactor structureWhat the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub shavakan/claude-marketplace --plugin shavakan-commands12 commands in this plugin
/cleanupRepository Cleanup AuditComprehensive repository audit and cleanup (dead code, comments, docs, architecture, deps)/cleanup-architectureRefactor ArchitectureRefactor structure - split god objects, break circular deps, improve separation of concerns/cleanup-commentsRemove Comment NoiseRemove obvious comments, commented code, outdated TODOs - keep 'why' explanations/cleanup-depsClean Up DependenciesClean dependencies - remove unused, fix security issues, update outdated, deduplicate/cleanup-docsSync Documentation with CodeSync documentation with code - fix dead links, update API docs, remove outdated content/cleanup-duplicationRemove Code DuplicationFind and refactor duplicated code - similar blocks, copy-paste functions, repeated stringsOther plugins' commands for the same job