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