Skip to content

API REFERENCE

Crate loctree

AI-oriented project analyzer. A static-analysis instrument designed for AI agents and developers β€” addresses the generation patterns that produce re-export cascades, circular imports, and spaghetti dependencies.

Canonical source: docs.rs/loctree Β· crates.io

FEATURES

Features

  • Holographic Slice β€” One file plus all its imports plus every consumer in a single context bundle.
  • Handler Trace β€” Trace a Tauri / IPC handler end-to-end across the FE β†’ BE boundary.
  • Dead Export Detection β€” Find exports with zero importers β€” confidence-scored, suppressible.
  • Circular Import Detection β€” Tarjan SCC over the import graph; identifies the weakest link in each cycle.
  • Auto-Detect Stack β€” Marker-file detection for Rust, JS/TS, Python, Go, Dart, Svelte, Vue, CSS.
  • HTML Reports β€” Server-rendered Leptos report with a navigable dependency graph.

QUICK START Β· LIBRARY

Quick start β€” library usage

Two examples mirroring the docs.rs intro β€” stack detection and import analysis.

Detect a project's stack

use loctree::{detect, snapshot, slicer};
use std::path::PathBuf;

let detected = detect::detect_stack(std::path::Path::new("."));
println!("Detected: {}", detected.description);

Run import analysis

use loctree::{analyzer, args};
use std::path::PathBuf;

let mut parsed = args::ParsedArgs::default();
parsed.dead_exports = true;
parsed.circular = true;

let roots = vec![PathBuf::from(".")];
analyzer::run_import_analyzer(&roots, &parsed).unwrap();

QUICK START Β· CLI

Quick start β€” CLI

The CLI binary is loct (loctree binary remains as a compatibility alias).

loctree
loctree slice src/App.tsx
loctree trace get_user
loctree -A --circular
loctree --for-ai

Full operational walkthrough β€” install, scan, integrate β€” lives on /how-it-works.

RE-EXPORTS

Re-exports

Public surface re-exported at the crate root. Each entry links to the canonical rustdoc page.

  • Mode β€” Top-level analysis mode (Init, Slice, Search, AnalyzeImports, ForAi, Tree, Git).
  • Options β€” Aggregate options consumed by run_import_analyzer.
  • OutputMode β€” Human / JSON / SARIF emission selector.
  • ColorMode β€” Auto / always / never color rendering.
  • FileAnalysis β€” Per-file analysis record (imports, exports, edges, language).
  • DetectedStack β€” Result of stack detection β€” language, marker file, description.
  • detect_stack β€” Detect the project stack from marker files.
  • HolographicSlice β€” File + dependencies + consumers context bundle.
  • SliceConfig β€” Configuration for the slicer (depth, filters).
  • Snapshot β€” Persistent snapshot β€” files, edges, indexes, bridges.
  • run_import_analyzer β€” Top-level entry point for analysis pipelines.
  • ReportSection β€” Report section identifier used by HTML rendering.
  • RefactorPlan β€” Composite refactor plan with steps and risk.
  • ParsedCommand β€” Parsed CLI command after subcommand resolution.

MODULES

Modules

Top-level modules of the loctree crate. Each link opens the rustdoc module page.

  • analyzer β€” Import / export analyzer for TS, JS, Python, Rust, CSS, Go, Dart, Svelte, Vue.
  • args β€” Legacy flag parser used as fallback after the subcommand parser.
  • cli β€” Command enum, parser, and dispatch layer for the loct binary.
  • colors β€” ANSI color rendering and color-mode handling.
  • config β€” Project configuration loader (.loctree/config.toml).
  • detect β€” Stack detection from marker files (Cargo.toml, package.json, …).
  • diff β€” Snapshot diff utilities β€” compare two scans.
  • focuser β€” Module focus β€” files, internal edges, external dependencies.
  • fs_utils β€” Filesystem helpers β€” gather files, respect gitignore + loctignore.
  • git β€” Git integration β€” HEAD detection, staleness checks.
  • impact β€” Impact analysis β€” direct + transitive consumers (blast radius).
  • jaq_query β€” jq-style queries over snapshot.json.
  • layoutmap β€” CSS layout map analyzer.
  • progress β€” Progress bars and status reporting (stderr).
  • query β€” Snapshot query layer used by instant commands.
  • refactor_plan β€” Composite refactor planner β€” steps, risk, sequencing.
  • similarity β€” Similarity metrics for the twins / crowd analyzers.
  • slicer β€” Holographic slice generator β€” file + deps + consumers.
  • snapshot β€” Snapshot persistence β€” files, edges, export index, bridges.
  • suppressions β€” False-positive management (.loctree/suppressions.toml).
  • tree β€” Directory tree rendering with LOC counts.
  • types β€” Core types β€” FileAnalysis, Mode, Options, ImportEntry, ExportSymbol.
  • watch β€” File watcher β€” incremental scans on change.

REPO DOCUMENTATION

The repository ships canonical Markdown for everything operational. Each section below links straight to the source β€” single source of truth, never out of date.

GETTING STARTED

Getting started

Hands-on entry into Loctree β€” install, scan, query.

INSTALLATION

Installation

CLI REFERENCE

CLI reference

Every subcommand of loct, every flag, every output mode.

EDITOR / IDE

Editor / IDE

INTEGRATIONS

Integrations

TUTORIALS

Tutorials

USE CASES

Use cases

Thirty-plus worked examples on real codebases β€” from Tauri command audits to FastAPI route maps.

docs/use-cases/ β€” browse the full catalogue.

Highlights:

PERCEPTION LAYER

Perception layer

The doctrine behind context-over-memory: why agents perceive the codebase before remembering it.

ARCHITECTURE

Architecture

BENCHMARKS

Benchmarks

RESOURCES

Resources