dead-code-eliminator — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited dead-code-eliminator (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Systematically identify unused or redundant code in Python codebases to improve maintainability, reduce confusion, and eliminate technical debt.
Define what to analyze:
Questions to ask:
Determine analysis scope:
# Check project structure
ls -la
# Count Python files
find . -name "*.py" | wc -l
# Identify test directories
find . -type d -name "*test*"Use multiple detection strategies to find different types of dead code.
#### Strategy 1: Find Unused Functions
Use the bundled script for AST-based analysis:
# Scan entire project
python scripts/find_unused_functions.py /path/to/project
# Exclude specific directories
python scripts/find_unused_functions.py /path/to/project tests,venv,docsWhat it detects:
Limitations:
#### Strategy 2: Find Unused Imports
Use the bundled script to identify unused imports:
# Scan single file
python scripts/find_unused_imports.py /path/to/file.py
# Scan entire directory
python scripts/find_unused_imports.py /path/to/project
# Exclude directories
python scripts/find_unused_imports.py /path/to/project venv,.venv,testsWhat it detects:
from X import Y statements#### Strategy 3: Use External Tools
Leverage Python ecosystem tools for comprehensive analysis:
vulture - Finds unused code:
# Install
pip install vulture
# Run on project
vulture /path/to/project
# Exclude directories
vulture /path/to/project --exclude venv,tests
# Set minimum confidence (0-100)
vulture /path/to/project --min-confidence 80autoflake - Focuses on imports and variables:
# Install
pip install autoflake
# Check for unused imports
autoflake --check --imports /path/to/file.py
# Check unused imports and variables
autoflake --check --remove-all-unused-imports --remove-unused-variables /path/to/file.py
# Recursive scan
autoflake --check -r /path/to/projectpylint - General linting including dead code:
# Install
pip install pylint
# Check for unused variables, imports, functions
pylint /path/to/project --disable=all --enable=unused-import,unused-variable,unreachable#### Strategy 4: Manual Code Review
Read the code to identify patterns:
Unreachable code:
return statementsbreak, continue, or raiseRedundant conditions:
else after returnLook for:
# Find code after return statements (basic pattern)
grep -A 3 "return" **/*.py | grep -v "^--$"
# Find functions with "old" or "legacy" in name
grep -r "def.*old\|def.*legacy" .
# Find TODO comments about removal
grep -r "TODO.*remove\|FIXME.*delete" .Organize dead code by type and priority.
See dead-code-patterns.md for comprehensive pattern catalog.
#### Category: Unused Imports
Priority: High (easy to remove, low risk)
Examples:
import os but os is never usedfrom typing import List, Dict but only List is used#### Category: Unused Functions/Methods
Priority: Medium to High
Subcategories:
Caution - May be intentional:
#### Category: Unreachable Code
Priority: High (indicates bugs or confusion)
Examples:
returnraise#### Category: Redundant Code
Priority: Medium
Examples:
else after return#### Category: Unused Variables
Priority: Low to Medium
Examples:
Before reporting, verify that identified code is truly dead.
Check for dynamic usage:
# Code may appear unused but is called dynamically
handlers = {
'process': process_handler, # Looks unused but isn't
}
# Or via getattr
handler = getattr(module, function_name)Check for external usage:
Check for framework conventions:
# Django signal handlers
@receiver(post_save, sender=User)
def user_saved(sender, instance, **kwargs): # May appear unused
pass
# Pytest fixtures
@pytest.fixture
def sample_data(): # Used by tests but not "called" directly
return {"key": "value"}Verify with grep:
# Search for function name in entire codebase
grep -r "function_name" .
# Search in quotes (dynamic calls)
grep -r "'function_name'\|\"function_name\"" .
# Search in setup.py or config files
grep -r "function_name" setup.py pyproject.tomlCreate a structured markdown report of findings.
Project: [Project Name] Analyzed: [Date] Scope: [Directories analyzed] Excluded: [Excluded directories]
Total: Z dead code instances found
Code that can never execute - should be removed immediately.
#### Issue 1: Code After Return
Location: src/utils.py:45-47
Code:
def process_data(data):
if not data:
return None
logging.warning("Empty data") # UNREACHABLE
validate(data) # UNREACHABLERecommendation: Remove lines 46-47 (unreachable after return).
Impact: Misleading code that suggests validation happens but doesn't.
#### File: src/main.py
Lines:
import os (unused)from typing import Dict, Tuple (only Dict is used)import re (unused)Recommendation: Remove unused imports. Update line 5 to from typing import Dict.
Functions that appear unused but should be verified before removal.
#### Issue 3: Orphaned Helper Function
Location: src/helpers.py:89
Function: format_timestamp(ts: int) -> str
Analysis:
Verification needed:
Recommendation: If not part of public API, remove. Otherwise, document it.
#### Issue 4: Duplicate Logic
Locations:
src/processor_a.py:45-52src/processor_b.py:78-85Code: Both files contain identical validation logic.
Recommendation: Extract common logic into shared utility function.
Impact: Maintenance burden - changes must be duplicated.
#### Issue 5: Unnecessary Else After Return
Location: src/validator.py:123-127
Code:
def check_status(value):
if value > 0:
return "positive"
else: # Unnecessary
return "negative"Recommendation: Remove else clause (implicit after return).
Impact: Minor - slightly less readable but no functional impact.
#### Issue 6: Unused Variable
Location: src/calculator.py:56
Code:
def compute(a, b):
total = a + b # Assigned but never used
return a * bRecommendation: Remove unused total variable.
These appear unused but may be called dynamically. Manual verification needed.
#### Function: handle_create()
Location: src/handlers.py:34
Reason for caution: File contains handler registry suggesting dynamic dispatch.
Code pattern:
HANDLERS = {
'create': handle_create,
'update': handle_update,
}Recommendation: Verify this is registered and used. If confirmed unused, remove.
Add to CI/CD pipeline:
# Add to pre-commit hook or CI
vulture src/ --min-confidence 80
autoflake --check -r src/Configure IDE:
Code review checklist:
[If needed, include full lists of all findings organized by file]
Share the report with the team and get feedback.
Present clearly:
Be cautious about:
Request feedback:
Start conservatively:
Use multiple detection methods:
Prioritize by risk:
Consider the context:
Prevention is better than cure:
Be aware of code that appears dead but isn't:
1. Dynamic dispatch:
handler = getattr(module, f"handle_{action}")2. Entry points:
# setup.py
entry_points={
'console_scripts': ['tool=module:main_function']
}3. Pytest fixtures:
@pytest.fixture
def sample_data(): # Used by tests implicitly
return data4. Django signals:
@receiver(post_save, sender=Model)
def handle_save(sender, instance, **kwargs): # Called by framework
pass5. Decorators and metaclasses:
class Meta:
def __init_subclass__(cls): # Called implicitly
register(cls)6. Public API functions:
# In library code - may be used by external code
def public_function(): # Appears unused internally
passFor comprehensive dead code patterns and detection strategies, see dead-code-patterns.md.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.