A static analysis tool for identifying dead code in a codebase. It provides Python API and CLI for use by agents.
Project description
graphlint
Dead code detection for AI-generated Python codebases.
AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and detect dead code — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
Features
- Dead code detection — finds components unreachable from any entry point via graph traversal
- AST parsing — extracts classes, functions, methods, variables, and fields
- Dependency graph — builds directed edges:
read,write,call,inherit,decorate - Entry point detection — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
- Warning detection — 11 warning types including circular references, unused imports, write-only variables, and more
- Incremental indexing — SHA256-based change detection parses only modified files, with mtime-based fast-path stamp for zero-cost no-op rebuilds
- Python API + CLI — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
- Zero runtime dependencies — only requires the Python standard library
Installation
pip install graphlint
Requirements: Python >= 3.9
Quick Start
Agent Integration
Graphlint provides a command to inject its usage prompt into your AI coding tools at the global level, so every project automatically has graphlint's guidance:
# Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
graphlint install
# Remove graphlint prompt from agent tools
graphlint uninstall
Run graphlint install and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see Agent Integration.
CLI
# Find dead code in current directory
graphlint query --warn-types "dead_code"
# Full analysis with JSON output
graphlint query --json
# View a specific graph detail
graphlint query -g 1 --detail full
# Rebuild index
graphlint build --force
# Configure
graphlint config show
graphlint config set --key lang --value en
Python API
from graphlint.api import query
# Find dead code components
result = query(warn_types="dead_code", json_output=True)
# Full dependency graph analysis
result = query(include_tests=True, json_output=True)
Warning Types
| Warning | Description |
|---|---|
unused_import |
Imported module or name is never used |
dynamic_import |
Dynamic import via importlib or __import__ |
circular_ref |
Circular dependency between functions/classes |
syntax_error |
File contains a syntax error |
write_only |
Variable is written but never read |
deprecated_usage |
Usage of a deprecated function/class |
dead_code |
Component unreachable from any entry point |
type_mismatch |
Suspicious type annotations |
unresolved_ref |
Reference to an undefined name |
unused_variable |
Variable is defined but never used |
file_too_large |
File exceeds the configured size limit |
Development
# Clone the repository
git clone https://github.com/AngelosZou/graphlint.git
cd graphlint
# Create a virtual environment
python -m venv env
env/Scripts/activate # Windows
source env/bin/activate # Unix
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=graphlint
# Run type checking
mypy graphlint/
# Run linting
ruff check graphlint/ tests/
Configuration
Graphlint stores its configuration in .graphlint/config.json within the analyzed directory. Use graphlint config commands to manage settings, or edit the file directly.
See graphlint config show for the full default configuration.
Documentation
Full documentation is available in the docs/ directory:
- Getting Started
- Agent Integration
- Configuration Guide
- Entry Point Detection
- Warning Reference
- CLI Usage
- Architecture Overview
- Python API
Limitations
- Static analysis only — currently, graphlint performs static analysis and cannot detect runtime linkage such as
getattr,importlib.import_module(), or other dynamic dispatch patterns, which may result in false positives. - Large codebase build time — on a large codebase with 700+
.pyfiles, 1,000+ classes, and 14,000+ functions, a full rebuild takes approximately 200 seconds (actual performance depends on hardware). This is not a concern for small projects — a codebase with 60 Python files completes in about 1 second.
License
MIT — see LICENSE for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphlint-0.1.5.tar.gz.
File metadata
- Download URL: graphlint-0.1.5.tar.gz
- Upload date:
- Size: 142.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba622a9cfaccc4a50c922315fd1a1c3d3eba2c387510690bc0f35054b9613561
|
|
| MD5 |
4ee8ec84e1bfda0052556869cd149ece
|
|
| BLAKE2b-256 |
384c159f50cddf4aa9f7538d57048490205aa2520e18c0017ac9386604b3ae15
|
File details
Details for the file graphlint-0.1.5-py3-none-any.whl.
File metadata
- Download URL: graphlint-0.1.5-py3-none-any.whl
- Upload date:
- Size: 75.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e465850006d61dce682a1dbe4a1f0498196bb8aa1961d74dc5d0135f7403f599
|
|
| MD5 |
10be8e83e67d24f3b0fc51c9d2204f60
|
|
| BLAKE2b-256 |
5020308dff56095876470eac742c9997c8bb6a897126f778ca72ae799a6ed90d
|