npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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.

Readme

flatten-tool

npm version

A CLI utility to flatten directory structures, with perfect GitHub Flavored Markdown compatibility including explicit HTML anchors for maximum portability.

Video thumbnail
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.

asciicast

Installation

Requires Bun runtime (v1.1+).

Via npm

npm install -g flatten-tool

Run 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 shell

Inside 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 install

Run 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 .gitignore files (default: true). Use --no-gitignore to disable.
  • --help, -h: Show help.
  • --version, -v: Show version.

Examples

Flatten current directory to flattened.md:

flatten-tool

Flatten a specific directory to flattened.md:

flatten-tool /path/to/source

Flatten current directory to a custom Markdown file:

flatten-tool output.md

Flatten a specific directory to a custom Markdown file:

flatten-tool /path/to/source output.md

Flatten to individual files in a directory:

flatten-tool --directory

This creates a flattened/ directory with flattened files.

Flatten a specific directory to a custom output directory:

flatten-tool /path/to/source output-dir --directory

Move files instead of copying:

flatten-tool --move

Overwrite existing files:

flatten-tool --overwrite

Combine options:

flatten-tool /path/to/source output.md --move --overwrite

Flatten current directory to Markdown and copy to clipboard:

flatten-tool --clipboard

Preview flattening without changes:

flatten-tool --dry-run

Testing

Run all tests:

unittest  # If using devenv
bun unittest  # Otherwise

Run tests in watch mode:

bun test --watch

Run 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 go
  • format: Format code with Biome
  • lint: Run Biome lint
  • unittest: 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.