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 — cross-file detection of definitions that are never referenced anywhere in the scanned project.
  • 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.

Example:

code-prune src --categories unreachable,unused-import,todo-marker --format all

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" findings — useful for dunder methods, main, test hooks (test_*, setUp), 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.1.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.1.0
File Size Uploaded Provenance Actions
code_prune-1.1.0.tar.gz 26.4 kB With provenance Details for code_prune-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 54.4 kB

Release files / code_prune-1.1.0.tar.gz

Download URL code_prune-1.1.0.tar.gz
Size 26.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8a20c55b443c11001a301243d2ff537262d49dfbd846e9a9b187c43c43b23a6f
BLAKE2b-256 checksum
How to use checksums
d9bef2c415052866e9fff7d917aa297b4644e2dd6c0b6c893d99662e8636a719
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 7, 2026.

Transparency log

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

Download URL code_prune-1.1.0-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2984cb5de8d6954e4dc8169e1c334902435aa228b11827349a8927910d018ad
BLAKE2b-256 checksum
How to use checksums
06788feb9f9df3192f468505ac452279bafcb743464c08e9c4a9b14195f033d1
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 7, 2026.

Transparency log

Security for code-prune 1.1.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.1.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 7, 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