| Crates.io | dircat |
| lib.rs | dircat |
| version | 0.4.1 |
| created_at | 2025-04-23 15:52:20.245355+00 |
| updated_at | 2025-08-03 16:13:07.639697+00 |
| description | High-performance Rust utility that concatenates and displays directory contents, similar to the C++ DirCat. |
| homepage | |
| repository | https://github.com/romelium/dircat-rust |
| max_upload_size | |
| id | 1645890 |
| size | 358,550 |
Fast, gitignore-aware directory concatenation with Markdown output.
dircat-rust recursively walks through a directory, concatenates the content of discovered files (respecting .gitignore rules and offering extensive filtering), and outputs everything as a single, well-formatted Markdown file.
It's designed for speed, developer convenience, and seamless integration with tools that consume Markdown (like LLMs or documentation systems).
Table of Contents
dircat-rust?
src and testsglow for terminal renderingdircat-rust?Are you tired of:
cat-ing multiple files to create context for LLMs or documentation?find ... -exec commands just to view relevant code?.gitignore rules?dircat-rust solves these problems by providing a fast, configurable, and developer-friendly way to concatenate directory contents into a clean Markdown format.
.gitignore rules (via the excellent ignore crate) ensures the output accurately reflects the relevant parts of a typical software project. Sensible defaults like skipping binary files and an option to skip lockfiles enhance usability.rayon) to handle large directories efficiently without unnecessary overhead.dircat will clone the repo into a temporary location and process it.
--git-branch.--git-depth to save time and data.-n to disable)..gitignore Support: Natively respects rules from .gitignore, .ignore, global git config files, and parent directories using the ignore crate. (-t to disable).-i).--include-binary to override).--no-lockfiles).-m, e.g., 1M, 512k).-e) or exclude (-x) files based on their extensions (case-insensitive).-r).-d).//, /* ... */) while respecting strings (-c).-l).## File: headers separate content from different files.-f).-L).-b).-s, -C).walkdir and ignore for file system operations.-o), or the system clipboard (-p).-D).Download the appropriate binary for your system from the Latest Release page.
(Note: Binaries are self-contained and do not require installing Rust or any other language runtime.)
Linux (x86_64 / aarch64) / macOS (Intel x86_64 / Apple Silicon arm64):
# 1. Get the latest version tag from the releases page:
# https://github.com/romelium/dircat-rust/releases/latest
#
# 2. Set the VERSION and TARGET variables.
# - VERSION should be the tag name (e.g., v0.4.1).
# - TARGET options: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin
VERSION="<latest_version>"
TARGET="x86_64-unknown-linux-gnu"
# 3. Download the binary.
curl -L "https://github.com/romelium/dircat-rust/releases/download/${VERSION}/dircat-${VERSION}-${TARGET}.tar.gz" -o dircat.tar.gz
# 4. Extract the archive.
tar xzf dircat.tar.gz
# 5. Make the binary executable.
chmod +x dircat
# 6. Optional: Move the binary to a directory in your system's PATH.
# sudo mv dircat /usr/local/bin/
# OR (if you have a ~/bin directory in your PATH)
# mkdir -p ~/bin && mv dircat ~/bin/
Windows (x86_64):
# 1. Get the latest version tag from the releases page:
# https://github.com/romelium/dircat-rust/releases/latest
#
# 2. Set the VERSION variable.
# - VERSION should be the tag name (e.g., v0.4.0).
$VERSION = "<latest_version>"
$TARGET = "x86_64-pc-windows-msvc"
# 3. Download the binary.
$URL = "https://github.com/romelium/dircat-rust/releases/download/${VERSION}/dircat-${VERSION}-${TARGET}.zip"
$OUTPUT = "dircat.zip"
Invoke-WebRequest -Uri $URL -OutFile $OUTPUT
# 4. Extract the archive.
Expand-Archive -Path $OUTPUT -DestinationPath .
# 5. Optional: Add the directory containing dircat.exe to your system's PATH environment variable
# or move dircat.exe to a directory already in your PATH.
If you have the Rust toolchain installed (rustup), you can install dircat-rust using cargo:
cargo install dircat
(Requires Rust 1.70 or later - check project's Cargo.toml for exact MSRV if specified).
# Clone the repository
git clone https://github.com/romelium/dircat-rust.git
cd dircat-rust
# Build the release binary
cargo build --release
# The executable will be in ./target/release/dircat
./target/release/dircat --version
Install dircat using one of the methods above (pre-compiled binary recommended).
Run it in your project directory:
# Concatenate all relevant text files in the current directory into output.md
# (skips binaries, respects .gitignore by default)
dircat . > output.md
Check output.md! You should see something like:
## File: src/main.rs
```rs
fn main() { /* ... */ }
```
## File: README.md
```md
# My Project
...
```
🚀 Start using dircat now! Try dircat . in your project.
dircat [OPTIONS] [INPUT]
INPUT: The directory, specific file, or git repository URL to process. Defaults to the current directory (.).Basic Examples:
# Process the current directory (text files, respecting .gitignore), print to stdout
dircat
# Process the 'src' subdirectory
dircat src
# Process only a single file (binary check still applies unless --include-binary)
dircat src/main.rs
# Process a remote git repository by cloning it to a temporary directory
dircat https://github.com/romelium/dircat-rust.git
# Process a specific branch of a remote repository
dircat https://github.com/some/repo.git --git-branch develop
# Process the current directory and save to a file
dircat . -o project_snapshot.md
# Process the current directory, including binary files
dircat . --include-binary > output_with_binaries.md
# Process the current directory, excluding common lockfiles
dircat . --no-lockfiles > output_without_locks.md
Below are the most common options. For a full, definitive list, run dircat --help.
| Option | Description |
|---|---|
[INPUT] |
Path to a directory/file, or a git URL. Defaults to .. |
--git-branch BRANCH |
For git URL inputs, clone a specific branch instead of the default. |
--git-depth DEPTH |
For git URL inputs, perform a shallow clone with a limited history depth. |
| Option | Alias | Description | Example |
|---|---|---|---|
--max-size BYTES |
-m |
Skip files larger than this size (e.g., "1M", "512k", "1024"). | -m 1M |
--no-recursive |
-n |
Process only the top-level directory or specified file (disable recursion). | -n |
--ext EXT |
-e |
Include only files with these extensions (case-insensitive, repeatable). | -e rs -e toml |
--exclude-ext EXT |
-x |
Exclude files with these extensions (case-insensitive, repeatable, overrides -e). |
-x log -x tmp |
--ignore GLOB |
-i |
Ignore files/directories matching these custom glob patterns (relative to input path, repeatable). | -i "target/*" -i "*.lock" |
--regex REGEX |
-r |
Include only files whose full path matches any of these regexes (case-insensitive, repeatable). | -r "src/.*\.rs$" |
--filename-regex REGEX |
-d |
Include only files whose filename matches any of these regexes (case-insensitive, repeatable). | -d "^test_.*" |
--no-gitignore |
-t |
Process all files, ignoring .gitignore, .ignore, hidden files, etc. |
-t |
--include-binary |
-B |
Include files detected as binary/non-text (default is to skip them). | --include-binary |
--no-lockfiles |
-K |
Skip common lockfiles (e.g., Cargo.lock, package-lock.json). |
--no-lockfiles |
| Option | Alias | Description |
|---|---|---|
--remove-comments |
-c |
Remove C/C++ style comments (//, /* ... */) from content. |
--remove-empty-lines |
-l |
Remove lines containing only whitespace from content. |
| Option | Alias | Description |
|---|---|---|
--filename-only |
-f |
Show only the filename (basename) in ## File: headers, not the relative path. |
--line-numbers |
-L |
Add line numbers to the beginning of each content line. |
--backticks |
-b |
Wrap filenames in headers and summary list with backticks (`). |
| Option | Alias | Description |
|---|---|---|
--output FILE |
-o |
Write output to the specified file instead of stdout. |
--paste |
-p |
Copy output to the system clipboard. |
--summary |
-s |
Print a summary list of processed files at the end. |
--counts |
-C |
Include line, character (byte), and word counts in the summary (implies -s). |
| Option | Alias | Description | Example |
|---|---|---|---|
--last GLOB |
-z |
Process files matching these glob patterns (relative path/filename) last, in the order specified. Repeatable. | -z README.md -z src/main.rs |
--only-last |
-Z |
Only process files specified with -z/--last. Skip all others (requires -z). |
-Z |
| Option | Alias | Description |
|---|---|---|
--dry-run |
-D |
Print files that would be processed (respecting filters/order), but not content. |
💡 Explore further! Experiment with different filters or check dircat --help for all options.
src and testsdircat . -e rs -r "^(src|tests)/" > rust_code.md
Output Snippet:
## File: src/lib.rs
```rs
// Library code...
```
## File: tests/integration.rs
```rs
// Test code...
```
````
#### Goal: Create context for an LLM, excluding tests, logs, and comments
```bash
dircat . -e rs -e py -e toml -x log -i "tests/*" -c --no-lockfiles -o llm_context.md
```
*Output Snippet:*
````markdown
## File: src/config.py
```py
# Config loading logic (comments removed)
```
## File: Cargo.toml
```toml
# Dependencies (comments removed)
```
````
#### Goal: See which files would be included if max size is 50kB
```bash
dircat . -m 50k -D
```
*Output Snippet:*
```
--- Dry Run: Files that would be processed ---
- src/small_module.rs
- config/settings.toml
--- End Dry Run ---
```
#### Goal: Process `README.md` and `LICENSE` last
```bash
dircat . -z README.md -z LICENSE > project_with_readme_last.md
```
*Output Snippet:* (Other files appear first, then README, then LICENSE)
````markdown
...
## File: src/main.rs
```rs
...
```
...
## File: README.md
```md
...
```
## File: LICENSE
```
...
```
dircat . -z "config/*.toml" -z ".env.example" -Z > config_files.md
Output Snippet: (Only files matching the -z patterns are included)
## File: config/database.toml
```toml
...
```
## File: .env.example
```
VAR=value
```
dircat src -e py -c -l -p
glow for terminal renderingdircat src -e rs | glow -
dircat assets --include-binary > assets_output.md
dircat . --no-lockfiles > project_without_locks.md
# Clones the repo to a temporary directory and processes it.
# Automatically uses SSH keys for private repos.
# Displays a progress bar for long clones.
dircat git@github.com:romelium/dircat-rust.git > repo_content.md
# Clone a specific branch
dircat https://github.com/some/repo.git --git-branch develop
# Perform a shallow clone of depth 1
dircat https://github.com/some/repo.git --git-depth 1
dircat on large directories can produce significant output. Consider using filters (-m, -e, -r, etc.) or the dry-run (-D) option first. Use -o FILE to redirect large outputs to a file instead of overwhelming your terminal.dircat attempts to skip binary files. Use -B if you need to include them (e.g., for embedding small images represented as text, though this is generally not recommended for large binaries). The detection is heuristic and might not be perfect.-K to easily exclude common dependency lockfiles. This is often desirable when generating context for LLMs.## File: headers and the summary (-s) are relative to the input path you provided (or the current directory if none was given).-r): Matches against the relative path (from the input directory), normalized to use / separators.-d): Matches against the filename (basename) only.-i, -z): Match against the path relative to the input path.dircat-rust is designed for speed, processing extremely large files or a vast number of files will still take time. Use filters to narrow down the scope when possible.| Feature | dircat-rust |
cat |
find ... -exec cat {} + |
tree |
|---|---|---|---|---|
| Directory Input | ✅ Yes | ❌ No | ✅ Yes (via find) |
✅ Yes |
| Concatenate Content | ✅ Yes | ✅ Yes (files) | ✅ Yes | ❌ No |
| Gitignore Aware | ✅ Yes (Built-in) | ❌ No | Manual (complex) | Manual |
| Markdown Output | ✅ Yes | ❌ No | ❌ No | ❌ No |
| Skip Binaries | ✅ Yes (Default) | Reads all | Manual (e.g., file) |
N/A |
| Skip Lockfiles | ✅ Yes (-K) |
❌ No | Manual (-name) |
Manual |
| Filtering (Size) | ✅ Yes (-m) |
❌ No | Manual (-size) |
Manual |
| Filtering (Ext/Regex) | ✅ Yes (-e/-x/-r/-d) |
❌ No | Manual (-name/-regex) |
Manual |
| Content Processing | ✅ Yes (-c/-l) |
❌ No | Manual (e.g., sed) |
❌ No |
| Speed Focus | ✅ Yes (Rust/Parallel) | Fast (single) | Variable | Fast (metadata) |
| Cross-Platform Binaries | ✅ Yes | OS specific | OS specific | OS specific |
dircat-rust is under active development. It utilizes modern Rust practices, including:
cargo fmt) and linting (cargo clippy).Contributions are welcome! Whether it's bug reports, feature suggestions, or code improvements, please feel free to:
pre-commit install) to ensure your contributions meet project standards.🤝 We welcome contributions! Please see our COMMIT.md guidelines and check the issue tracker for ways to help.
This project is licensed under the MIT License. See the LICENSE file for details.