Context Builder
A CLI tool to aggregate directory contents into a single markdown file optimized for LLM consumption.
Overview
Context Builder is a powerful command-line utility that recursively processes directories and creates comprehensive markdown documentation. It's specifically designed to generate context files that are optimized for Large Language Models (LLMs), making it easier to provide complete project context in AI conversations.
Features
- 📁 Recursive directory processing - Scans entire directory trees
- 🔍 Smart filtering - Include only specific file extensions
- 🚫 Flexible ignoring - Exclude folders and files by name
- 🌳 File tree visualization - Generates clear directory structure
- 👀 Preview mode - See what will be processed before generating
- 📝 Line numbers - Optional line numbering for code blocks
- ⚡ Fast processing - Efficient file handling with detailed timing
- 🛡️ Safe operations - Confirms before overwriting existing files
Installation
From crates.io
From source
Usage
Basic Usage
# Process current directory and create output.md
# Process specific directory
# Specify output file
Advanced Options
# Filter by file extensions
# Ignore specific folders/files
# Preview mode (show file tree without generating output)
# Add line numbers to code blocks
# Combine multiple options
Command Line Options
-d, --input <PATH>- Directory path to process (default: current directory)-o, --output <FILE>- Output file path (default: output.md)-f, --filter <EXT>- File extensions to include (can be used multiple times)-i, --ignore <NAME>- Folder or file names to ignore (can be used multiple times)--preview- Preview mode: only show file tree, don't generate output--line-numbers- Add line numbers to code blocks in the output-h, --help- Show help information-V, --version- Show version information
Output Format
Context Builder generates markdown files with the following structure:
- Header - Project name and generation timestamp
- Processing Summary - File counts and filtering information
- File Tree - Visual directory structure
- File Contents - Each file's content in fenced code blocks
Use Cases
- LLM Context Generation - Create comprehensive project context for AI assistants
- Code Reviews - Generate complete snapshots of codebases
- Documentation - Create unified documentation from multiple files
- Project Analysis - Get overview of project structure and contents
- Backup/Archival - Create readable snapshots of project states
Examples
Rust Project
JavaScript Project
Documentation Project
Performance
Context Builder is designed for efficiency:
- Processes thousands of files in seconds
- Memory-efficient streaming for large files
- Parallel directory traversal
- Smart filtering to avoid unnecessary processing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
Changelog
v0.2.0
- Added line numbers support
- Improved file tree visualization
- Enhanced error handling
- Better CLI argument validation
v0.1.0
- Initial release
- Basic directory processing
- File filtering and ignoring
- Markdown output generation
License
MIT License. See LICENSE file for details.