# Remove Dead Code Safely

Unused imports, functions, and classes increase maintenance cost and deployment size. This skill guides Claude, Codex, and Claude Code through conservative analysis, backups, removal, and validation.

## Install

```bash
npx skillstore add joseph obrien/89jobrien-dead-code-removal
```

## Metadata

- Status: approved
- Slug: 89jobrien-dead-code-removal
- Version: 1.0.1
- Author version: 1.0.1
- Skillstore revision: r1
- Version status: valid
- Tree hash: 2292d3410eeee49444e36b05962641428fb385b92df91040a8b69858f0f76413
- Author: Joseph OBrien
- GitHub username: 89jobrien
- License: MIT
- Repository: https://github.com/89jobrien/steve/tree/main/steve/skills/dead-code-removal
- Ref: c4037264bbd363c572662d6154a3ab28f5ca4f53
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: scripts, external\_commands, filesystem
- Quality score: 80
- Quality tier: silver
- Public page: https://skillstore.pages.dev/skills/89jobrien-dead-code-removal
- Manifest: https://skillstore.pages.dev/api/skills/89jobrien-dead-code-removal/manifest

## Capabilities

- Identifies project languages by checking common config and manifest files.
- Maps entry points, imports, require calls, function calls, and inheritance patterns.
- Includes a Python AST helper script for unused import detection.
- Preserves framework hooks, routes, models, tests, migrations, and exported APIs.
- Recommends backups, incremental changes, syntax checks, tests, and build validation.

## Use Cases

- Clean Python Services: Find unused imports and private helpers before a service release, then validate syntax and tests.
- Reduce Frontend Bundle Size: Review stale components, utilities, and imports after feature removal while preserving framework entry points.
- Prepare Legacy Refactors: Build a cautious cleanup plan that separates safe removals from public APIs and dynamic usage.

## Prompt Templates

### Find Unused Imports

```
Analyze this repository for unused Python imports. Report each candidate with file, line, confidence, and validation steps before changing files.
```

### Remove Safe Candidates

```
Remove only unused imports and private functions that have no references. Create a backup, run syntax checks, and summarize every change.
```

### Audit a Refactor

```
Review the recent refactor for dead code across src and tests. Preserve framework hooks, public APIs, migrations, and dynamic usage patterns.
```

### Plan Cross-Language Cleanup

```
Build a dependency map for this mixed-language project, rank dead-code candidates by risk, remove low-risk items incrementally, and run available tests after each batch.
```

## Limitations

- Cannot prove dynamic runtime references are unused without project-specific tests.
- JavaScript, Java, Go, and Rust guidance is documented but has no included helper script.
- Some documentation examples reference a helper filename that differs from the included script name.
- May preserve code that appears unused when framework or reflection patterns are present.

## Best Practices

- Start with imports and private helpers before considering exported APIs.
- Run syntax checks and tests after each small removal batch.
- Treat reflection, decorators, route registration, and template references as preservation signals.

## Anti Patterns

- Deleting public or exported symbols based only on name search.
- Removing code before backups and validation are complete.
- Ignoring tests, migrations, generated files, or framework conventions.

## Security Audit

- Audited at: 2026-07-05T11:42:38.998\+00:00
- Summary: All static findings were reviewed in context. They are false positives from Markdown code fences, inline backticks, sample validation commands, and safety checklist text. The helper script reads local Python files, parses AST, and prints unused import results. No evidence of prompt injection, network activity, exfiltration, or hidden execution was found.

## Stats

- Views: 178
- Downloads: 25
- Favorites: 1
- Popularity score: 0
