#dead-code #import #codebase #static-analysis #export

bin+lib loctree

Fast, language-aware codebase analyzer for detecting dead exports, circular imports, and generating dependency graphs

23 unstable releases (3 breaking)

Uses new Rust 2024

new 0.8.11 Feb 7, 2026
0.8.10 Feb 6, 2026
0.8.9 Jan 21, 2026
0.7.4 Dec 23, 2025
0.5.1 Nov 29, 2025

#1 in #dead-code


Used in loctree_server

MIT/Apache

4MB
78K SLoC

Rust 68K SLoC // 0.0% comments JavaScript 10K SLoC // 0.3% comments BASH 128 SLoC // 0.1% comments TypeScript 8 SLoC

loctree logo

loctree

Scan once, query everything.
AI-oriented static analysis for dead exports, circular imports, dependency graphs, and holographic context slices.

crates.io downloads docs.rs CI License


Install

curl -fsSL https://loct.io/install.sh | sh   # One-liner (installs from crates.io)

Or directly via Cargo:

cargo install loctree        # CLI: loct, loctree
cargo install loctree-mcp    # MCP server for AI agents

Quick Start

loct                              # Scan project, save snapshot to .loctree/
loct --for-ai                     # AI-optimized overview (health, hubs, quick wins)
loct slice src/App.tsx --consumers # Context: file + deps + consumers
loct find useAuth                  # Find symbol definitions
loct find 'Snapshot FileAnalysis'  # Cross-match: where terms meet
loct impact src/utils/api.ts       # What breaks if you change this?
loct health                        # Quick summary: cycles + dead + twins
loct dead --confidence high        # Unused exports
loct cycles                        # Circular imports
loct twins                         # Dead parrots + duplicates + barrel chaos
loct audit                         # Full codebase review

What It Does

loctree captures your project's real dependency graph in a single scan, then answers structural questions instantly from the snapshot. Designed for AI agents that need focused context without reading every file.

Core capabilities:

  • Holographic Slice - extract file + dependencies + consumers in one call
  • Cross-Match Search - find where multiple terms co-occur (not flat grep)
  • Dead Export Detection - find unused exports across JS/TS, Python, Rust, Go, Dart
  • Circular Import Detection - Tarjan's SCC algorithm catches runtime bombs
  • Handler Tracing - follow Tauri commands through the entire FE/BE pipeline
  • Impact Analysis - see what breaks before you delete or refactor
  • jq Queries - query snapshot data with jq syntax (loct '.files | length')

MCP Server

loctree ships as an MCP server for seamless AI agent integration:

loctree-mcp    # Start via stdio (configure in your MCP client)

Tools: repo-view, slice, find, impact, focus, tree. Each tool accepts a project parameter - auto-scans on first use, caches snapshots in RAM.

{
  "mcpServers": {
    "loctree": {
      "command": "loctree-mcp",
      "args": []
    }
  }
}

Language Support

Language Dead Export Accuracy Notes
Rust ~0% FP Tested on rust-lang/rust (35K files)
Go ~0% FP Tested on golang/go (17K files)
TypeScript/JavaScript ~10-20% FP JSX/TSX, React patterns, Flow, WeakMap
Python ~20% FP Library mode, __all__, stdlib detection
Svelte <15% FP Template analysis, .d.ts re-exports
Vue ~15% FP SFC support, Composition & Options API
Dart/Flutter Full pubspec.yaml detection

Auto-detects stack from Cargo.toml, tsconfig.json, pyproject.toml, pubspec.yaml, src-tauri/.

Holographic Slice

Extract 3-layer context for any file:

loct slice src/App.tsx --consumers
Slice for: src/App.tsx

Core (1 files, 150 LOC):
  src/App.tsx (150 LOC, ts)

Deps (3 files, 420 LOC):
  [d1] src/hooks/useAuth.ts (80 LOC)
    [d2] src/contexts/AuthContext.tsx (200 LOC)
    [d2] src/utils/api.ts (140 LOC)

Consumers (2 files, 180 LOC):
  src/main.tsx (30 LOC)
  src/routes/index.tsx (150 LOC)

Total: 6 files, 750 LOC

Multi-term queries show where terms meet, not flat OR:

loct find 'Snapshot FileAnalysis'
=== Cross-Match Files (9) ===
  src/snapshot.rs: Snapshot(6), FileAnalysis(4)
  src/slicer.rs: Snapshot(2), FileAnalysis(3)
  ...

=== Symbol Matches (222 in cross-match files) ===
  src/snapshot.rs:20 - Snapshot [struct]
  src/types.rs:15 - FileAnalysis [struct]
  ...

=== Parameter Matches (4 cross-matched) ===
  src/slicer.rs:45 - snapshot: &Snapshot in build_slice(analyses: &[FileAnalysis])

jq Queries

Query snapshot data directly:

loct '.dead_parrots'                           # Dead code findings
loct '.files | length'                         # Count files
loct '.edges[] | select(.from | contains("api"))' # Filter edges
loct '.summary.health_score'                   # Health score

CI Integration

loct lint --fail --sarif > results.sarif    # SARIF for GitHub/GitLab
loct --findings | jq '.dead_parrots | length'  # Check dead code count
loct doctor && echo 'Clean'                 # Health gate

Crates

Crate Description
loctree Core analyzer + CLI (loct, loctree)
report-leptos HTML report renderer (Leptos SSR)
loctree-mcp MCP server for AI agents

Development

make precheck        # fmt + clippy + check (run before push)
make install         # Install loct + loctree-mcp
make test            # Run all workspace tests
make publish         # Cascade publish to crates.io

Badge

[![loctree](https://img.shields.io/badge/analyzed_with-loctree-a8a8a8?style=flat&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2Ij48cmVjdCB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIGZpbGw9IiMwMDAiLz48dGV4dCB4PSI4IiB5PSIxMiIgZm9udC1mYW1pbHk9Im1vbm9zcGFjZSIgZm9udC1zaXplPSIxMCIgZmlsbD0iI2E4YThhOCIgdGV4dC1hbmNob3I9Im1pZGRsZSI+TDwvdGV4dD48L3N2Zz4=)](https://crates.io/crates/loctree)

License

MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.


VibeCrafted with AI Agents (c)2025-2026 VetCoders

Dependencies

~47–91MB
~1.5M SLoC