A CLI tool to provide LLM context for coding projects by combining project files into a single text file with a directory tree structure.
When working with Large Language Models (LLMs) to continue or debug your coding projects, providing the right context is key. gptree
simplifies this by:
- Generating a clear directory tree structure of your project.
- Combining the contents of relevant files into a single output text file.
- Allowing you to select files interactively to fine-tune which files are included.
The resulting file can easily be copied and pasted into LLM prompts to provide the model with the necessary context to assist you effectively.
- π Tree Structure: Includes a visual directory tree of your project.
- β
Smart File Selection: Automatically excludes ignored files using
.gitignore
and common directories like.git
,__pycache__
, and.vscode
. - π Interactive Mode: Select or deselect files interactively using arrow keys, with the ability to quit immediately by pressing
ESC
. - π Global Config Support: Define default settings in a
~/.gptreerc
file. - π§ Directory-Specific Config: Customize behavior for each project via a
.gptree_config
file. - π CLI Overrides: Fine-tune settings directly in the CLI for maximum control.
- π Safe Mode: Prevent overly large files from being combined by limiting file count and total size.
- π Clipboard Support: Automatically copy output to clipboard if desired.
- π Custom Configuration Management: Define configurations that are auto-detected per project or globally.
pipx install gptree-cli
brew tap travisvn/tap
brew install gptree
Homebrew will attempt to install gptree
using pip3
and will fall back to binary installation otherwise
Alternatively, install gptree
(gptree-cli
) directly via pip:
pip install gptree-cli
Note
Performance is better when installing directly with Python (pipx
or pip
)
The binary installation might take a second or two longer to start up (not a huge deal β just something to note)
Run gptree
in your project directory:
gptree
Or run it anywhere and define the relative path to your project
Flag | Description |
---|---|
--interactive , -i |
Enable interactive file selection |
--copy , -c |
Copy result directly to clipboard |
--include-file-types |
Comma-separated list of file types to include (e.g., .py,.js or py,js ). Use * for all types |
--exclude-file-types |
Comma-separated list of file types to exclude (e.g., .log,.tmp or log,tmp ) |
--output-file |
Specify the name of the output file |
--output-file-locally |
Save the output file in the current working directory |
--no-config , -nc |
Disable creation or use of configuration files |
--ignore-gitignore |
Ignore .gitignore patterns |
--disable-safe-mode , -dsm |
Disable safe mode checks for file count or size |
--previous , -p |
Use the previously saved file selection |
--save , -s |
Save the selected files to the configuration |
--version |
Display the current version of GPTree |
path |
(Optional) Root directory of your project. Defaults to . |
Interactive file selection with custom file types:
gptree --interactive --include-file-types '.py,.js'
Save current selection to config:
gptree --interactive --save
Re-use previously saved file selections and copy to clipboard:
gptree --previous --copy
Define your global defaults in ~/.gptreerc
to avoid repetitive setup across projects. Example:
# ~/.gptreerc
version: 1
useGitIgnore: true
includeFileTypes: .py,.js # Include only Python and JavaScript files
excludeFileTypes: .log,.tmp # Exclude log and temporary files
outputFile: gptree_output.txt
outputFileLocally: true
copyToClipboard: false
safeMode: true
storeFilesChosen: true
This file is automatically created with default settings if it doesn't exist.
Customize settings for a specific project by adding a .gptree_config
file to your project root. Example:
# .gptree_config
version: 1
useGitIgnore: false
includeFileTypes: * # Include all file types
excludeFileTypes: .test # Exclude test files
outputFile: gptree_output.txt
outputFileLocally: false
copyToClipboard: true
safeMode: false
storeFilesChosen: false
Settings are applied in the following order (highest to lowest precedence):
- CLI Arguments: Always override other settings.
- Global Config: User-defined defaults in
~/.gptreerc
. - Directory Config: Project-specific settings in
.gptree_config
. - Programmed Defaults: Built-in defaults used if no other settings are provided.
To prevent overly large files from being combined, Safe Mode restricts:
- The total number of files (default: 30).
- The combined file size (default: ~25k tokens, ~100,000 bytes).
Override Safe Mode with --disable-safe-mode
.
In interactive mode, use the following controls:
Key | Action |
---|---|
β/β |
Navigate the file list |
SPACE |
Toggle selection of the current file |
a |
Select or deselect all files |
ENTER |
Confirm the selection and proceed |
ESC |
Quit the process immediately |
Contributions are welcome! Please fork the repository and create a pull request for any improvements.
This project is licensed under GNU General Public License v3.0 (GPL-3.0).