flatten-tool
v1.11.0
Published
CLI tool to flatten directory structures: merge files into a single Markdown file (default) or copy/move to a flat directory with escaped filenames. Respects .gitignore, supports move/overwrite, and more.
Maintainers
Readme
flatten-tool
A CLI utility to flatten directory structures, with perfect GitHub Flavored Markdown compatibility including explicit HTML anchors for maximum portability.

Watch the YouTube video for an example of why you might need to flatten project files into a single document for AI discussions and code reviews.
Installation
Requires Bun runtime (v1.1+).
Via npm
npm install -g flatten-toolRun without installation
You can run flatten-tool directly without installing:
npx flatten-tool [args]
bunx flatten-tool [args]For Development
With devenv (recommended)
Clone the repository and enter the development environment:
git clone https://github.com/MBanucu/flatten-tool.git
cd flatten-tool
devenv shellInside the devenv shell, dependencies are managed automatically. Run the tool with:
bun run index.ts [args]Without devenv
Clone the repository and install dependencies:
git clone https://github.com/MBanucu/flatten-tool.git
cd flatten-tool
bun installRun directly with Bun:
bun run index.ts [args]Usage
By default, the tool merges all file contents into a single Markdown file, starting with a project file tree for navigation, followed by each file's content under a header with its full relative path, in a code block with appropriate language highlighting based on the file extension. The tree includes clickable links to file sections using GitHub-compatible anchors. Ignores and filters are applied as usual.
The <source> argument is optional and defaults to the current directory (.). The <target> argument is also optional and defaults to flattened.md (or flattened/ when using --directory).
Options
--clipboard,-c: Copy the generated Markdown content to clipboard (only for Markdown mode).--directory,-d: Flatten to individual files in a directory instead of merging to Markdown.--dry-run,-n: Preview changes without modifying the filesystem.--move,-m: Move files instead of copying (original files will be deleted).--overwrite,-o: Overwrite existing target files.--gitignore,-g: Respect.gitignorefiles (default: true). Use--no-gitignoreto disable.--help,-h: Show help.--version,-v: Show version.
Examples
Flatten current directory to flattened.md:
flatten-toolFlatten a specific directory to flattened.md:
flatten-tool /path/to/sourceFlatten current directory to a custom Markdown file:
flatten-tool output.mdFlatten a specific directory to a custom Markdown file:
flatten-tool /path/to/source output.mdFlatten to individual files in a directory:
flatten-tool --directoryThis creates a flattened/ directory with flattened files.
Flatten a specific directory to a custom output directory:
flatten-tool /path/to/source output-dir --directoryMove files instead of copying:
flatten-tool --moveOverwrite existing files:
flatten-tool --overwriteCombine options:
flatten-tool /path/to/source output.md --move --overwriteFlatten current directory to Markdown and copy to clipboard:
flatten-tool --clipboardPreview flattening without changes:
flatten-tool --dry-runTesting
Run all tests:
unittest # If using devenv
bun unittest # OtherwiseRun tests in watch mode:
bun test --watchRun a specific test:
bun test -t "flattens a simple nested directory"Development
This project uses Bun for runtime, TypeScript for type safety, and follows the guidelines in AGENTS.md for coding standards.
Development Scripts (devenv)
When using devenv, the following scripts are available:
check: Format + lint in one goformat: Format code with Biomelint: Run Biome lintunittest: Run all tests with Bun
Changelog
See CHANGELOG.md for a full list of changes.
License
This project was created using bun init in bun v1.3.8. Bun is a fast all-in-one JavaScript runtime.

