Deno File Flattener for Claude Projects

Claude ProjectsDeno

Deno File Flattener for Claude Projects #

Claude Projects are awesome for iterating on code projects while preserving the context. If you have more than a handful of files and if those files are in multiple folders, it does get a bit tedious to upload those files to Claude projects while also trying to convey the structure of the project.

tree_flatten is a Deno 2 script that flattens a directory structure by copying all files into a single output directory, replacing path separators with '^' in the filenames.

It also outputs a directory_structure.txt file that describes the original and flattened directory structures to help Claude understand the project better.

Original Directory Structure:
===========================
├── backend
│   ├── models
│   │   └── model.py
│   ├── api.py
│   └── requirements.txt
├── frontend
│   ├── src
│   │   ├── component.vue
│   │   └── main.js
│   └── index.html
├── deno.json
├── deno.lock
├── README.md
└── tree_flatten

Flattened Directory Structure:
===========================
└── flattened_files
    ├── backend^api.py
    ├── backend^models^model.py
    ├── backend^requirements.txt
    ├── deno.json
    ├── deno.lock
    ├── frontend^index.html
    ├── frontend^src^component.vue
    ├── frontend^src^main.js
    ├── README.md
    └── tree_flatten

Installation and setup #

Make sure you have Deno 2 installed. Then make the file executable and copy it to a location in your PATH, for example /usr/local/bin.

chmod +x tree_flatten

cp tree_flatten /usr/local/bin       

source ~/.zshrc

You can now run this script from any directory from the terminal

Basic usage #

Directory Flattening Tool
  Usage: tree_flatten [options]
  
  Options:
    -h, --help              Show this help message
    -o, --output <dir>      Output directory (default: "flattened_files")
    -e, --exclude <dirs>    Comma-separated list of directories to exclude
                           (default: "dist,node_modules,.git")
    -v, --vue-txt          Append .txt to .vue files
    -t, --top              prepend to files
    
  Example:
    tree_flatten -o flat -e node_modules,dist,build -vue-txt -t frontend

Note that Claude doesn't allow the .vue extension so the -v option appends .txt to vue files.

Upload to Claude Projects #

After you run this command, you can then upload the files in the flattened directory to your Claude project:

Claude Projects upload Claude Projects Files

Source code on GitHub