A simple CLI tool to merge source code from multiple files and directories into a single, context-rich text file.
Coalesce is a command-line utility designed to solve a specific problem: consolidating an entire project's source code into one file. The primary goal is to create a comprehensive input for Large Language Models (LLMs), providing them with the full context of a codebase in a single pass—a process used extensively during the development of Coalesce itself.
This is a solo project, developed almost entirely by AI. It's built primarily for personal use, but is being shared in the hope that it might be useful to others. Please use it with the understanding that it's a personal tool, not a commercial product. It's provided "as-is" without any guarantees.
- Directory Merging: Scans one or more source directories and merges all eligible files.
- Configuration File: Easily configure options using a
coalesce.yamlfile. - CLI Overrides: All configuration options can be overridden with command-line arguments for flexibility.
- Smart Filtering:
- Include files based on a whitelist of extensions (
--include-ext). - Exclude directories and files by name (
--exclude-dir,--exclude-file). - Exclude files by extension (
--exclude-ext).
- Include files based on a whitelist of extensions (
- Path-Only Mode: Include the path of binary or irrelevant files without their content (
--path-only-ext). - Project Presets: Quickly generate a
coalesce.yamlfor common project types likedotnetandnode. - Custom Presets: Create your own presets for your specific project structures.
- Dry Run Mode: Preview which files will be included in the output without actually writing the file using the
--dry-runflag. - Cross-Platform: Generates OS-specific run scripts (
coalesce-run.batorcoalesce-run.sh) for ease of use.
Platform Support Note: Coalesce is developed and tested primarily on Windows 🖥️. While the core functionality is intended to be cross-platform, its behavior on macOS and Linux has not been verified. Some features, like the automatic install-path command, are Windows-specific.
- Download the latest executable for your operating system from the Releases page.
- Place the executable in a directory of your choice.
- For ease of use, add this directory to your system's PATH environment variable.
For Windows users, you can use the built-in command to add Coalesce to your user PATH automatically:
coalesce install-pathYou may need to restart your terminal for the PATH change to take effect.
The easiest way to get started is by using the init command in your project's root directory.
-
Initialize Configuration
This command creates a default
coalesce.yamlfile and an appropriate run script (.bator.sh).coalesce init
If you're working with a Node.js or .NET project, you can use a preset to get a more tailored configuration:
# For a Node.js project coalesce init --preset node # For a .NET project coalesce init --preset dotnet
-
Customize
coalesce.yamlOpen the newly created
coalesce.yamland edit thesourceDirectoryPathsand other options to match your project structure.# Path for the final merged output file. outputFilePath: coalesce.md # List of source directories to scan for files. sourceDirectoryPaths: - ./src # - ./another-source-folder
-
Run the Merge
Simply execute the main command. It will automatically find and use your
coalesce.yamlfile.coalesce
This will generate the
coalesce.mdfile (or whatever you specified in your config) in the current directory.
This is the default command. It merges files based on configuration from coalesce.yaml and any command-line overrides.
Syntax
coalesce [output-file] [source-dirs...] [options][output-file]: (Optional) The path for the merged output file. Overrides the value incoalesce.yaml.[source-dirs...]: (Optional) One or more source directories to scan. Overrides the list incoalesce.yaml.
Options
| Option | Description | Behavior with coalesce.yaml |
|---|---|---|
--config <path> |
Path to a specific YAML configuration file. | |
--exclude-dir <name> |
Excludes a directory by name (e.g., 'node_modules'). Can be used multiple times. | Adds to the list in the config file. |
--exclude-file <name> |
Excludes a file by name (e.g., 'yarn.lock'). Can be used multiple times. | Adds to the list in the config file. |
--include-ext <ext> |
Includes only files with this extension (e.g., '.md'). Can be used multiple times. | Replaces the list in the config file. |
--exclude-ext <ext> |
Excludes files with this extension (e.g., '.log'). Can be used multiple times. | Adds to the list in the config file. |
--path-only-ext <ext> |
Includes a file by path only, without content (e.g., '.dll'). Can be used multiple times. | Adds to the list in the config file. |
--dry-run |
Simulates a merge, printing which files would be included. | |
-q, --quiet |
Suppresses all informational output. | |
-v, --verbose |
Enables detailed output, showing why files are skipped. | |
--help |
Show help and usage information. |
Example
# Run using the config file, but add 'dist' to the excluded directories
coalesce --exclude-dir dist
# Run with a specific output file and source, ignoring the config for those values
coalesce docs/context.md ./src ./lib --include-ext .js .cssGenerates a coalesce.yaml configuration file and a run script.
coalesce init [--preset <name>]--preset: (Optional) Initializes the config from a built-in (dotnet,node) or custom preset.
Manages configuration presets.
coalesce preset list: Lists all available built-in and custom presets.coalesce preset path: Displays the path to the user's custom presets directory.
Manages the application's presence in the system PATH.
- On Windows, this command modifies the user's PATH automatically.
- On macOS/Linux, this command displays manual instructions for updating your PATH.
The coalesce.yaml file is the primary way to configure the tool for a project. The init command generates this file for you.
Here is an example of the default configuration:
# Default configuration for Coalesce.
# Use 'coalesce init --preset <name>' for project-specific templates (e.g., dotnet, node).
# Path for the final merged output file.
outputFilePath: coalesce.md
# List of source directories to scan for files.
sourceDirectoryPaths:
- ./src
# (Whitelist) To process ONLY specific file types, add their extensions here (e.g., ".cs", ".py").
# If this list is empty, Coalesce processes ALL files not matched by other exclusion rules.
includeExtensions: []
# (Blacklist) Explicitly skip files with these extensions.
excludeExtensions: []
# Skip directories with these names (case-insensitive).
excludeDirectoryNames:
- .git
# Skip files with these names (case-insensitive).
excludeFileNames:
- .DS_Store
- Thumbs.db
- coalesce.yaml
# For these file types, only include their path in the output, not their content.
# Useful for binary files like images, DLLs, etc.
pathOnlyExtensions:
- .png
- .jpg
- .jpeg
- .gif
- .bmp
- .svg
- .ico
- .webp
- .dll
- .exePresets are templates for coalesce.yaml that help you get started quickly.
Using a Preset
Use the init command with the --preset option:
coalesce init --preset nodeCreating a Custom Preset
-
Find your presets directory:
coalesce preset path
-
Navigate to that directory.
-
Copy the
_template.yamlfile to a new file, for examplemy-preset.yaml. -
Customize
my-preset.yamlto your needs.
You can now use your custom preset:
coalesce init --preset my-presetYour custom preset will now also appear when you run coalesce preset list.
Contributions are very welcome! If you encounter a bug, have an idea for a new feature, or want to improve the code, please feel free to:
- 🐛 Open an Issue: Report bugs or suggest new features.
- 🧑💻 Submit a Pull Request: Offer improvements, fixes, or new functionality.
This project is licensed under the MIT License.