CopyTree is a command-line tool that recursively scans your current directory, collects source code files (filtered by extension), prints a visual tree of matched files, and copies the content of those files into your clipboard. This makes it easy to share structured code with AI tools or collaboratorsβjust copy, paste, and go!
- π Recursively scans the current directory and subdirectories
- π§ Filters files by one or more extensions (e.g.
go
,js
,py
) - π² Prints a formatted tree of included files for easy visualization
- π Copies all matching files' content into your clipboard in a structured format
- π Outputs a summary: file count, line count, and character count
- π€ ChatGPT mode: Splits output into manageable sections for easier LLM pasting
git clone https://github.com/SarahRoseLives/CopyTree.git
cd CopyTree
Make sure you have Go installed.
go build -o copytree main.go
./copytree
- Scans the current directory and subdirectories
- Prints a tree of all files
- Copies all file contents to your clipboard
./copytree go js py
- Only includes files ending with
.go
,.js
, or.py
./copytree --chatgpt
- Splits the output into sections of up to 20,000 characters, ideal for pasting into ChatGPT or other LLMs with context limits.
.
βββ main.go
βββ utils.go
βββ README.md
Copied Dir Tree and 3 files to clipboard
Total lines 200 Total Characters 5274
After running, your clipboard will contain both the directory tree and the file contents, in a format like this:
.
βββ main.go
βββ utils.go
βββ README.md
====./main.go====
<contents of main.go>
====./utils.go====
<contents of utils.go>
====./README.md====
<contents of README.md>
- The tool works from your current directory. To copy from your project root, run it from there.
- Clipboard integration uses atotto/clipboard, which supports macOS, Windows, and Linux with X11.
- On Linux, make sure you have
xclip
orxsel
installed for clipboard support. - Unknown CLI flags are ignored (except
--chatgpt
).
- Share code with ChatGPT or other LLMs: Instantly copy all relevant code files for context.
- Send snippets to a collaborator: Grab only your
go
andyaml
files for a quick review. - Create code archives: Easily gather source files by extension for documentation or backup.
- The
--chatgpt
flag splits the output into 20,000 character sections, with prompts to make it easy to paste sequentially into LLMs with limited context windows. - Summaries are color-coded:
- Green (β€20,000 chars): Safe for most AIs
- Yellow (β€50,000 chars): May work with larger context AIs
- Red (>50,000 chars): Unlikely to work in one paste