Skip to main content

code-prune

License: MIT Version Python PyPI

A CLI tool that scans a codebase for unreachable, unused, and obsolete code, helping you find dead code before it becomes technical debt.

Features

code-prune parses source files with tree-sitter and reports six categories of findings across Python, JavaScript, TypeScript, Java, and Gosu:

  • Unreachable code — statements after return/raise/throw/break/ continue, and if branches whose condition is a constant falsy literal (False/false/0). Comments are never reported as unreachable.
  • Unused imports & local variables — per-file, syntactic detection of bindings that are never referenced again in the same file.
  • Unused functions/classes/methods/fields — cross-file detection of definitions that are never referenced anywhere in the scanned project. Fields cover class-level fields in every language, Python self.x attributes, JavaScript #private fields, TypeScript interface properties and constructor parameter properties, and Java enum constants.
  • Obsolete markers — @deprecated/@Deprecated-style decorators and annotations, plus comments mentioning deprecated.
  • TODO markers — TODO/FIXME/XXX comment tags (not necessarily obsolete, so reported separately).
  • Commented-out code — comments whose content heuristically resembles source code. Documentation comments (Javadoc/JSDoc /** ... */) and Python docstrings are not treated as commented-out code.

Only supported files (.py, .pyi, .js, .mjs, .cjs, .ts, .tsx, .java, .gs, .gsx) are read; every other file is skipped.

Detection is heuristic and syntactic rather than a full scope- or call-graph-aware analysis — treat findings as a starting point for review, not a guarantee.

Requirements

  • Python >=3.14

Installation

pip install code-prune

Usage

code-prune <path> [options]

<path> may be a file, a directory, or several of them separated by ;.

Common options:

Option Description
--ext Comma-separated extensions to include (e.g. py,js,ts,java,gs,gsx). Omit to scan every supported file.
--categories Comma-separated categories to report: unreachable, unused-import, unused-local, unused-symbol, obsolete, todo-marker, commented-out. unused is shorthand for all three unused-* categories (default: all).
--format Output format: json, html, or all (default: json).
--output Base output filename without extension (default: code-prune-output).
--output-dir Directory for the report file(s) (default: reports).
--workers Number of parallel worker threads used to scan files.
--db Path to the SQLite scratch database used during a scan run.
--target-list Treat path as a file listing target paths, one per line.
--search-path Files and/or directories (separated by ;) searched textually for each unused-symbol candidate; a symbol found there is not reported. Classes, functions/methods and fields are all matched by a whole-word regex; a method or field additionally requires its enclosing class's name to appear in the same file. The symbol's own file is skipped and .codepruneignore rules apply.
--search-ext Comma-separated extensions of the files searched in --search-path (e.g. xml,json). Omit to search every text file. Requires --search-path.

Example:

code-prune src --categories unreachable,unused-import,todo-marker --format all
code-prune src --categories unused-symbol --search-path "templates;../other-repo" --search-ext xml,json,py

Reports

Both report formats include the number of findings per category: the JSON report has a category-counts object, and the HTML report shows the counts in a category dropdown filter listing the categories present in the report. The HTML summary line shows only the total number of findings.

Configuration

Logging is bootstrapped via env-dir-bootstrap. Set the CODE_PRUNE_CONFIG_DIR environment variable to override the default configuration directory used to resolve logging.ini, config.ini, .codepruneignore, and symbol_ignore.

Ignoring files and directories

.codepruneignore holds gitignore-style patterns for files/directories to exclude from scanning (mirroring .gitignore syntax). Override the filename used in the configuration directory via config.ini:

[override]
ignore-file = .codepruneignore

In addition, a .codepruneignore placed in the target path (the scanned directory, or the directory containing a scanned file) extends those patterns. It always uses that fixed name and is not affected by config.ini.

Ignoring symbol names

symbol_ignore holds one regex pattern per line, matched against symbol names to suppress from "unused function/class/method/field" findings — useful for dunder methods, main, test hooks (test_*, setUp), serialVersionUID, and similar intentionally-unreferenced symbols.

Development

Development uses Poetry 2.2.

Install the project and its dev dependencies:

poetry install

Run the CLI from the working tree:

poetry run code-prune <path> [options]

Run tests with coverage and generate an HTML report:

poetry run pytest --cov=code_prune tests --cov-report html

Format and lint the code:

poetry run black code_prune; poetry run pylint code_prune

License

This project is licensed under the MIT License.

Metadata

Release files for code-prune 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-prune 1.3.0
File Size Uploaded Provenance Actions
code_prune-1.3.0.tar.gz 31.4 kB With provenance Details for code_prune-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for code-prune 1.3.0
File Interpreter ABI Platform Actions
code_prune-1.3.0-py3-none-any.whl Python 3 none any Details for code_prune-1.3.0-py3-none-any.whl

Total release size: 64.7 kB

Release files / code_prune-1.3.0.tar.gz

Download URL code_prune-1.3.0.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e1a9de837843fb8f5651c684b037bf25e30b26a9193ed3adc46351ecf8dea36b
BLAKE2b-256 checksum
How to use checksums
407df3a9496555c43cdd2d54938ef80b97ef7345fa25ad1beafc51d60c599e57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / code_prune-1.3.0-py3-none-any.whl

Download URL code_prune-1.3.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df6e90123784f1b1116d59f71acb9bc05bbb62011deff84a04f59fa125d71c77
BLAKE2b-256 checksum
How to use checksums
166bd4613fe0ce73fc412cdd69ce8aa63254391d362d8f7516358198916f158b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for code-prune 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for code_prune-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page