Skip to main content

Generate focused, token-efficient LLM context files from your project.

Project description

cxtree

PyPI Python Tests License

Generate focused, token-efficient LLM context files from your project.

cxtree walks a project directory, assembles source files into Markdown code blocks and writes context.md — ready to paste into any LLM chat. When the project is large it automatically splits into per-folder files.

DEMO


Why

Pasting code into an LLM and hoping for the best is not a workflow. Deciding what the LLM sees — and why — forces a clarity that makes every conversation more precise and every answer more useful. cxtree makes that decision explicit: one command generates the context, then abstract-leaf.yaml files let you progressively annotate your project until the view reflects exactly what matters for the task at hand. It takes some upfront effort. Navigating a codebase together with an LLM, with full control over its view, is worth it.


Installation

pip install cxtree
# or
uv add cxtree

Requires Python 3.11+.


Quick start

cd my-project
cxtree create     # writes context.md
                  # paste it into your LLM

Commands

cxtree tree

Print a coloured directory tree with line-budget percentages.

cxtree tree [-n N]
Option Default Description
-n / --max-lines 3000 Line budget used to colour percentage labels

Colours: green ≤ 80 %, yellow ≤ 90 %, red ≤ 100 %, magenta > 100 %.

If abstract-tree.yaml exists its include_extensions / exclude_folders settings are applied to the tree.


cxtree create

Generate context.md from the current directory.

cxtree create [-n N] [--code | --complete] [-f]
Option Default Description
-n / --max-lines 3000 (or saved value) Max lines per context.md before splitting
--complete default Verbatim file content
--code Strip docstrings; apply # CX markers
-f / --folder Store files in .context-tree/ with rotation

What it writes:

  • context.md — at the project root (or .context-tree/context.md in folder mode)
  • _context.md — in each overflowed sub-directory (normal mode)
  • abstract-tree.yaml — project structure + saved config
  • abstract-leaf.yaml — per-directory key/value index (see below)

Overflow / splitting:

When the total line count exceeds -n, create splits by immediate sub-directories: each sub-directory gets its own _context.md (recursing as needed). The root context.md contains only root-level files plus references to the sub-contexts. Overflowed directories appear as _context.md in abstract-tree.yaml.

-n is remembered:

The first time you pass -n 500, the value is saved in abstract-tree.yaml. Subsequent cxtree create calls without -n reuse the saved value.


cxtree rm

Remove all cxtree-generated artefacts.

cxtree rm

Always removed: .context-tree/, abstract-tree.yaml, all context.md files.

Conditionally kept: abstract-leaf.yaml files that contain user-written summaries (any value other than false) are preserved so that documentation committed to the repository is not lost.


Render modes

--complete (default)

File content is copied verbatim into the code block.

--code

Docstrings are stripped from Python files. A docstring is kept when its body contains the marker # cxtree (or #cxtree).

def deploy():
    """
    Deploy to production.
    # cxtree  <- marker: keep this docstring
    """
    ...

Inline markers (work in both modes):

Marker Effect
# CX or # cxtree Remove this line from the output
# CX -N or # cxtree -N Remove the next N lines; insert # ...
SECRET_KEY = "abc123"  # CX

# cxtree -3
token = header[7:]
sig   = hmac.new(SECRET_KEY, token)
valid = sig == expected

abstract-tree.yaml

Auto-generated at the project root. Contains a config header and a flat tree of the project.

cxtree:
  n: 3000
  include_extensions: [py, ts]
  exclude_startswith: [".", "__"]
  exclude_folders: [.venv, node_modules, __pycache__, .git, .context-tree]

_root:
  - main.py
  - pyproject.toml

src:
  - utils.py
  - models.py

src/api:
  - routes.py

domain: _context.md     # overflow: _context.md was created here
workers: _context.md

Edit include_extensions and exclude_folders to control which files are included on subsequent runs. Everything else is informational.


abstract-leaf.yaml

Created alongside each context.md. Keys are the immediate files and sub-directories; values start as false.

# src/abstract-leaf.yaml
utils.py: false
models.py: false
api/: false

Adding summaries:

Change a value from false to a string. On the next cxtree create run, the summary replaces the actual file content — useful for reducing noise from large or irrelevant modules.

utils.py: "String helpers  no LLM context needed."
models.py: false
api/: false

Summaries are picked up at every level:

Sub-directory abstract-leaf.yaml files are always merged into the parent context. If domain/abstract-leaf.yaml marks users/: "User management", that summary will appear in the root context.md regardless of overflow.

Formatting is preserved:

cxtree create never rewrites existing entries. New keys for newly added files are appended to the end of the file. Commit abstract-leaf.yaml to the repository as lightweight per-directory documentation.


Folder mode (-f)

cxtree create -f

All context files are stored inside .context-tree/ instead of scattered across the project tree.

  • .context-tree/.gitignore is created automatically.
  • On each run, previous context files are rotated to .context-tree/bin/<timestamp>/.
  • Bin folders older than 2 hours are deleted automatically.
  • Once .context-tree/ exists, folder mode is auto-activated on subsequent runs.

Example workflow

cxtree create -n 2000        # first run — sets and saves budget
cxtree tree -n 2000          # explore with percentages

# annotate heavy directories in abstract-leaf.yaml, then:
cxtree create                # n=2000 is reused

cxtree rm                    # clean up (keeps leaf files with summaries)
cxtree create                # summaries are picked up automatically

License

MIT

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

cxtree-1.0.1.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

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

cxtree-1.0.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file cxtree-1.0.1.tar.gz.

File metadata

  • Download URL: cxtree-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cxtree-1.0.1.tar.gz
Algorithm Hash digest
SHA256 402c71b2d1a5fefbcb5f4fde800f130a9b9a7fcc64614e5526c895c8ccc276ce
MD5 63425bc05254ac2269e7a202e265391e
BLAKE2b-256 146b4aac9744e1435d730d351578d278abdbee6fd26a4b2d1a644f16481ea645

See more details on using hashes here.

File details

Details for the file cxtree-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: cxtree-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cxtree-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9828612fee5d41e520b467049a3d0bc266caa39c2ce98363eb69fbc8a1409c3
MD5 957544e6c563cb8977afeb43c94daea2
BLAKE2b-256 defffe639092e21b812f6aaf420c84f7e7b160d5c13ed8c793c52eafd44eb3b2

See more details on using hashes here.

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