A lightweight (60-line) Perl script that helps collect and organize codebase context for LLMs. Perfect for gathering relevant code snippets and files before sending them to your favorite LLM.
- Quick context gathering from any directory
- Flexible file filtering with include/exclude patterns
- Outputs a single, clean Markdown file ready for LLM consumption
- Maintains file structure and organization in the output
- Extremely portable - just needs Perl and one module
- Clone or download this repository
- Ensure you have Perl 5.10+ installed
- Install the required File::Slurp module:
or
cpanm File::Slurp
cpan File::Slurp
- Make the script executable:
chmod +x context-collector.pl
./context-collector.pl [options]--help, -h: Show usage information--dir, -d <directory>: Directory to scan (defaults to current directory)--output, -o <file>: Output file (defaults to codebase.md)--include, -i <patterns>: Comma-separated patterns to include (case-insensitive)--exclude, -e <patterns>: Comma-separated patterns to exclude (case-insensitive)
-
Collect context from current directory:
./context-collector.pl
-
Gather context from a specific project:
./context-collector.pl --dir my-project --output context.md
-
Focus on specific file types while excluding irrelevant directories:
./context-collector.pl --include py,js,jsx --exclude node_modules,venv
- Fork this repository
- Create a new branch for your contribution
- Commit and push your changes
- Open a Pull Request
We welcome feature requests, bug reports, and improvements!