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 five 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).
  • 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 TODO/FIXME/XXX comment tags.
  • Commented-out code — comments whose content heuristically resembles source code.

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
  • Poetry 2.2

Installation

poetry install

Usage

poetry run code-prune <path> [options]

Common options:

Option Description
--ext Comma-separated extensions to include (e.g. py,js,ts,java,gs,gsx).
--categories Comma-separated categories to report: unreachable,unused,obsolete,commented-out (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:

poetry run code-prune src --categories unreachable,unused --format all

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 via config.ini:

[override]
ignore-file = .codepruneignore

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

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.0.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.0.0
File Size Uploaded Provenance Actions
code_prune-1.0.0.tar.gz 23.7 kB With provenance Details for code_prune-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 49.6 kB

Release files / code_prune-1.0.0.tar.gz

Download URL code_prune-1.0.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
be12e6685f18ba54a078c0c9f5f39eaf9f2bfcecdfca308ac4af29d7c7789ea7
BLAKE2b-256 checksum
How to use checksums
bbb46a929f25e6d62558af00e82be34ee6afaefff5a1544c9a9b11a5592f7b2b
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 Oct 31, 2026.

Transparency log

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

Download URL code_prune-1.0.0-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3859b1c37e037d9ff40673c86d11e753e26c49098abb28140222e399e634fa1d
BLAKE2b-256 checksum
How to use checksums
ba92c90820abb1d9ca131a7f2c6422e4e10735cc84533360724865ed58db02f3
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 Oct 31, 2026.

Transparency log

Security for code-prune 1.0.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.0.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 Oct 31, 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