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.2.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.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cxtree-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9e9e5402e2e65ab20c65fec601f6e42afa068ac8866851969955c767cc984e55
MD5 6a35f4e726ef8e39d83b8f56f7b02916
BLAKE2b-256 188e19cec77a744f1318b0e714d897fa5b3a99d291a3505bb4330484eb83c2ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cxtree-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 70b950f993752b008da0619a12bc310e912c6a1a67aa86d781ec5825e76e2fe2
MD5 15dd704c36e67587e1389b42f1514515
BLAKE2b-256 b9b00cfb36f93865652e543b211487b4c17cab90ba08b87de28d46feef324d4f

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