I built dir2txt — a simple but powerful CLI tool that turns a directory tree into a clean, structured text or JSON dump.
What It Does • Traverses a project directory • Dumps readable file contents • Optionally strips comments (smart detection of comment blocks + patterns) • Respects .gitignore, .dockerignore, .npmignore, etc. • Outputs LLM-friendly .json or .txt files
Why I Made It
Working with LLMs like GPT-4 or Claude, I kept hitting the same issue: how do I give the model meaningful access to an entire project?
Manually pasting files is noisy and lossy. Existing tools like tree only give structure. I wanted one tool that could: •Structure the directory •Include the real content •Strip boilerplate if needed •Output in a format usable by RAG pipelines, code copilots, or embedders
Example $>dir2txt ./my-project --strip-comments --json > project.json
And then feed it into a vector DB or tokenizer for embedding + retrieval.
Install
Homebrew $>brew tap shubhamoy/dir2txt $>brew install dir2txt