Skip to main content

Map a codebase to YAML/JSON/Markdown/text and select smart git-diff context for LLMs

Project description

TreeMapper

PyPI License

Map a codebase into LLM-ready context. TreeMapper serializes an entire directory tree — structure plus file contents — to YAML, JSON, Markdown, or text, and selects the minimal smart git-diff context needed to understand a change. Paste the output into Claude, ChatGPT, or any LLM.

TreeMapper is a thin command-line product built on the diffctx engine. All traversal, serialization, and diff-context selection live in diffctx; TreeMapper re-exposes them under the treemapper name so there is a single source of truth and no duplicated logic.

Installation

pipx install treemapper                  # recommended: isolated, no venv needed
pip install treemapper                   # or with pip
pip install 'treemapper[tree-sitter]'    # + AST parsing for smarter diff context
pip install 'treemapper[mcp]'            # + MCP server for AI assistants

Usage

treemapper .                     # map current directory to YAML (stdout)
treemapper /path/to/project      # map a specific directory
treemapper . -f json             # output as JSON
treemapper . -f md --save        # save as tree.md
treemapper . --no-content        # structure only, no file contents
treemapper . -c                  # copy output to clipboard
treemapper . --diff HEAD~1       # smart context for the last commit
treemapper . --diff main..HEAD   # smart context for a branch range
treemapper graph .               # project dependency graph (mermaid)

Two modes

  • Tree mapping (treemapper .) — walks the directory tree, respects hierarchical ignore patterns (.gitignore, .diffctx/ignore), reads file contents with binary/encoding detection, and serializes the result.
  • Diff context (treemapper . --diff) — analyzes a git diff and selects the minimal set of code fragments needed to understand the change, instead of dumping whole files.

Run treemapper --help for the full flag reference.

Python API

import treemapper

tree = treemapper.map_directory(".", no_content=False)
print(treemapper.to_yaml(tree))

context = treemapper.build_diff_context(root_dir=".", diff_range="HEAD~1")

# treemapper.run drives the full branded CLI from Python (same surface as the command)
treemapper.run(["graph", "."], prog="treemapper", version=treemapper.__version__)

Every run reports an exact tiktoken token count (not a chars / 4 estimate), so you know the real context cost before you paste.

Relationship to diffctx

TreeMapper is the user-facing distribution; diffctx is the reusable engine. Pin compatibility is diffctx>=1.10.1,<2.0. If you are embedding the engine in your own tool, depend on diffctx directly.

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treemapper-2.3.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

treemapper-2.3.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file treemapper-2.3.0.tar.gz.

File metadata

  • Download URL: treemapper-2.3.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for treemapper-2.3.0.tar.gz
Algorithm Hash digest
SHA256 cb8c49a56523cd74c3974b23aa4ee860e30ece7117d5cc1781bdd85ceab81f23
MD5 d0e92513360fcd6946d38c1014307870
BLAKE2b-256 525afb39642517983bd79cd84dcd68bce9cebc280ce11da7dc6a9cbe26114e51

See more details on using hashes here.

Provenance

The following attestation bundles were made for treemapper-2.3.0.tar.gz:

Publisher: cd.yml on nikolay-e/treemapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file treemapper-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: treemapper-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for treemapper-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e62b3b3a3d1135643a9334f0982c4b3aba419b378ad2381efa7b720c00e3c82
MD5 10a3da575eb03009f120f460525a2fba
BLAKE2b-256 57d292a58a423062f6ed5e069291aa2ad713120911740ee90b66529f844d80de

See more details on using hashes here.

Provenance

The following attestation bundles were made for treemapper-2.3.0-py3-none-any.whl:

Publisher: cd.yml on nikolay-e/treemapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page