Export codebase structure and contents for AI/LLM context
Project description
TreeMapper
Extends ../CLAUDE.md
Export your codebase for AI/LLM context in one command.
pip install treemapper
treemapper . -o context.yaml # paste into ChatGPT/Claude
Why TreeMapper?
Unlike tree or find, TreeMapper exports structure + file contents in a format optimized for LLM context windows:
name: myproject
type: directory
children:
- name: main.py
type: file
content: |
def hello():
print("Hello, World!")
- name: utils/
type: directory
children:
- name: helpers.py
type: file
content: |
def add(a, b):
return a + b
Usage
treemapper . # YAML to stdout
treemapper . -o tree.yaml # save to file
treemapper . -o - # explicit stdout output
treemapper . --format json # JSON format
treemapper . --format text # tree-style text
treemapper . --no-content # structure only (no file contents)
treemapper . --max-depth 3 # limit directory depth
treemapper . --max-file-bytes 10000 # skip files larger than 10KB
treemapper . -i custom.ignore # custom ignore patterns
treemapper . --no-default-ignores # disable .gitignore/.treemapperignore (custom -i still works)
treemapper . -v 2 # verbose output (0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG)
treemapper --version # show version
Python API
from treemapper import map_directory, to_yaml, to_json, to_text
# Full function signature
tree = map_directory(
path, # directory path (str or Path)
max_depth=None, # limit traversal depth
no_content=False, # exclude file contents
max_file_bytes=None, # skip files larger than N bytes
ignore_file=None, # custom ignore file path
no_default_ignores=False, # disable .gitignore/.treemapperignore
)
# Examples
tree = map_directory("./myproject")
tree = map_directory("./src", max_depth=2, no_content=True)
tree = map_directory(".", max_file_bytes=50000, ignore_file="custom.ignore")
# Serialize to string
yaml_str = to_yaml(tree)
json_str = to_json(tree)
text_str = to_text(tree)
Ignore Patterns
Respects .gitignore and .treemapperignore automatically. Use --no-default-ignores to include everything.
Features:
- Hierarchical: nested
.gitignore/.treemapperignorefiles work at each directory level - Negation patterns:
!important.logun-ignores a file - Anchored patterns:
/root_only.txtmatches only in root,*.logmatches everywhere - Output file is always auto-ignored (prevents recursive inclusion)
Content Placeholders
When file content cannot be read normally, placeholders are used:
<file too large: N bytes>— file exceeds--max-file-byteslimit<binary file: N bytes>— file detected as binary (contains null bytes)<unreadable content: not utf-8>— file is not valid UTF-8<unreadable content>— file cannot be read (permission denied, I/O error)
Development
pip install -e ".[dev]"
pytest
pre-commit run --all-files
Testing
Integration tests only - test against real filesystem. No mocking.
Architecture
src/treemapper/
├── cli.py # argument parsing
├── ignore.py # gitignore/treemapperignore handling
├── tree.py # directory traversal
├── writer.py # YAML/JSON/text output
└── treemapper.py # main entry point
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file treemapper-1.1.3.tar.gz.
File metadata
- Download URL: treemapper-1.1.3.tar.gz
- Upload date:
- Size: 42.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
753bb8ed3d8b2f540386cf8172cd0b0e5ebd50368cbb00431477d81fae1471d6
|
|
| MD5 |
dc7f3482fa7ba1c6cbe383da713473d1
|
|
| BLAKE2b-256 |
06e78d628b69f06463036490ce5e8987b08e077bca7490e5a53adf397e730caf
|
Provenance
The following attestation bundles were made for treemapper-1.1.3.tar.gz:
Publisher:
cd.yml on nikolay-e/treemapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treemapper-1.1.3.tar.gz -
Subject digest:
753bb8ed3d8b2f540386cf8172cd0b0e5ebd50368cbb00431477d81fae1471d6 - Sigstore transparency entry: 780710307
- Sigstore integration time:
-
Permalink:
nikolay-e/treemapper@df94a54dd91bb3ad6e2c90f7ac8c58319ddf8b3d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nikolay-e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@df94a54dd91bb3ad6e2c90f7ac8c58319ddf8b3d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treemapper-1.1.3-py3-none-any.whl.
File metadata
- Download URL: treemapper-1.1.3-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4ca24039b6d715572c7b1305d6462030994a6ed4e6e211225fe48c49bfa3c4a
|
|
| MD5 |
43dce34c2910e8e67b0c48fbdf683114
|
|
| BLAKE2b-256 |
67789854efe93c0e935c4e88968e2983c953295a9942c1025191d51ccb0bd6df
|
Provenance
The following attestation bundles were made for treemapper-1.1.3-py3-none-any.whl:
Publisher:
cd.yml on nikolay-e/treemapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treemapper-1.1.3-py3-none-any.whl -
Subject digest:
b4ca24039b6d715572c7b1305d6462030994a6ed4e6e211225fe48c49bfa3c4a - Sigstore transparency entry: 780710308
- Sigstore integration time:
-
Permalink:
nikolay-e/treemapper@df94a54dd91bb3ad6e2c90f7ac8c58319ddf8b3d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nikolay-e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@df94a54dd91bb3ad6e2c90f7ac8c58319ddf8b3d -
Trigger Event:
workflow_dispatch
-
Statement type: