Skip to main content
Ghostbuster Header

Ghostbuster

Find and bust the ghosts haunting your codebase.

PyPI version Python CI License: MIT

Unused dependencies, dead functions, orphan files, and phantom environment variables lurk in codebases - slowing down repos, confusing new contributors, and wasting CI minutes.

Ghostbuster finds them all in one command.


Quick Start

# Install
pip install ghostbuster-cli

# Scan your project
ghostbuster scan

# No config needed.

What It Finds

Ghostbuster detects 4 categories in your codebase:

Category Identifier What It Detects
Dead Import dead-import Dependencies in requirements.txt / pyproject.toml that are never imported
Orphan File orphan-file node_modules/, venv/, .pyc, large files that should be in .gitignore
Zombie Code zombie-code Functions and classes that are defined but never called from anywhere
Phantom Env phantom-env os.environ["KEY"] / os.getenv("KEY") where KEY is never set

Ghost Score

Every scan produces a Ghost Score (0-100) - the higher the score, the more technical debt in your codebase:

+----------------------- Ghost Score ------------------------+
|                                                            |
|    47 / 100                                                |
|                                                            |
|    #########################--------------------------     |
|                                                            |
|    Noticeable technical debt detected.                     |
|                                                            |
+------------------------------------------------------------+

Auto-Fix

Ghostbuster can also fix detected issues:

# Preview what would be fixed (safe, default)
ghostbuster bust

# Actually apply fixes
ghostbuster bust --confirm

Currently auto-fixes:

  • Removes unused import statements from Python files
  • Appends missing orphan files and directories to .gitignore
  • Appends missing environment variable stubs (KEY=) to .env.example

Usage

Basic Scan

# Scan current directory
ghostbuster scan

# Scan a specific path
ghostbuster scan ./my-project

# Verbose mode (show locations and fix suggestions)
ghostbuster scan -v

Filtered Scan

# Only check for dead imports
ghostbuster scan --category dead-import

# Only check for zombie code
ghostbuster scan -c zombie-code

Output Formats

# Default: formatted terminal output
ghostbuster scan

# JSON (for CI pipelines and scripting)
ghostbuster scan --format json

# Markdown (for pasting into issues/PRs)
ghostbuster scan --format markdown

Pre-commit Hook Integration

Add Ghostbuster to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/adewanggar/ghostbuster-cli
    rev: v0.2.0
    hooks:
      - id: ghostbuster-scan

CI Integration

# .github/workflows/ghostbuster.yml
name: Ghost Check
on: [push, pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install ghostbuster-cli
      - run: ghostbuster scan --format json

Note: ghostbuster scan exits with code 1 if issues are found - ideal for CI gates.

Configuration

Ghostbuster works with zero config, but you can customize it:

pyproject.toml

[tool.ghostbuster]
exclude_dirs = ["migrations", "generated"]
ignore_packages = ["my-internal-lib"]
ignore_env_vars = ["CI", "GITHUB_ACTIONS"]
ignore_names = ["deprecated_helper"]
large_file_threshold = 5242880  # 5MB

.ghostbuster.toml

exclude_dirs = ["vendor", "third_party"]
categories = ["dead-import", "phantom-env"]  # Only run these scanners

How It Works

Ghostbuster uses pure AST analysis - no runtime imports, no code execution, no external services:

  1. Dead Imports: Parses requirements.txt/pyproject.toml for declared dependencies, walks AST for imports, cross-references with a package-to-import mapping table.
  2. Orphan Files: Walks the file tree checking for known ignorable patterns (node_modules/, venv/, __pycache__/, large binary files) and verifies they are covered by .gitignore.
  3. Zombie Code: Collects all function/class definitions and references across the codebase, identifying definitions with zero references (skipping __init__, test_*, and decorated functions).
  4. Phantom Env: Detects os.environ["KEY"], os.environ.get("KEY"), os.getenv("KEY") patterns via AST and checks against .env files and system environment.

Alternatives

Tool Scope Ghostbuster Advantage
Vulture Dead code only Ghostbuster also covers dependencies, files, and env vars
deptry Unused deps only Ghostbuster is a superset with unified output
deadcode Dead code only Ghostbuster adds auto-fix and unified scoring
git-sizer Repo size Ghostbuster checks .gitignore coverage

Roadmap

  • Node.js / JavaScript / TypeScript support (package.json, process.env, import.meta.env)
  • Pre-commit hook integration (.pre-commit-hooks.yaml)
  • GitHub Actions reporter (comment Ghost Score on PRs)
  • Config inheritance for monorepos
  • Ghost Score history tracking & trend chart

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

git clone https://github.com/adewanggar/ghostbuster-cli.git
cd ghostbuster-cli
pip install -e .
pip install pytest ruff mypy
pytest tests/ -v

License

MIT (c) Ghostbuster Contributors


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghostbuster_cli-0.3.0.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghostbuster_cli-0.3.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file ghostbuster_cli-0.3.0.tar.gz.

File metadata

  • Download URL: ghostbuster_cli-0.3.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.11

File hashes

Hashes for ghostbuster_cli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 accf764e53bf326c03eef9196d7e9f8fa3b402e67a917fff443178d3726f34cd
MD5 a169590684cc4ed68fb596908b280eb6
BLAKE2b-256 19ca2d69210b282bef8b4821bbffd494ca3dbf6bef50521f9d14da2c03faeaab

See more details on using hashes here.

File details

Details for the file ghostbuster_cli-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ghostbuster_cli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a23660675ee4f04abb425045e5e0112d5e9e43e589eeb4611e6f76d4b2fecc5
MD5 a261dc07b9d82691984ce9ace9e5553a
BLAKE2b-256 4dfd51347b9ee69ab3f559db1b267add06b0b81b5c29a4a7545d2514195d9f33

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.0 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

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