Skip to content
Back to skills

Repo Caretaker Pruning Dead Code

ASecurity

Method used by the Repo Caretaker pack to find and safely remove dead code - unused files, exports, functions, dependencies and stale flags, using static tools plus searches for dynamic references, treating public APIs, reflection and config-loaded code as live. Load only when the Repo Caretaker agent or the user asks for it by name.

  • 12 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentspythonrustgojavakotlinc#nodegitapi

Works with

  • api

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add MhdAljuboori/ZumiBot --skill repo-caretaker-pruning-dead-code --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Repo Caretaker Pruning Dead Code?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Repo Caretaker Pruning Dead Code
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mhdaljuboori-repo-caretaker-pruning-dead-code/badge)](https://www.skillsdirectory.com/skills/mhdaljuboori-repo-caretaker-pruning-dead-code)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: repo-caretaker-pruning-dead-code
description: Method used by the Repo Caretaker pack to find and safely remove dead code - unused files, exports, functions, dependencies and stale flags, using static tools plus searches for dynamic references, treating public APIs, reflection and config-loaded code as live. Load only when the Repo Caretaker agent or the user asks for it by name.
---

# Pruning dead code

Goal: remove code that nothing can reach, without ever removing code that something reaches in a way a tool cannot see.

## 1. Know what is public
Before any tool, write down what counts as an entry point. Anything here is **live**, whatever a tool says:
- Package exports and entry points: `main`, `exports`, `bin` in `package.json`; `__init__.py` re-exports and `__all__`; `pub` items of a library crate; exported identifiers of a Go library package; anything documented as API.
- Framework conventions: route files, pages, migrations, management commands, fixtures, plugins, `conftest.py`, Storybook stories, test files.
- Config-loaded code: names in YAML/JSON/TOML config, DI containers, `entry_points` in `pyproject.toml`, serverless handlers, CI and build scripts, `Makefile` targets.
- Reflection and dynamic access: `import()` / `require()` with variables, `importlib`, `getattr`, string-keyed registries, decorators that register handlers, templates that call helpers by name, serialization by field name.

If the repo is a library others depend on, public removals are breaking changes: report them; do not remove them.

## 2. Run the tools
Run a tool only if it is already in the lockfile or on PATH (`npx` must resolve an installed copy, never fetch one); otherwise list it under Not checked:

| Stack | Tool |
|---|---|
| JS / TS | `npx knip` (files, exports, dependencies; reads framework plugins) |
| Python | `vulture <src> --min-confidence 80`, plus `deptry .` for unused dependencies |
| Go | `staticcheck ./...` (U1000), `deadcode ./...` from golang.org/x/tools |
| Rust | compiler `dead_code` warnings, `cargo +nightly udeps` or `cargo machete` for dependencies |
| Java / Kotlin / C# | IDE or compiler unused warnings; search by hand |
| Any | `git log -1 --format=%cr -- <file>` for age; files untouched for years and unimported are good candidates |

Also look for: feature flags that have been fully on or off for months (both branches still in code), commented-out blocks, `TODO remove after` notes past their date, and unused CSS or assets if the user asks.

## 3. Verify every candidate by hand
For each candidate name:
1. `rg -n --hidden -g '!node_modules' -g '!dist' "<name>"` over the whole repo: code, tests, config, docs, scripts, templates.
2. Search string forms: the name in quotes, kebab or snake variants, the file path without extension (dynamic imports), and partial names built by concatenation (`"handle" + type`).
3. Check whether it matches a framework convention or a public entry point from step 1.
4. Check git history for why it exists: `git log -S"<name>" --oneline | head`.

Confidence:
- **High:** no references anywhere, not public, not convention-loaded, tool and search agree.
- **Medium:** only referenced by its own tests, or only by other dead code.
- **Low:** any string or dynamic match, any doubt. Low items are reported, never removed.

## 4. Remove in small batches (only when asked)
- Record the starting branch; work on a new local branch (`caretaker/deadcode-<date>`, add `-2` if it exists). One batch per area (one module, one dependency group), small enough to review in minutes.
- Snapshot before each batch: copy every file the batch will edit or delete, plus the manifests and lockfiles, into a temp folder (`mktemp -d`), keeping relative paths.
- Remove the code, its now-unused imports and its own tests together. Keep tests of live code.
- After each batch: build, typecheck, lint and the full test suite with the repo's own commands. Anything red: copy the snapshot back over the repo and reinstall from the lockfile, never `git checkout --` or `git restore` (they also wipe earlier green batches), then move the item to Low with the error.
- Removing a dependency: also update the lockfile with the package manager, then reinstall from the lockfile and rebuild.
- Leave changes uncommitted unless asked. Report that the checkout is now on the new branch (`git switch -` returns).

## Report
Group by confidence. Per item: what (file, symbol or dependency), evidence (tool output plus your search result), why it is safe or not, and size (lines). Give the total lines removable at High confidence. List public API candidates separately as "possibly unused API, removing is breaking".

## Don't
- Don't trust one tool's output alone.
- Don't remove anything public, convention-loaded or reflected.
- Don't mix dead code removal with refactors or formatting in the same batch.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.