dir2txt

April 18, 2025 ยท View on GitHub

logo 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.

License: MIT


๐Ÿ” 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 โ€” dir2txt gives 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

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