| Crates.io | dirgrab |
| lib.rs | dirgrab |
| version | 0.3.1 |
| created_at | 2025-04-01 21:37:31.726808+00 |
| updated_at | 2025-10-20 17:37:06.238399+00 |
| description | CLI tool to concatenate file contents from directories, respecting Git context. |
| homepage | |
| repository | https://github.com/rileyleff/dirgrab |
| max_upload_size | |
| id | 1615638 |
| size | 83,120 |
dirgrab walks a directory (or Git repository), selects the files that matter, and concatenates their contents for easy copy/paste into language models. It can write to stdout, a file, or your clipboard, and it ships with a library crate so the same logic can be embedded elsewhere.
config.toml, project-local .dirgrab.toml, .dirgrabignore, and CLI flags.--tracked-only and --all-repo to opt out.-s/--stats now prints summary totals plus a per-file token leaderboard, and you can pick which reports to show each run..gitignore, and gracefully skips binary/non-UTF8 files.cargo install dirgrab
# or from a local checkout
# cargo install --path .
Check it worked:
dirgrab --version
dirgrab [OPTIONS] [TARGET_PATH]
TARGET_PATH defaults to the current directory. When invoked inside a Git repo, dirgrab scopes the listing to that subtree unless you pass --all-repo.
-o, --output [FILE] โ write to a file (defaults to dirgrab.txt if no name is given). Conflicts with --clipboard.-c, --clipboard โ copy to the system clipboard instead of stdout or a file.--no-headers / --no-tree / --no-pdf โ disable headers, the directory tree, or PDF extraction.-e, --exclude <PATTERN> โ add glob-style excludes (applied after config files).--tracked-only โ Git mode: limit to tracked files. (Compatibility note: -u/--include-untracked still forces inclusion if you need it.)--all-repo โ Git mode: operate on the entire repository even if the target is a subdirectory.--include-default-output โ allow dirgrab.txt back into the run.--no-git โ ignore Git context entirely and walk the filesystem.--no-config โ ignore global/local config files and .dirgrabignore.--config <FILE> โ load an additional TOML config file (applied after global/local unless --no-config).--token-ratio <FLOAT> โ override the characters-to-tokens ratio used by --stats (defaults to 3.6).--tokens-exclude-tree / --tokens-exclude-headers โ subtract tree or header sections when estimating tokens.-s, --stats [REPORT...] โ print stats reports to stderr. Defaults to overview + top-files=5; provide explicit reports like --stats overview top-files=10.-v, -vv, -vvv โ increase log verbosity (Warn, Info, Debug, Trace).-h, --help / -V, --version โ CLI boilerplate.dirgrab layers configuration in the following order (later wins):
~/.config/dirgrab/config.toml & ~/.config/dirgrab/ignore~/Library/Application Support/dirgrab/config.toml & โฆ/ignore%APPDATA%\dirgrab\config.toml & ignore<target>/.dirgrab.toml<target>/.dirgrabignore--tracked-only, --no-tree, etc.)Sample config.toml:
[dirgrab]
exclude = ["Cargo.lock", "*.csv", "node_modules/", "target/"]
include_tree = true
add_headers = true
convert_pdf = true
tracked_only = false
all_repo = false
[stats]
enabled = true
token_ratio = 3.6
tokens_exclude = ["tree"]
reports = ["overview", "top-files=8"]
ignore files use the same syntax as .gitignore. CLI -e patterns and the active output file name are appended last, so the freshly written file is never re-ingested accidentally.
# Grab the current repo subtree (includes untracked files) and show stats
dirgrab -s
# Limit to tracked files only and exclude build artifacts
dirgrab --tracked-only -e "*.log" -e "target/"
# Force a whole-repo snapshot from within a subdirectory
dirgrab --all-repo
# Plain directory mode with custom excludes, writing to the default file
dirgrab --no-git -e "*.tmp" -o
# Use project defaults but ignore configs for a โcleanโ run
dirgrab --no-config --no-tree --no-headers
git ls-files, scoped to the target subtree unless --all-repo is set, and the final list is sorted for deterministic output. Non-Git mode uses walkdir with the same ordering.--stats is active (or enabled in config), stderr shows the requested reports (default: totals + top files). Exclude tree/headers, adjust the ratio, or pick different reports via config or CLI.dirgrab.txt stays excluded unless explicitly re-enabled, and any active -o FILE target is auto-excluded for that run.dirgrab-lib)The same engine powers dirgrab-lib; import it to drive custom tooling:
use dirgrab_lib::{grab_contents, GrabConfig};
# // build a GrabConfig and call grab_contents(&config)
See docs.rs for API details.
See CHANGELOG.md for the full release history.
Licensed under either of:
Issues and PRs are welcome! Please run cargo fmt, cargo clippy, and cargo test before submitting.