Skip to main content

gptree 🌳

A CLI tool to provide LLM context for coding projects by combining project files into a single text file with a directory tree structure.

GitHub stars PyPI - Version GitHub Actions Workflow Status GitHub Release GitHub last commit PyPI Downloads

What is gptree?

When working with Large Language Models (LLMs) to continue or debug your coding projects, providing the right context is key. gptree simplifies this by:

  1. Generating a clear directory tree structure of your project.
  2. Combining the contents of relevant files into a single output text file.
  3. 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.

GPTree Demo

Features

  • 🗂 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.

🆕 GPTree GUI - Now Available! 🎉

Experience gptree with a beautiful and efficient graphical interface!

  • Lightweight & Fast: Built with Rust for optimal performance.
  • Cross-Platform: Available on macOS, Windows, and Linux
  • Learn More & Download: Visit gptree.dev
  • Open Source: Check out the code on GitHub

Installation

pipx install gptree-cli

How to setup pipx

Install via Homebrew 🍺

brew tap travisvn/tap
brew install gptree

Homebrew will attempt to install gptree using pip3 and will fall back to binary installation otherwise

Install via pip 🐍

Alternatively, install gptree (gptree-cli) directly via pip:

pip install gptree-cli

Usage

Run gptree in your project directory:

gptree

Or run it anywhere and define the relative path to your project

Options

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
--line-numbers, -n Add line numbers to the output
--previous, -p Use the previously saved file selection
--save, -s Save the selected files to the configuration
--show-ignored-in-tree Show all ignored files in the directory tree
--show-default-ignored-in-tree Show default ignored files in the tree while still respecting gitignore
--version Display the current version of GPTree
path (Optional) Root directory of your project. Defaults to .

Examples

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

Configuration

Global Config (~/.gptreerc)

Define your global defaults in ~/.gptreerc to avoid repetitive setup across projects. Example:

# ~/.gptreerc
version: 2
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
lineNumbers: false
storeFilesChosen: true
showIgnoredInTree: false
showDefaultIgnoredInTree: false

This file is automatically created with default settings if it doesn't exist.

Directory Config (.gptree_config)

Customize settings for a specific project by adding a .gptree_config file to your project root. Example:

# .gptree_config
version: 2
useGitIgnore: false
includeFileTypes: *  # Include all file types
excludeFileTypes: .test  # Exclude test files
outputFile: gptree_output.txt
outputFileLocally: false
copyToClipboard: true
safeMode: false
lineNumbers: false
storeFilesChosen: false
showIgnoredInTree: false
showDefaultIgnoredInTree: true  # Show default ignored files while still respecting gitignore

Configuration Precedence

Settings are applied in the following order (highest to lowest precedence):

  1. CLI Arguments: Always override other settings.
  2. Global Config: User-defined defaults in ~/.gptreerc.
  3. Directory Config: Project-specific settings in .gptree_config.
  4. Programmed Defaults: Built-in defaults used if no other settings are provided.

Safe Mode

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.

Interactive Mode

In interactive mode, use the following controls:

Key Action
↑/↓/j/k 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

Contributing

Contributions are welcome! Please fork the repository and create a pull request for any improvements.

License

This project is licensed under GNU General Public License v3.0 (GPL-3.0).

Metadata

Release files for gptree-cli 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gptree-cli 1.5.0
File Size Uploaded Provenance
gptree_cli-1.5.0.tar.gz 14.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gptree-cli 1.5.0
File Interpreter ABI Platform
gptree_cli-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / gptree_cli-1.5.0.tar.gz

Download URL gptree_cli-1.5.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f791dfa16218ed35f7449b5e9899240a698eb6d5f8d2896404328fe25b06bb38
BLAKE2b-256 checksum
How to use checksums
45a3d623fa36d3739385fb1646168352500bc4f501fb0769a17a02e35847f367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / gptree_cli-1.5.0-py3-none-any.whl

Download URL gptree_cli-1.5.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa699367e8cd08b95bf9b52dcc8df0e15bc082d6b6a9cc0c3df3fbd6f8b91ac2
BLAKE2b-256 checksum
How to use checksums
768fdfbdcbfbd2f041486b714eab8ed0d6a9ef2f4af149cfa702c1eaec38d685
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for gptree-cli 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page