// npm cli
dir-analysis-tool
Find out what is taking up space: largest folders, duplicates, stale files and size budgets for CI, in one pass.
dat is a memory-bounded directory analyzer for the terminal and for CI. It walks a tree once and reports the largest folders and files, duplicated content, empty and stale files and a breakdown by type, then prints it as a table, JSON, Markdown, CSV or a single-file HTML report. Version 3 adds directory diffs, a watch mode, size budgets that fail a build, an explain command that says why a path was skipped, a JSON Schema for every report, and a typed library API that returns exactly what the CLI prints.
- year
- 2025
- type
- npm cli
- group
- developer tools
- status
- released on npm, maintained
- stars
- 8
//in plain words
When a disk fills up, the hard part is finding out why. dat looks through a folder and tells you which sub-folders and files take the most room, which files are exact copies of each other and what has not been touched in years. It can also watch a folder, compare two folders, and refuse to let a project ship if its output grows past a limit you set.
for developers with a full disk, and teams that want a build to fail when a folder grows
the problem
//01the problem
Disk audits either load everything into memory or give you a wall of output you cannot act on or pipe anywhere. The ones that are fast tend to lie a little: they count hard links twice, follow symlink cycles, or skip unreadable paths without saying so.
how it works
//02how it works
- 01
One walk, bounded memory
Every file is stat'ed exactly once. Top-N lists live in bounded heaps, one concurrency limiter covers every filesystem call so wide trees cannot exhaust handles, and depth-first scheduling keeps the queue small. The author's benchmark holds about 9 MB for 140,000 files.
- 02
Duplicates in three stages
Files are grouped by size first. Candidates over 256 KiB are then compared by a SHA-256 sample of their first and last 64 KiB, and only survivors get a full streaming hash with reused buffers. Most files are never read in full, which made duplicates about four times faster than version 2.
- 03
Answers that point somewhere
The headline is the largest folders, and a folder that is 95% one child folds into it so the list points at where the data lives instead of repeating parents. Large, stale, empty and duplicate files come with totals you can act on, and ordering is by size then path, never discovery order.
- 04
Budgets, diffs and a watch
Rules like size<=2MB or duplicates=0 fail a build with exit code 2 and name the rule. dat compare lists what was added, removed and changed between two trees, by content on request. dat watch follows a folder with native filesystem events and streams NDJSON.
- 05
Five outputs, one shape
Pretty, JSON with a versioned schema, Markdown for a pull request summary, CSV with a section column and neutralised formula cells, and an HTML report in a single file with inline charts and a content security policy that blocks all network access. Progress and warnings go to stderr; stdout carries only the report.
- 06
A library that is the CLI
analyze, compare and every renderer are exported as typed ESM, and the library's return value is exactly what --format json prints. Releases are cut by semantic-release from conventional commits with npm provenance, after every pull request passes on three operating systems and the release run passes again on Linux and Windows with three Node versions.
screens
//03screens
6 captured from the running product

01A scan in the terminalThis site's working copy with node_modules included: 31,145 files in 131 ms, the breakdown by type, then the five largest folders and files. 
02The HTML reportOne self-contained file with the totals, the space duplicates could give back, a path filter and the breakdown by type as a chart. 
03Duplicate groupsEach group leads with what removing the copies would reclaim; opened, it lists every copy and the SHA-256 they share. 
04A budget failingThree rules on this site's public folder: two fail with their actual values, and the exit code is 2, so a CI step stops there. 
05Comparing two releasesdat's own npm package, v3.0.0 against v3.2.0: the size change, a renamed chunk, and every changed file with its size before and after. 
06Largest folders in the reportThe same tree ranked by folder, each bar scaled to the largest, with the file count beside it.
measured
//04measured
- 28,660
- files scanned in 0.13 s
- this site's node_modules, 442 mib, warm cache, measured on 19 oct 2026
- 0.5 s
- with duplicate detection
- same tree: 1,559 duplicate groups, 6.3 mib reclaimable
- 500
- tests, 95.6% statements
- vitest, ci run of 30 nov 2026; thresholds enforced on linux and windows with node 22, 24 and 26, and macos with node 22
- 4,501
- npm downloads in a year
- api.npmjs.org, year to 2 dec 2026
decisions
//05decisions
what was chosen, and what it cost
- 01
chose staged SHA-256 duplicate detection
over hashing every file in full
Grouping by size and sampling 128 KiB of large candidates rules out most files before any full read. Duplicates got about four times faster on a 140,000-file tree, at the cost of a third code path and tests for every stage.
- 02
chose largest folders as the headline
over largest files
A full disk is usually a folder problem: caches, build output, old exports. Folding a folder into a child that holds 95% of it keeps the list short, though it hides the parent's name until you expand the tree.
- 03
chose binary units by default
over decimal units
Finder, Explorer and du disagree with each other; KiB and MiB match what the filesystem allocates. The --si flag switches, and a bare 100 still means 100 MiB so version 2 scripts keep working.
- 04
chose one exclude pattern per flag
over a comma-separated list
A list argument kept swallowing the directory argument that followed it. Repeating the flag is more typing but never ambiguous, and gitignore syntax covers most of what people were listing anyway.
- 05
chose stdout for the report only
over mixing progress into the output
Piping dat into jq or a step summary has to work without flags. Progress, warnings and status go to stderr and the progress line only draws when stderr is a terminal.
try it
//06try it
//run it on a folder without installing
node 22.12 or later
npx dir-analysis-tool ~/Downloadsnode 22.12 or later
//find duplicates and files untouched for two years
dat . -d --stale 2y//fail a build when the output grows
exit code 2 when a budget fails
dat dist -b "size<=2MB" -b "duplicates=0" -f markdownexit code 2 when a budget fails
//use it from code
npm install dir-analysis-tool
highlights
//07highlights
- Largest folders, largest files, duplicates, stale and empty files, type breakdown
- Size budgets for CI that exit 2, directory diffs and a watch mode
- Pretty, JSON, Markdown, CSV and single-file HTML output
- Hard links counted once, symlink cycles detected, unreadable paths reported
- Typed library API with the same results as the CLI
- Zero runtime dependencies since 3.1, with an in-house gitignore matcher
- Published with npm provenance; every change is tested on macOS, Linux and Windows first
built with
- TypeScript
- Node.js
- Vitest
- tsdown
- semantic-release
- GitHub Actions
- npm
on githubdir-analysis-tool
- stars
- 8
- license
- MIT
- language
- TypeScript
- latest release
- v3.6.0 nov 30, 2026
- last push
- nov 30, 2026
printings
//08printings
10 entries
v1.0.0
An interactive directory analyzer with a progress bar and a tree view, published to npm the same day.
v2.0.5
A rewrite with a streaming engine and subcommands, a dat binary, and semantic-release cutting versions from conventional commits.
v2.0.7
A new README with a banner and badges; the npm page stays current because documentation commits ship as patches.
v3.0.0
Engine and CLI rewritten: largest folders, compare, watch, budgets, Markdown output, a library API, a versioned JSON schema and staged SHA-256 duplicates. Old flag names still work with a warning.
v3.1.0
The last runtime dependencies removed: gitignore rules matched by an in-house matcher that honours bare wildcards, duplicate candidates hashed with one read per small file, and unreadable folders no longer reported as empty.
v3.2.0
An official agent skill in the repository, installed with npx skills add, so a coding agent can run size, duplicate and budget checks the way the docs intend.
v3.3.0
A new dat explain command shows why a scan skips a path and which rule decided. The 3.2.1 patch before it matched Git on ignore rules, stopped wildcard rules from hanging and escaped control characters in file names.
v3.5.0
A JSON Schema ships for every JSON report. Version 3.4.0 the same day added --compact for bounded one-line JSON, and 3.4.1 stopped Windows files from being mistaken for hard links.
v3.5.8
Eight patches in a week. Watch updates reports from the folders that changed instead of re-scanning and exits 130 on Ctrl+C, large duplicate sets are hashed on worker threads, and compare --content checks byte by byte instead of hashing both files.
v3.6.0
Compare gains --compact for bounded one-line JSON. Data reached by several paths is now counted under a fixed path, not the first one the scan reached.
questions
//09questions
- Why does the total differ from du?
- du reports allocated blocks. dat's headline is the sum of file lengths, and its on-disk line matches du. It also skips .git and node_modules unless you pass --all, and counts hard-linked data once.
- Is it safe to run on a huge directory?
- Memory does not grow with the number of files unless you ask for a listing report, filesystem concurrency is capped, unreadable paths are reported instead of aborting the scan, and Ctrl+C exits cleanly with code 130.
- Does it change anything on disk?
- No. It only reads. The only files it writes are the reports you ask for with --output, --html or --csv, and the config file created by dat init.
- How do I use it in CI?
- Run it with one or more -b budgets and the markdown format, and append the output to the job summary. A failed budget exits with code 2 and names the rule that failed.
- Will my version 2 scripts break?
- Mostly not. Old flag names and config keys are still read with a deprecation warning. The JSON shape moved to schema version 3 and units are binary by default, so check anything that parses the output.
related sheets
//10related sheets
- Repo ScoutExplore a codebase through architecture maps, hotspots, ownership and Git history, all on your machine.analytics platform
- jwt-toolkitInspect, compare and stress-test JWTs, with verification you can read.security cli
- cliprobeBlack-box tests for the terminal bugs that only show up in a pipe, on Ctrl-C or in front of an AI agent.npm cli
//11contact
Say hello.I read everything.
Email is the fastest way to reach me. For anything that needs a conversation, book a call.
to
- name
- Khaled Saeed
- country
- Lebanon