A fast, lightweight command-line utility written in Zig that recursively merges source code files from a directory tree into a single markdown-formatted output file. Perfect for code reviews, documentation, or creating consolidated views of your codebase.
- Recursive Directory Scanning: Automatically traverses subdirectories to find all matching source files
- Flexible File Filtering: Filter files by extension using comma-separated lists (e.g.,
c,cpp,h
orjs,ts,tsx
) - Markdown Output: Generates properly formatted markdown with syntax highlighting for 25+ languages
- Sorted Output: Files are sorted alphabetically by path for consistent, predictable results
- Lightweight & Fast: Written in Zig for optimal performance and minimal resource usage
- Cross-Platform: Works on Linux, macOS, and Windows
- Zig (latest version recommended)
git clone <repository-url>
cd merge_source_code
zig build
zig build install
./zig-out/bin/merge_source_code -d <directory> -suffix <extensions> [options]
-d <directory>
: Root directory to scan for source files-suffix <ext1,ext2,...>
: Comma-separated list of file extensions to include (without dots)
-o <output_file>
: Output file path (default:merged_source_code.txt
)-encoding <encoding>
: Text encoding (default:UTF-8
)
# Merge all Zig files from src directory
./zig-out/bin/merge_source_code -d ./src -suffix zig
# Merge C/C++ files with custom output name
./zig-out/bin/merge_source_code -d ./project -suffix c,cpp,h -o combined_c_project.md
# Merge multiple web technologies
./zig-out/bin/merge_source_code -d ./webapp -suffix js,ts,tsx,css,html -o webapp_source.md
# Merge Python project with custom encoding
./zig-out/bin/merge_source_code -d ./python_app -suffix py -encoding UTF-8 -o python_merged.txt
The tool generates markdown-formatted output with:
- File paths as headers
- Syntax-highlighted code blocks for each file
- Proper language detection based on file extensions
- Clean separation between files
Example output:
src/main.zig:
```zig
const std = @import("std");
// ... file content
src/config.zig:
pub const Config = struct {
// ... file content
};
## Supported Languages
The tool automatically detects and applies syntax highlighting for:
- **Systems**: C, C++, Rust, Zig, Go
- **Web**: JavaScript, TypeScript, HTML, CSS, SCSS
- **Scripting**: Python, Bash, Ruby, PHP, Lua
- **JVM**: Java, Kotlin, Gradle
- **Mobile**: Swift, Kotlin
- **Data**: JSON, YAML, TOML, XML, CSV, SQL
- **Config**: INI, Properties, Dockerfile
- **Documentation**: Markdown
- **Scientific**: R, MATLAB
## Development
### Build Commands
```bash
# Standard build
zig build
# Optimized release build
zig build -Doptimize=ReleaseFast
# Build and run
zig build run
# Build and run with arguments
zig build run -- -d ./src -suffix zig -o output.md
# Run all unit tests
zig build test
├── build.zig # Build configuration
├── build.zig.zon # Package manifest
├── src/
│ └── main.zig # Complete implementation
├── CLAUDE.md # AI assistant guidance
└── README.md # This file
The application consists of several key components:
- Config Management: Handles command-line argument parsing and validation
- File Collection: Recursively scans directories and filters files by extension
- Content Processing: Reads file contents and formats them as markdown
- Language Detection: Maps file extensions to syntax highlighting languages
This project is open source. See the license file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Initial release
- Basic directory scanning and file merging functionality
- Support for 25+ programming languages
- Markdown output with syntax highlighting