dir2txt
April 18, 2025 ยท View on GitHub
Turn your entire project directory into a clean, readable, and AI-friendly output โ effortlessly. A blazing-fast CLI tool to export a directory's structure and contents into a neatly formatted .txt or .json file.
๐ Features
- ๐ Generates a beautiful directory tree view
- ๐ Dumps actual file contents (optionally stripped of comments)
- ๐ฏ Respects
.gitignore,.dockerignore, and custom ignore files - ๐ง Smart binary file detection (skips them)
- ๐ง Outputs in text or structured JSON โ perfect for feeding into AI pipelines
๐ค Built for AI & LLM Workflows
Working with GPT-based agents? Retrieval-Augmented Generation (RAG)? Code-aware copilots?
dir2txt simplifies the first step: structuring your codebase for context ingestion.
Use it to:
โ
Prepare prompt-friendly project dumps for ChatGPT or Claude
โ
Feed clean file trees + contents into a vector database
โ
Preprocess source code for embedding + search
โ
Power local AI agents that operate on code
โ
Automate audits, changelogs, and debugging assistants
Instead of manually collecting files or asking LLMs to interpret a directory โ
dir2txtgives them context on a silver platter.
๐ง Integrating with AI Pipelines
dir2txt is designed to be the first step in your AI workflow โ transforming messy source directories into clean, structured input for language models.
Whether you're working on Retrieval-Augmented Generation (RAG), AI copilots, code search, or documentation bots โ dir2txt prepares your project for intelligent ingestion.
๐งฉ Typical Pipeline
[ Source Code Directory ]
โ
โผ
๐ dir2txt
(Tree + Content Dump)
โ
โผ
๐ Chunking + Embedding
(e.g., LangChain, llama-index)
โ
โผ
๐๏ธ Vector DB / Index
(ChromaDB, Weaviate, FAISS)
โ
โผ
๐ค LLM / AI Agent
(e.g., GPT, Claude, Mistral, LLaMA)
๐ผ๏ธ Screenshot

๐งช Quick Install via Homebrew
brew tap shubhamoy/dir2txt
brew install dir2txt
๐ ๏ธ Usage
dir2txt ./my-project \
--ignore node_modules,build \
--strip-comments \
--include-dotfiles \
--json
๐ ๏ธ Build Instructions
โ Prerequisites
A C++20 compatible compiler:
- macOS: Apple Clang 14+ or g++-13 via Homebrew
- Linux: g++ 10 or newer
CMake 3.16 or higher
git (to clone the repo)
๐ง Build (macOS)
git clone https://github.com/shubhamoy/dir2txt.git
cd dir2txt
mkdir build && cd build
cmake ..
cmake --build .
./dir2txt