ctx
Package a repository into a single, LLM-ready context file.
ctx walks a directory and emits one markdown file containing an ASCII tree of
the repo, the contents of every source file (fenced with language hints), and a
token estimate — so you can paste a whole repository into an LLM prompt, or
point an agent at it, and the model sees structure and code together.
What it looks like
Running ctx on this repo (tree trimmed for the README; the header counts are real):
# repo — context
- files: **26** · **68860 bytes** · ~**20208 tokens**
## Tree
```text
├── .github/
│ ├── workflows/
│ │ ├── ci.yml
│ │ └── release.yml
│ └── FUNDING.yml
├── src/
│ └── ctx/
│ ├── __init__.py
│ ├── __main__.py
│ ├── ...
│ └── walker.py
├── tests/
│ ├── conftest.py
│ ├── test_cli.py
│ ├── test_ignore.py
│ ├── test_render.py
│ ├── test_tokens.py
│ └── test_walker.py
├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── pyproject.toml
└── README.md
```
Features
- One file out. Directory tree, file contents, and a token estimate in a single markdown document — ready to paste into a prompt.
- Gitignore-aware. Follows
.gitignore(and.ctxignore) at every level of the tree, with git's semantics: deeper rule files win. - Binary-safe. Binary files are detected and listed, but their content is omitted instead of corrupting the document.
- Token-aware.
--max-tokensstops early once the running estimate crosses the limit, so the output fits your context window. - Filterable.
--include/--excludewith repeatable pathspec globs, and--max-sizeto skip files that are too big. - Offline and light. The only runtime dependency is
pathspec.
Install
Requires Python 3.10+. The package is published on PyPI as repocxt; the
command you run is ctx.
pipx install repocxt
Or install from a checkout directly:
pipx install .
Or with plain pip:
pip install repocxt
However you install it, you get a ctx command (it also runs as
python -m ctx).
Usage
usage: ctx [-h] [-o FILE] [--include GLOB] [--exclude GLOB] [--max-size BYTES]
[--max-tokens N] [--no-tree] [--json] [--version]
[root]
root— directory to pack. Defaults to the current directory. The header uses the directory's name (orrepowhen the name is empty, e.g..).-o FILE, --output FILE— write to a file. Defaults toctx.mdin the current directory;-o -means stdout explicitly.--include GLOB/--exclude GLOB— keep or drop paths matching a glob (repeatable; pathspec syntax). Both are applied after ignore filtering, and--excludewins over--include.--max-size BYTES— skip files larger than this many bytes.--max-tokens N— stop once the emitted text reaches N tokens.--no-tree— omit the ASCII tree section; just the files.--json— print a machine-readable summary (file list, counts, bytes, tokens) instead of the document.
With LLMs
The output is self-contained, so driving an LLM is two steps:
# writes ctx.md in the current directory by default
ctx
# or just paste stdout straight into the prompt
ctx -o - | head -c 20000
Point the model at ctx.md ("this is my whole repo, read it") or paste it
directly — the tree tells it the layout, the fenced blocks give it the code,
and the token estimate tells you whether it fits.
How it decides what to include
- Gitignore semantics.
.gitignorefiles are read at every directory and applied to relative paths; a deeper.gitignore's decision wins over a shallower one's, and later lines override earlier ones. A private.ctxignorefile is honored the same way, for rules you do not want to commit to git. - Always-skipped directories.
.git,.svn,.hg,.ctx,__pycache__, and.mypy_cacheare always skipped. - Binary omission. A file is treated as binary when its first 8 KB contain a NUL byte — images, archives, compiled objects. It is still listed in the document, but with a note instead of content.
- Files, not directories. Only regular files are packed; empty directories and directory symlinks do not appear in the tree.
Philosophy
Offline-first. There is no telemetry, no network call, and no tokenizer — token
counts come from a small local heuristic that errs high, which is the safe
direction for context budgeting. The dependency list stays minimal
(pathspec is the only runtime dependency) and the output is plain markdown
you can read, diff, and paste anywhere.
Development
git clone <your fork>/ctx
cd ctx
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
- Run tests:
python -m pytest - Lint:
python -m ruff check .(config and dev extras live inpyproject.toml)
No need to install to poke at the CLI:
export PYTHONPATH="$PWD/src"
python3 -m ctx --help
Testing & compatibility
Honest status of what is and isn't verified:
- Tested on: Linux, Python 3.12 — 106 automated tests pass (
pytest),ruffclean, wheel + sdist build clean,twine checkpasses. Edge cases covered by tests: nested/overriding.gitignore, negation, directory-only patterns, filenames with spaces, undecodable and binary files, oversized files, symlinks (not followed for dirs), backtick-fences inside file bodies, and--max-tokens/--jsonbehavior. - Expected but not yet verified: macOS and Windows, and Python 3.10–3.11.
The code is pure Python +
pathspecwith no OS-specific calls, so it should run anywhere, but only Linux/3.12 has been exercised. The GitHub Actions matrix (ci.yml) runs 3.10–3.12 on Linux for every push; wider platform testing is welcome via PRs / CI runs. - Not verified at all: any real PyPI publication (needs a maintainer token).
If you hit a platform you use that isn't green, open an issue with your OS, Python version, and the error — that's the fastest way this list gets shorter.
License
MIT © 2026 Kamran
Metadata
Release files for repocxt 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| repocxt-0.1.1.tar.gz | 24.3 kB | With provenance | Details for repocxt-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| repocxt-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for repocxt-0.1.1-py3-none-any.whl |
Total release size: 39.8 kB
Release files / repocxt-0.1.1.tar.gz
| Download URL | repocxt-0.1.1.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b658b18e7aff5244d9c9980f5eb9e695927b6fbc49c4c2bd1061450b84e5f9cc
|
|
BLAKE2b-256 checksum How to use checksums |
69bafc7c0be68ffd229a2d4695c95e0765742cf5cc6bbb319a74bd0e560d161d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / repocxt-0.1.1-py3-none-any.whl
| Download URL | repocxt-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8748675538e35c7039ba0db4d16648a7c89f7b954d5c388364d140b591c0362f
|
|
BLAKE2b-256 checksum How to use checksums |
aec9b9e24f807a2a6603b48a508d03afababd631f5183a3c83e5fe3d14538290
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for repocxt 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for repocxt-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.