Dump your entire project into one text file. For LLMs, code reviews, or backups.
---- Overview
- Features
- Quick Start
- Installation
- Usage Guide
- Ignore Patterns
- Output Example
- Requirements
- License
dir2txt is a lightweight, zero-dependency Python command-line tool that recursively scans your project directory, extracts the content of all text-based files, and aggregates them into a single, well-structured text file.
This tool is designed for developers who need to:
- Feed entire codebases to Large Language Models (LLMs) like ChatGPT or Claude
- Perform comprehensive code reviews across multiple files
- Create human-readable backups of project source code
- Generate documentation that includes both structure and content
- Archive project states in a portable text format
🔍 Recursive Scanning
Automatically traverses all subdirectories from the target path
🚫 Binary Detection
Intelligently skips binary files using content-based detection
📝 Comment Stripping
Removes code comments to reduce token usage
📊 Token Estimation
Calculates token count and warns about context limits
🎯 Custom Ignore Rules
Supports .dir2txtignore with .gitignore-style patterns
📦 Zero Dependencies
Pure Python implementation requiring no external packages
⚡ Fast Processing
Optimized for large projects with efficient file handling
🎨 Clean Output
Generates structured output with directory tree and file separators
# Clone the repository
git clone https://github.com/Hmidqorbani/dir2txt
cd dir2txt
# Install as a Python package
pip install -e .
# Scan your current directory
python -m dir2txt
# Find your output in `project.txt`Method 1: Install as a Package (Recommended)
git clone https://github.com/Hmidqorbani/dir2txt
cd dir2txt
pip install -e .After installation, you can run the tool from any directory:
python -m dir2txtMethod 2: Using Git without Installation
git clone https://github.com/Hmidqorbani/dir2txt
cd dir2txt
python -m dir2txtScan the current working directory
python -m dir2txtScan a specific directory
python -m dir2txt -i ./srcWrite output to a custom file
python -m dir2txt -o output.txtAdd a description header to the output
python -m dir2txt -d "Project Description"| Option | Description | Example |
|---|---|---|
| -i, --input | Target directory to scan | -i ./project/src |
| -o, --output | Custom output file path | -o docs/summary.txt |
| -d, --description | Add a description header | -d "My Django Project v2" |
| -e, --ignore-ext | Ignore specific file extensions | -e pt onnx dcm |
| -h, --help | Show help message and exit | -h |
1. Scan a Django Project
python -m dir2txt -i ./my_django_app -d "Django E-Commerce API" -o api_summary.txt2. Exclude Model Checkpoints
python -m dir2txt -e pt pth h5 onnx3. Scan with Detailed Output
python -m dir2txt -i ./src -o full_analysis.txt -d "Comprehensive Source Code Analysis"Create a .dir2txtignore file in your project root to exclude specific files or patterns:
# .dir2txtignore example
# Python bytecode and cache
*.pyc
__pycache__/
*.pyo
# Environment files
.env
.venv/
venv/
# Node.js
node_modules/
npm-debug.log
# Binary files
*.exe
*.dll
*.so
# Data files
*.pt
*.pth
*.onnx
*.dcm
# IDE specific
.vscode/
.idea/
*.swp
Note: The tool uses the same pattern matching syntax as
.gitignore. Wildcards (*), directory exclusions (/), and negation (!) are fully supported.
Directory Tree Section
$----Start----|test/project.tree.txt|----
test/
├── my_test_project
│ ├── .dir2txtignore
│ ├── example.exe [SKIPPED - Binary]
│ ├── example.txt
│ └── my_privet_file.sec [SKIPPED - Unknown type]
├── project.tree.txt
├── project.txt
└── run.sh
$-----End-----|test/project.tree.txt|----File Content Section
$----Start----|test/my_test_project/example.txt|----
This is a test text.
$-----End-----|test/my_test_project/example.txt|----
$----Start----|test/run.sh|----
#!/bin/bash
echo "Running project..."
$-----End-----|test/run.sh|----Python: Version 3.8 or higher
Dependencies: None (pure Python standard library)
This project is licensed under the MIT License – see the LICENCE file for details.
- LLM Context Preparation – Feed your entire codebase to ChatGPT, Claude, or Gemini for analysis
- Code Review Automation – Create a single file for comprehensive code reviews
- Project Backup – Generate a human-readable text backup of your source code
- Documentation Generation – Combine structure and content for auto-documentation
- Archiving – Preserve the complete state of a project in portable text format
- Auditing – Perform security or compliance audits across all files
-
Large Projects: Use
.dir2txtignoreto exclude unnecessary folders likenode_modulesor__pycache__ -
Binary Files: The tool automatically skips binaries, but you can extend the ignore list for specific types
-
Token Limits: For very large projects, consider:
- Using
-eto ignore large binary extensions - Splitting the output into multiple files
- Using the token estimation to stay within model limits
- Using

