Ultra-efficient CLI tool to extract folder structure and file contents with advanced minification for AI processing.
It's an essential utility for developers, system administrators, and power users who need an efficient solution for file management, data extraction, and AI-ready code preparation.
- π Generate a complete directory structure overview
- π Extract the content of all files in a directory tree
- π« Automatically exclude specific directories from scanning (
.git,node_modules,venv,__pycache__,.next,dist,build) - π§ Filter files by extension with
--excludeoption - π― Include only specific file types with
--includeoption - β‘ ULTRA-AGGRESSIVE: Advanced minification with
--minifyoption (50-70% size reduction) - π οΈ SMART: External minification tools integration for maximum compression
- π¦ Compress output files with
--compressoption - π CLIPBOARD: Copy output directly to clipboard with
--copy - π DEBUG MODE: Advanced debugging with
--debugoption for troubleshooting - ποΈ INTELLIGENT: Skip empty files automatically (no more useless sections)
- π§ AI TOKENS: Estimated token count in stats
- π« BINARY SAFE: Automatically detects and skips binary files
- π Support for special files (
.gitignore,Dockerfile,README, etc.) - π¨ Produces aesthetically pleasing tree-like output
- π Supports versioning of extracted data
- β Automated tests and continuous integration with GitHub Actions
- β¨ NEW: DEFAULT CURRENT DIRECTORY: Simply run
./codepackto process current directory
-
β Directory Structure Generation
- Tree-like visualization of folders and files
- Proper indentation and branch lines
- Marking of excluded directories and files
- Non-recursive exploration of excluded directories
-
β Content Extraction
- Multi-file content extraction in a single operation
- Proper file content formatting with headers
- Automatic character encoding fixes
- Filtering of non-printable characters
- Intelligent empty file detection and skipping
-
β Filtering Options
- Automatic exclusion of system directories (
.git,node_modules,venv,__pycache__,.next,dist,build) - Automatic exclusion of sensitive files (
.env,.DS_Store) - Extension-based inclusion with
--includeoption - Extension-based exclusion with
--excludeoption
- Automatic exclusion of system directories (
-
β Ultra-Aggressive Content Optimization
- Smart minification with
--minifyoption (50-70% reduction) - External minification tools integration (terser, pyminify, csso, etc.)
- Language-aware ultra-aggressive comment removal
- Advanced whitespace optimization
- Special file types support (
.gitignore,Dockerfile,YAML, etc.) - Python ultra-minification (removes excess spaces around operators)
- AI-optimized content formatting
- Smart minification with
-
β Tool Management
--install-minifierscommand for automatic tool installation--minify-infocommand to check available tools- Intelligent fallback to bash minification
- External tool detection and configuration
-
β Compression & Output
- Gzip compression with
--compressoption - File size reduction statistics
- Compression ratio reporting
- Processing statistics (files processed vs skipped)
- Gzip compression with
-
β User Experience
- Progress bar with percentage display
- File counter with thousands separator
- Formatted file size display (bytes, KB, MB)
- Clear completion messages
- Timestamped output files
- Detailed minification tool status reporting
- Default current directory processing - no path required
-
β Debugging & Troubleshooting
- Debug mode with
--debugoption - Detailed file processing information
- Content length tracking
- Minification process monitoring
- Smart debug output (only when requested)
- Debug mode with
- Project documentation
- Codebase analysis
- System audits
- Backup preparation
- Development project snapshots
- AI code analysis and processing (optimized for Claude, GPT, etc.)
- Large codebase compression for sharing
- Ultra-compact code preparation for AI tools
- Quick current directory analysis (just run
./codepack)
git clone https://github.com/w3spi5/codepack.git
cd codepack
chmod +x codepack.shFor maximum compression (50-70% size reduction), install external tools:
# Automatic installation
./codepack.sh --install-minifiers
# Manual installation
npm install -g terser csso-cli html-minifier-terser # JavaScript, CSS, HTML
pip3 install pyminify python-minifier # Python
brew install jq # JSON (macOS)
# sudo apt install jq # JSON (Ubuntu)
go install github.com/tdewolff/minify/v2/cmd/minify@latest # Multi-format (optional)./codepack.sh [path/to/directory] [options]NEW: The directory path is now optional! If no directory is specified, codepack will process the current directory.
--exclude <ext1> [<ext2> ...]- Exclude files with specified extensions--include <ext1> [<ext2> ...]- Include ONLY files with specified extensions--minify- Ultra-aggressive minification (50-70% size reduction with external tools)--compress- Compress output file with gzip--copy- Copy output to system clipboard (requires pbcopy, xclip, wl-copy, or clip.exe)--debug- Enable debug mode for detailed processing information--install-minifiers- Install recommended external minification tools--minify-info- Show status of available minification tools
Note: You cannot use both --include and --exclude at the same time
This project now includes automated tests to ensure reliability and stability.
- Basic and advanced tests are located in the
test/folder. - To run all tests locally:
cd test ./test_basic.sh
- Tests are also executed automatically on every push and pull request via GitHub Actions.
See the test/ folder for details.
Every push and pull request triggers a GitHub Actions workflow that:
- Runs minimal and advanced tests (see
.github/workflows/publish.yml) - Verifies that the CLI works with
--minify-infoand other options - Ensures code quality before publishing to npm or GitHub Packages
You can check the build status at the top of this README.
To publish this package to GitHub Packages or npm:
- Add your npm or GitHub token as a repository secret named
NPM_TOKEN(see GitHub > Settings > Secrets and variables > Actions). - The
.npmrcfile is already configured for GitHub Packages. - The publish step is automated in the GitHub Actions workflow.
Never commit your token in the code or repository.
# Process current directory (no path needed!)
./codepack.sh
# Current directory with ultra-minification (recommended for AI)
./codepack.sh --minify
# Current directory with maximum compression
./codepack.sh --minify --compress
# Current directory with specific file types only
./codepack.sh --include js css html py --minify
# Current directory excluding binary files
./codepack.sh --exclude pdf jpg png --minify
# Current directory with debug mode
./codepack.sh --debug
# Current directory with minification and debug
./codepack.sh --minify --debug# Process specific directory
./codepack.sh /home/user/project
# Ultra-aggressive minification on specific directory
./codepack.sh /home/user/project --minify
# Maximum compression on specific directory
./codepack.sh /home/user/project --minify --compress
# Process only code files with ultra-minification
./codepack.sh /home/user/project --include js css html py --minify
# Exclude binary files and minify
./codepack.sh /home/user/project --exclude pdf jpg png --minify
# Debug mode for troubleshooting specific directory
./codepack.sh /home/user/project --debug
# Debug with minification to see processing details
./codepack.sh /home/user/project --minify --debug
# Debug with specific file types
./codepack.sh /home/user/project --include js py --minify --debug# Check available minification tools
./codepack.sh --minify-info
# Install minification tools automatically
./codepack.sh --install-minifiers# Quick analysis of current project (most common use case)
./codepack.sh --minify
# Share current project with AI tools (ultra-compact)
./codepack.sh --minify --compress
# Debug current project processing
./codepack.sh --debug --minify
# Process only code files in current directory
./codepack.sh --include js py css html --minifyThe --minify option provides intelligent ultra-aggressive optimization with external tool integration:
- terser (recommended) - Ultra-aggressive JS minification
- esbuild - Fast alternative minifier
- Expected reduction: 60-80%
- pyminify - Specialized Python minifier
- python-minifier - Advanced Python optimization
- Expected reduction: 50-70%
- csso-cli - Advanced CSS optimizer
- clean-css-cli - Alternative CSS minifier
- Expected reduction: 70-85%
- html-minifier-terser - Comprehensive HTML minification
- Expected reduction: 40-60%
- jq - Native JSON compactor
- Expected reduction: 30-50%
- minify (Go tool) - Universal minifier for multiple formats
- JavaScript/TypeScript (
.js,.jsx,.ts,.tsx,.mjs) - Python (
.py,.pyw) - Ultra-aggressive space removal - CSS/Preprocessors (
.css,.scss,.sass,.less) - HTML (
.html,.htm,.xhtml) - Java/C/C++ (
.java,.c,.cpp,.h,.hpp) - Shell Scripts (
.sh,.bash) - PHP (
.php) - Ruby (
.rb,.ruby) - Go (
.go) - Rust (
.rs) - XML (
.xml,.xsl,.xsd) - SQL (
.sql)
- Ignore files (
.gitignore,.dockerignore,.eslintignore, etc.) - Dockerfile (preserves functionality)
- YAML (
.yml,.yaml) - preserves indentation - TOML (
.toml) - Config files (
.ini,.conf,.config) - Markdown (
.md) - light optimization for AI readability - Makefile
- README, LICENSE files
- β
Comments removal (all types:
//,/* */,#,<!--,--) - β Whitespace compression (preserving syntax)
- β Empty lines elimination
- β
Operator spacing optimization (
a = bβa=b) - β
Parentheses/brackets spacing (
( a , b )β(a,b)) - β
Import statement cleanup (
import moduleβimport module) - β
String quote spacing (
' string 'β'string')
- Python: Preserves critical indentation, removes docstrings
- CSS: Optimizes selectors and property spacing
- HTML: Removes optional tags and attributes
- JavaScript: Console.log removal, variable mangling (with terser)
- JSON: Complete whitespace removal
- YAML: Preserves indentation hierarchy
- With external tools: 50-70% size reduction
- Bash fallback only: 30-40% size reduction
- Empty files: Automatically skipped (no pollution)
The --debug option provides detailed processing information for troubleshooting and monitoring:
- File processing tracking: Shows current file being processed
- Content analysis: Reports file sizes and content length
- Minification monitoring: Tracks minification start/completion
- Processing statistics: Real-time processing information
- Error diagnosis: Helps identify problematic files
./codepack.sh --minify --debug
DEBUG: Processing file 1/55: ./src/app.js
DEBUG: Reading content from: app.js
DEBUG: Content length: 2847
DEBUG: Starting minification for: app.js
DEBUG: Minification complete for: app.js
DEBUG: Writing to output: app.js- β Troubleshooting: When extraction fails or behaves unexpectedly
- β Performance analysis: Monitor processing of large codebases
- β Minification testing: Verify minification is working correctly
- β File investigation: Identify problematic or empty files
- β Process monitoring: Track progress on large projects
Note: Debug mode significantly increases output verbosity - use only when needed.
The --compress option uses gzip compression:
- Creates a
.gzcompressed version alongside the original file - Reports compression statistics and size reduction percentage
- Provides decompression instructions
- Best practice: Combine with
--minifyfor maximum reduction
The script generates a timestamped file containing:
- Directory Structure: Tree-like representation with excluded items marked
- File Contents: All processed files with clear headers
- Statistics: Processing summary and compression ratios
- Standard:
codepack_YYYYMMDD_HHMMSS.txt - Compressed:
codepack_YYYYMMDD_HHMMSS.txt.gz
$ ./codepack.sh
π§ codepack v4
Automatically excluding directories: '.git', 'node_modules', 'venv', '__pycache__', '.next', 'dist', 'build'
Automatically excluding files: '.env', '.DS_Store'
No filtering - processing all file types
ποΈ Generation in progress, please wait ...
Found 11 files to process
[==================================================] 100%
π Processed 8 files (skipped 3 empty files)
β
Extraction complete
π Output: "./codepack_20250622_215837.txt"
π Stats: 1 920 lines, 85 KB
π All file types were processed.
π― Ready for AI analysis! Use --minify-info to check available tools.
- Empty files skipped: No more useless sections with just headers
- Processing statistics: Shows files processed vs. skipped
- Compression reporting: Detailed size reduction metrics
- Default current directory: No need to specify path for current directory
- Bash shell (required for running tests in
test/) findcommandsed,tr,wc(standard Unix tools)
- Node.js + npm (for JavaScript/CSS/HTML tools)
- Python 3 + pip (for Python minifiers)
- jq (for JSON minification)
- Go (for multi-format minify tool)
- gzip (for compression feature)
# Package managers
brew install node jq
npm install -g terser csso-cli html-minifier-terser
pip3 install pyminify python-minifier
# Test your installation with debug mode
./codepack.sh --minify-info
./codepack.sh --minify --debugsudo apt update
sudo apt install nodejs npm jq python3-pip
npm install -g terser csso-cli html-minifier-terser
pip3 install pyminify python-minifier
# Test your installation with debug mode
./codepack.sh --minify-info
./codepack.sh --minify --debugsudo yum install nodejs npm jq python3-pip
npm install -g terser csso-cli html-minifier-terser
pip3 install pyminify python-minifier
# Test your installation with debug mode
./codepack.sh --minify-info
./codepack.sh --minify --debugThis afternoon in January 2025, I'm using claude and I have to continually open new chats because a message informs me that using the same chat window consumes more and more tokens.
In fact, it's true that coming back months later on a 3km long chat window is never very appreciable. And since you have to give Claude the context each time and the manual extraction is boring, that's it! I started coding a program in bash, Claude and o1 helped me fix the bugs and improve the program (even if Claude seems to be a level above), and the result is a project that I am proud of because it meets my expectations exactly and it only took me 3 hours to create all of this.
UPDATE: After several iterations and user feedback, I've enhanced the tool with ultra-aggressive minification, external tool integration, and smart file processing. The goal is to achieve 50-70% size reduction for optimal AI processing while maintaining code functionality. The latest update includes default current directory processing - simply run ./codepack without specifying a path! Enjoy and don't hesitate to contribute!
- Make sure you gave execution rights:
chmod +x codepack.sh - Run:
./codepack.sh --minify-infoto test your environment
- No, the script works without them, but compression will be less efficient. Use
--install-minifiersto install everything automatically.
- Use:
gzip -d codepack_YYYYMMDD_HHMMSS.txt.gz
- Yes! Simply run
./codepack.shand it will process the current directory by default. You can also combine it with options like./codepack.sh --minify.
- They are equivalent! Both process the current directory. The new version makes the directory path optional for convenience.
- Go to the
test/folder and run the scripts:./test_basic.sh
- Create a branch from
main - Code the functionality
- Submit a Pull Request
- β Default current directory processing β¨ NEW in v4
- β Debug mode for advanced troubleshooting β¨ NEW in v3.2.1
- Real-time minification during file processing
- Parallel processing for large codebases
- Custom minification rules configuration
- Binary file detection and smart handling
- Language detection improvements
- Plugin system for custom minifiers
- β¨ NEW: Default current directory processing - run
./codepackwithout specifying a path - π§ IMPROVED: Simplified usage - directory path is now optional
- π ENHANCED: Updated documentation with current directory examples
- π― OPTIMIZED: Better argument parsing for optional directory
- π NEW LOGO and package name
- β¨ NEW:
--debugmode for detailed processing information - π FIX: Debug messages no longer appear without explicit
--debugflag - Debug Mode: Added optional
--debugflag for detailed processing information and troubleshooting - Enhanced Progress Tracking: Improved progress bar with file count display (current/total)
- Intelligent File Processing: Smart detection and skipping of empty files to reduce output pollution
- External Tool Timeout Protection: Added 10-second timeout for external minifiers to prevent hanging
- Large File Handling: Automatic fallback for HTML files over 30KB to prevent html-minifier-terser crashes
- π§ IMPROVED: Cleaner output in production mode
- Robust Error Handling: All sed operations now include fallback mechanisms and error protection
- Memory Management: Better cleanup of temporary files and resources
- Processing Statistics: Detailed reports on processed vs skipped files
- Minification Reliability: Enhanced minification functions with comprehensive error handling for edge cases
- Tool Detection: Improved external minifier detection and configuration
- π ENHANCED: Better troubleshooting capabilities
- Fixed Progress Bar: Progress now correctly displays 0-100% instead of stopping at intermediate percentages
- Fixed Argument Parsing: Resolved issues with corrupted command-line arguments
- Fixed Empty Content Handling: All minification functions now properly handle empty or whitespace-only content
- Fixed External Tool Integration: Improved stability when using terser, pyminify, csso, html-minifier-terser, and jq
- Fixed Resource Cleanup: Proper cleanup of temporary files and moviepy resources
- π Ultra-aggressive minification with external tools
- π¦ Advanced compression capabilities
- π οΈ Smart minification tool detection and installation
- π Processing statistics and empty file detection
- Ultra-Aggressive Minification: Complete rewrite of minification engine with 50-70% size reduction
- External Tool Integration: Support for terser, pyminify, csso-cli, html-minifier-terser, and jq
- Intelligent Fallback System: Automatic fallback to bash minification when external tools unavailable
- Multi-Language Support: Enhanced support for 20+ file types including Python, JavaScript, CSS, HTML, JSON, YAML, XML, and more
- Tool Management Commands: Added
--install-minifiersand--minify-infocommands
- Advanced File Type Detection: Intelligent detection of file types based on content and extensions
- Modular Architecture: Completely refactored codebase with separate functions for each file type
- Enhanced Configuration: Improved handling of special files like Dockerfile, .gitignore, Makefile
- Better Resource Management: Optimized memory usage and file handling
- Fixed Minification Stability: Resolved crashes with complex file contents
- Fixed Character Encoding: Better handling of non-ASCII characters
- Fixed Large File Processing: Improved performance with files over 10MB
- Compression Support: Added
--compressoption for gzip compression of output files - File Filtering System: Added
--includeand--excludeoptions for fine-grained file selection - Progress Indicators: Added visual progress bars with percentage completion
- Processing Statistics: Comprehensive reporting of processed files, sizes, and compression ratios
- Minification Framework: Initial implementation of code minification capabilities
- Enhanced Directory Tree: Improved tree visualization with better formatting and excluded item marking
- File Size Reporting: Added file size calculations and formatting (bytes, KB, MB, GB)
- Error Handling: Comprehensive error handling and validation
- User Experience: Better command-line interface with detailed help and examples
- Fixed Directory Exclusion: Proper handling of nested excluded directories
- Fixed File Permissions: Better handling of read-only and protected files
- Fixed Output Formatting: Consistent formatting across different file types
- Automatic Directory Exclusion: Smart exclusion of common build/cache directories (
.git,node_modules,venv,__pycache__,.next,dist,build) - Sensitive File Protection: Automatic exclusion of sensitive files (
.env,.DS_Store) - Enhanced Output Format: Improved output structure with clear file headers and separators
- Timestamped Output: Output files include timestamp for version control
- Better File Detection: Improved file type detection and handling
- Enhanced Tree Generation: More accurate directory tree representation
- Cleaner Output: Reduced noise in output files by filtering irrelevant content
- Fixed Tree Structure: Corrected issues with nested directory visualization
- Fixed File Reading: Better handling of binary and special files
- Fixed Path Resolution: Improved path handling across different operating systems
- Directory Structure Visualization: Added comprehensive tree-like directory structure generation
- Dual-Section Output: Separated directory structure and file contents into distinct sections
- File Content Extraction: Complete file content extraction with proper formatting
- Command-Line Interface: Professional CLI with argument parsing and validation
- Modular Code Structure: Refactored codebase into logical functions and sections
- Better Documentation: Comprehensive inline documentation and comments
- Enhanced Error Messages: More descriptive error messages and validation
- Fixed File Reading: Resolved issues with special characters and encoding
- Fixed Directory Traversal: Improved handling of symlinks and special directories
- Fixed Output Generation: Consistent output formatting across all file types
- Recursive Directory Processing: Full recursive traversal of directory structures
- Multiple File Support: Ability to process multiple files in a single operation
- Basic File Filtering: Initial implementation of file type filtering
- Performance Optimization: Faster file processing and reduced memory usage
- Better File Handling: Improved handling of large files and directories
- Fixed Memory Issues: Resolved memory leaks with large directory structures
- Fixed File Encoding: Better handling of different character encodings
- Initial Release: Basic file extraction functionality
- Single File Processing: Extract content from individual files
- Simple Output Format: Basic text output with file names and content
- Cross-Platform Support: Compatible with Unix-like systems (Linux, macOS, BSD)
- File Content Reading: Basic file reading capabilities
- Text Output: Simple text-based output format
- Error Handling: Basic error detection and reporting
- Shell Script Foundation: Robust bash script architecture
- β No breaking changes
- β
New
--debugflag is optional and does not affect existing workflows
- β No breaking changes
- β
New minification features are optional and activated only with
--minifyflag - β External tools are optional; script works with built-in fallbacks
- β Output format enhanced but remains backward compatible
- β New filtering options are optional
- β Existing scripts will continue to work without modifications
β οΈ Significant output format changesβ οΈ Directory structure section addedβ οΈ May require updates to scripts that parse output
This project is under MIT license.
ΖΙΔ±s3 Solutions
β‘ Pro Tip: For maximum efficiency with AI tools like Claude, use:
# Quick current directory analysis (most common)
./codepack --minify
# For debugging and optimization testing
./codepack --minify --debug --include js py css html
# Silent production mode for specific directory (clean output)
./codepack /your/project --minify --compress --include js py css htmlThis gives you ultra-compressed, AI-optimized code extracts with minimal effort!
