graphlint
Dead code detection for AI-generated 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 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.
Supported Languages
| Language | Status | Parser | Features |
|---|---|---|---|
Python (.py) |
Built-in | ast (stdlib) |
Decorators, type annotations, dynamic imports, framework-aware entry detection |
Rust (.rs) |
Built-in (opt-in deps) | tree-sitter |
Attribute macros, traits, pub visibility, macro_rules! |
Install with Rust support: pip install graphlint[rust] (adds tree-sitter and tree-sitter-rust).
Features
- Dead code detection — finds components unreachable from any entry point via graph traversal
- Multi-language support — Python and Rust backends via a language adapter abstraction; Python uses stdlib
ast, Rust usestree-sitter - Language-specific awareness — Python decorators, Rust attribute macros (
#[tokio::main],#[test]), trait implementations,pubvisibility, and more - AST/CST parsing — extracts functions, methods, structs, enums, traits, impls, macros, variables, and fields; aware of type annotations and unpacked variables
- Dependency graph — builds directed edges:
read,write,call,inherit,decorate - Entry point detection — 17 built-in rules covering Python frameworks (FastAPI, Flask, Django, Click, Typer, Celery, pytest) and Rust conventions (main, async runtimes, WASM, proc macros, FFI, tests, pub API) plus custom rules
- Configurable entry templates — add custom entry rules via
ast_patternprefixes includingfunction_call:,function_def:,decorator:,file_match:,visibility:pub(Rust),trait_impl:(Rust),macro_def:(Rust), and more --public-as-entryflag — treat all public items (Rustpub) as entry points for library-crate analysis- Warning detection — 11 warning types including circular references, unused imports, write-only variables, and more
- Incremental updates — after initial full scan, only changed files are re-indexed; delta-aware reachability analysis avoids full-graph recomputation.
- Python API + CLI — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
Installation
pip install graphlint
Requirements: Python >= 3.9
For Rust support (.rs files), install the optional tree-sitter dependencies:
pip install graphlint[rust]
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
# Copy the prompt to clipboard for manual paste into your agent
graphlint prompt
# 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.
If your agent tool is not listed in install, run graphlint prompt to copy the prompt to your clipboard and provide it to your agent manually. For tools you'd like native support for, feel free to submit an issue — these requests are typically handled quickly.
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
# Exit non-zero when dead code or circular refs found (for CI)
graphlint query --json --fail-on dead_code,circular_ref
# Treat all public items as entry points (library-crate mode)
graphlint query --public-as-entry
# Rebuild index
graphlint build --force
# Configure
graphlint config show
graphlint config set --key lang --value en
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success — no warnings matched --fail-on |
1 |
Error — invalid parameters, exception, or config error |
2 |
Warnings found — --fail-on matched specified warning types |
Use --fail-on with a comma-separated list of warning types to make graphlint query return exit code 2 when matching warnings are found. This enables CI pipeline integration without blocking on non-critical warnings.
Graphlint is static-analysis based and cannot recognize certain Python dynamic references (e.g., getattr, importlib), which may produce unexpected exit codes. Only use --fail-on for CI blocking behavior when you're confident in your configuration. Agents are better suited for logic that requires contextual judgment. See Limitations for details.
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 — graphlint performs static analysis and cannot detect runtime linkage such as
getattr,importlib, or dynamic dispatch patterns, which may result in false positives. This primarily affects Python; Rust's static dispatch model produces fewer false positives. Mitigation: add custom entry rules matching your codebase's conventions. For example, graphlint's own codebase usesfunction_def:_detect_*andfunction_def:visit_*patterns to prevent functions discovered viagetattrfrom being flagged as dead. - Python dynamic imports — due to Python's dynamic import mechanisms (
importlib,getattr, metaclasses, etc.), the default entry templates may produce false positives in codebases that rely heavily on runtime dispatch. Users should tune theentry_rulesconfiguration to match their project's conventions. - Rust macro expansion — tree-sitter parses unexpanded source; procedural macros and
macro_rules!bodies appear as opaque token trees. Some macro-generated call paths may be missed.#[derive]attributes are partially recognized via implicitinheritedges. --public-as-entryscope — this flag only applies to languages withpublicvisibility declarations (Rustpub). It has no effect on Python files. Toggling this flag triggers a full re-index. For long-term library-crate analysis, prefer enabling therust_pub_apientry rule viagraphlint configto persist the setting.- 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). Small projects (~60 files) complete in ~1 second. This cost is one-time, after the initial full scan, subsequent queries use incremental updates.
License
MIT — see LICENSE for details.
Links
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.3.5.tar.gz.
File metadata
- Download URL: graphlint-0.3.5.tar.gz
- Upload date:
- Size: 188.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d72d3946dea03a276a1ba5eced83aae8ac8b2ff6215317e151a0f1c0444e840e
|
|
| MD5 |
5e8663aa9af7fe6fc61dbbaf8a50ea88
|
|
| BLAKE2b-256 |
d880e974007a64c53112df6b046e6f3ab876d4c4c74b928432f3816305c0243f
|
File details
Details for the file graphlint-0.3.5-py3-none-any.whl.
File metadata
- Download URL: graphlint-0.3.5-py3-none-any.whl
- Upload date:
- Size: 110.0 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 |
c5bef531198e49668485d7bfbe065ff146fc1d8fb653af09e05fe8137bec8cbf
|
|
| MD5 |
9de3f730027d8cb5bad121157d453567
|
|
| BLAKE2b-256 |
efe8431be5a1e6ee10778ceb0f5bde88c8ab0a5ef04311878c08b98b85531c61
|