Skip to main content

Pack a codebase into one LLM-ready Markdown file with a file tree and token estimate. Zero dependencies, no server.

Project description

ctxstash

Pack a codebase into one LLM-ready Markdown file — with a file tree and a token estimate. Zero dependencies, no server, no telemetry.

You're feeding code to ChatGPT / Claude / Cursor and you keep doing the same dance: open file, copy, paste, label it, repeat — then guess whether it'll blow the context window. ctxstash does it in one command: walk a directory, skip the junk (.venv, __pycache__, lockfiles, binaries), and emit a single tidy Markdown document with every file fenced and language-tagged, prefixed by a tree overview and an approximate token count.

ctxstash src > context.md
✓ packed 23 files · 142.3 KB · ~38,210 tokens

This is the Python build. There's a matching, behavior-identical Node version: npx ctxstash.

Install

pip install ctxstash

Requires Python ≥ 3.8. No dependencies. (You can also run it without installing the script: python -m ctxstash .)

Usage

ctxstash [paths...] [options]
ctxstash .                          # pack the current dir to stdout
ctxstash src tests > context.md     # pack two dirs, redirect to a file
ctxstash . -o context.md            # ...or write the file directly
ctxstash . -i "*.py,*.pyi"          # only Python
ctxstash . -e "*_test.py"           # drop tests
ctxstash . --estimate               # just tell me the token cost
ctxstash src --tree                 # just the file tree

Options

Option Description
-o, --out <file> Write to a file instead of stdout
-i, --include <globs> Only include matching files (comma-separated, e.g. "*.py,*.pyi")
-e, --exclude <globs> Exclude matching files (comma-separated)
--tree Print only the file tree (no contents)
--no-tree Omit the file-tree overview from the packed output
--estimate Print only stats (files, size, ~tokens) — pack nothing
--max-size <size> Skip files larger than this (e.g. 256kb, 1mb; default: no limit)
--no-default-ignore Don't auto-skip node_modules / .git / dist / lockfiles / etc.
--no-color Disable colored stderr
-h, --help · -v, --version

Globs support * (within a path segment), ** (across segments), and ?. A slash-less pattern like *.py matches at any depth.

What you get

# Repository context

> Packed by ctxstash — 3 files, 4.1 KB, ~1,040 tokens (estimate).

## File tree

​```
src/
  core.py
  cli.py
README.md
​```

## Files

### src/core.py

​```python
...file contents...
​```

The summary line always goes to stderr, so ctxstash > context.md keeps the file clean while you still see the count in your terminal.

Notes & limits

  • Binary files are skipped automatically (NUL-byte / control-byte sniff), so images and compiled artifacts never end up in your context.
  • Token counts are an estimate (~4 characters per token, OpenAI's rule of thumb) — tokenizer-agnostic and good enough for "will this fit?", not exact billing. For precise counts, run the output through a real tokenizer.
  • Fences are collision-safe: if a file contains a ``` run, ctxstash wraps it in a longer fence so the Markdown stays valid.
  • Symlinks are not followed (avoids loops).

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

ctxstash-0.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

ctxstash-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file ctxstash-0.1.0.tar.gz.

File metadata

  • Download URL: ctxstash-0.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for ctxstash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e90af08c686903fd686aa84e3d399c98a733275ad2e5ce0b2505d41d0beb325
MD5 a37088df528bd22a4a38207bce1671bf
BLAKE2b-256 1299e9b7c2c57c9c59a23681751f6b07cb8c27d92123fd8ccb982bbf4771162d

See more details on using hashes here.

File details

Details for the file ctxstash-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ctxstash-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for ctxstash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab26dde0704e81dce032e78963aa6b1aabb01b294953a894036115b6f4ad6a9f
MD5 d5213399cd102bfc575d209e2c8b57f6
BLAKE2b-256 cb54d52ac4ce1fde224be73576769e6939795028eeb9d97bad888a6532b0e05c

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