Arun Arumugam

llmdirtree: Directory Visualization and Context Generator for LLM Workflows

python cli filesystem llm developer-tools security

llmdirtree is a specialized developer tool with two powerful capabilities:

  1. Directory Tree Visualization - Creates clean, structured representations of your codebase
  2. LLM Context Generation - Produces AI-powered summaries of your code while respecting security boundaries

Both features are designed to enhance interactions with Large Language Models when discussing or getting help with your code.

Installation

Install directly from PyPI:

pip install llmdirtree

Key Features

Directory Tree Visualization

LLM Context Generation

Usage

Basic Directory Tree

# Generate a simple directory tree
llmdirtree --root /path/to/project --output project_structure.txt

With LLM Context Generation

# Generate both directory tree AND code context
llmdirtree --root /path/to/project --llm-context --openai-key YOUR_API_KEY

This creates two files:

Advanced Options

# Exclude specific directories
llmdirtree --exclude node_modules .git venv dist

# Customize output locations
llmdirtree --output custom_tree.txt --context-output custom_context.txt

# Control file selection for context generation
llmdirtree --max-files 150 --llm-context

# Override gitignore protection (not recommended)
llmdirtree --ignore-gitignore --llm-context

# Specify OpenAI model (skips prompting)
llmdirtree --llm-context --model gpt-4

Example Outputs

Directory Tree

Directory Tree for: /project
Excluding: .git, node_modules, __pycache__, venv
--------------------------------------------------
project/
├── src/
│   ├── main.py
│   └── utils/
│       └── helpers.py
├── tests/
│   └── test_main.py
└── README.md

LLM Context File

# project-name

> A React web application for tracking personal fitness goals with a Node.js backend and MongoDB database.

## src/components/

- **Dashboard.jsx**: Main dashboard component that displays user fitness stats, recent activities, and goal progress.
- **WorkoutForm.jsx**: Form for creating and editing workout entries with validation and submission handling.

## src/utils/

- **api.js**: Contains functions for making API calls to the backend, handling authentication and data fetching.
- **formatters.js**: Utility functions for formatting dates, weights, and other fitness metrics consistently.

Example Workflow

Directory Tree Only

  1. Generate your project structure:

    llmdirtree --root /path/to/project --output structure.txt
    
  2. Include it in your LLM prompt:

    Here's my project structure:
    
    [paste content from structure.txt]
    
    I need help understanding how the components interact...
    

With Full Context

  1. Generate both structure and context:

    llmdirtree --root /path/to/project --llm-context
    
  2. Include in your LLM prompt:

    Here's information about my project:
    
    [paste content from llmcontext.txt]
    
    Now I need help with implementing a new feature...
    
  3. The LLM now has both structural and semantic understanding of your code.

Large File Handling

One of the challenges when analyzing code for LLM context is dealing with large files that exceed token limits. llmdirtree now intelligently processes large files by:

  1. Automatic file chunking - Breaking large files into semantically meaningful chunks
  2. Per-chunk summarization - Analyzing each chunk independently
  3. Cohesive synthesis - Creating a unified summary that captures the essence of the entire file

This approach ensures even large files like complex modules or extensive configuration are appropriately represented in your context.

OpenAI Model Selection

llmdirtree offers flexible model selection to balance performance and cost:

This flexibility allows you to choose the right model for your specific needs, whether optimizing for speed, token capacity, or analysis quality.

.gitignore Support

The tool now fully respects .gitignore patterns for both the directory tree visualization and context generation:

This ensures sensitive files or directories are completely excluded from any visualization or analysis.

Security Features

The tool takes security seriously:

For more implementation details or to contribute, check the GitHub repository.