drft
A structural integrity checker for linked file systems. drft treats a directory of files as a dependency graph -- files are nodes, links are edges -- and validates the graph against configurable rules.
Install
Or download a prebuilt binary from GitHub Releases.
The binary is called drft.
Quick start
# Check a directory for issues (no setup required)
# Initialize a config file
# Snapshot the current state
# Check for staleness (files changed since last lock)
# Verify lockfile is current (for CI)
What it does
drft discovers files, runs configurable parsers to extract links between them, and builds a dependency graph. It then validates that graph against a set of rules:
| Rule | Description |
|---|---|
dangling-edge |
Edge target does not exist |
directed-cycle |
Circular dependency detected |
directory-edge |
Edge points to a directory, not a file |
stale |
Dependency changed since last lock |
boundary-violation |
Edge escapes the graph boundary |
encapsulation-violation |
Edge reaches into a child graph's non-interface files |
orphan-node |
Node has no inbound edges |
symlink-edge |
Edge target is a symlink |
fragility |
Structural single point of failure |
fragmentation |
Disconnected graph component |
layer-violation |
Edge violates depth hierarchy |
redundant-edge |
Edge is transitively redundant |
schema-violation |
Node metadata violates schema (requires options) |
All rules default to warn. Override to error for CI enforcement or off to suppress.
See the full documentation for details on parsers, analyses, and rules.
Commands
drft check
Validate the graph against all enabled rules.
drft lock
Snapshot file hashes to drft.lock. This enables staleness detection -- when a file changes, its dependents are flagged.
drft parse
Show raw parser output — what edges each parser found, before graph construction.
drft graph
Export the dependency graph.
drft impact
Show what depends on the given files (transitively), sorted by review priority. Each dependent is annotated with its depth from the changed file, impact radius (its own transitive dependents), and betweenness centrality.
drft report
Query structural analyses of the graph — degree, betweenness, SCC, depth, and more.
See analyses documentation for the full list.
drft init
Create a default drft.toml config file.
Configuration
drft.toml in the graph root:
# Which paths become File nodes (default: ["*.md"])
= ["*.md", "*.yaml"]
# Remove from the graph (also respects .gitignore)
= ["drafts/*", "archive/*"]
# Public interface — nodes accessible from parent graphs.
# Presence of this section enables encapsulation.
[]
= ["overview.md", "api/*.md"]
# Parsers — edge extraction from File nodes
[]
= ["*.md"] # restrict to .md files (default: all)
[] # custom (has command)
= ["*.tsx"]
= "./scripts/parse-tsx-links.sh"
# Rule severities: "error", "warn", or "off"
# Table form for per-rule options or custom rules
[]
= "error"
= "error"
= "error"
[]
= "warn"
= ["README.md", "CLAUDE.md"]
[]
= "./scripts/max-fan-out.sh"
= "warn"
[] # rule-specific options (passed through)
= 5
drft automatically respects .gitignore.
Graph nesting
A directory with a drft.toml or drft.lock becomes a graph. Child directories with their own config are child graphs -- they appear as Graph nodes in the parent graph and are checked independently.
project/
drft.lock # root graph
drft.toml
index.md
docs/
overview.md
research/
drft.toml # child graph (Graph node in parent)
drft.lock
overview.md
internal.md
Use --recursive to check or lock all graphs in one command. Use [interface] in drft.toml to declare a graph's public interface and control which files are visible to the parent.
Output
Text format (default):
error[dangling-edge]: index.md -> gone.md (file not found)
error[stale]: index.md (stale via setup.md)
warn[directed-cycle]: cycle detected: a.md -> b.md -> c.md -> a.md
JSON format (--format json):
Every JSON diagnostic includes a fix field with actionable instructions.
DOT format (drft graph --dot) for graph export:
digraph
Graph JSON follows the JSON Graph Format specification.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Clean (warnings may be present) |
| 1 | Rule violations at error severity, or lock --check found lockfile out of date |
| 2 | Usage or configuration error |
Custom rules
Custom rules are scripts that receive the dependency graph as JSON on stdin and emit diagnostics as newline-delimited JSON on stdout:
[]
= "./scripts/max-fan-out.sh"
= "warn"
#!/bin/sh
# Flag nodes with more than 5 outbound links
See examples/custom-rules for complete examples.
Security note: Custom rules and custom parsers execute arbitrary shell commands defined in drft.toml. Review the [rules] and [parsers] sections before running drft in untrusted repositories, the same as you would review npm scripts or Makefiles.
LLM integration
drft is designed to work with LLMs as both a validation tool during editing sessions and a CI gate.
JSON output
All commands support --format json. The check command returns a summary envelope:
Every diagnostic includes a fix field with actionable instructions an LLM can follow directly.
Impact analysis
After editing a file, check what depends on it:
Results are sorted by review priority — high-radius nodes at shallow depth first. impact_radius tells you how many files cascade if you miss this one. depth tells you how far from the original change. betweenness signals structural centrality. The fix field provides actionable instructions.
This is the primary signal for LLM-assisted editing: after every file change, drft impact tells the agent exactly which files to review, in priority order.
Claude Code hooks
Add to your project's .claude/settings.json to run drft impact automatically after file edits:
When the hook reports impacted files, the agent should read each one and verify its content still reflects the source. Extend the glob patterns (*.md, *.rs) to match the file types in your project.
If drft is installed globally (cargo install drft-cli), use drft instead of npx drft. For npm projects with drft-cli as a devDependency, npx drft ensures it resolves from node_modules.
CI
Run check first — it catches broken links, cycles, and stale files. Then lock --check verifies the lockfile is committed (structural consistency). Both exit with code 1 on failure.
The workflow: edit → drft impact (see what's affected) → review impacted files → fix impacts → drft lock (acknowledge the changes) → commit.
License
MIT