Skip to main content

Aggregate codebase files into a single context file for LLM consumption.

Project description

Context Engine CLI

Bridge the gap between massive local codebases and Large Language Models (LLMs). Context Engine CLI turns a repository into a clean, single-file context bundle that is easier to inspect, share, and paste into AI tools.

✨ Features

  • Deterministic LLM-ready context that preserves the original file traversal order, even while reading files concurrently.
  • Clean single-file output with a directory tree and clearly separated file sections for easy LLM parsing.
  • Fast directory traversal with os.scandir, avoiding slower recursive path walking.
  • Memory-safe output streaming that writes directly to disk instead of building one huge string in RAM.
  • Concurrent file reading with ThreadPoolExecutor for faster aggregation on large repositories.
  • .gitignore and .contextignore support for project-specific filtering.
  • Precompiled ignore rules using fnmatch.translate and re.Pattern for faster repeated matching.
  • Default binary and build-artifact exclusions for files such as .png, .exe, .pdf, .pyc, node_modules, __pycache__, and .git.
  • Token estimation using the practical rule of thumb 1 token ≈ 4 characters.
  • Token budget control with --max-tokens to stop before the output exceeds an LLM context window.
  • Clean terminal UX with scan feedback, warnings for skipped files, and a final processing summary.

📦 Installation

Install from PyPI:

pip install context-engine-zain333

After installation, the context-engine command is available from your terminal:

context-engine --help

On Windows, if the command is not recognized after installation, make sure your Python Scripts directory is on PATH.

🚀 Usage

Generate a clean context file for a local project:

context-engine ./my-project

By default, this creates:

codebase_context.txt

Write to a custom output file:

context-engine ./my-project --output project_context.txt

Ignore additional file extensions:

context-engine ./my-project --ignore .csv,.sqlite,.bak

Limit the estimated token budget:

context-engine ./my-project --max-tokens 100000

Combine options for larger repositories:

context-engine ./my-project \
  --output llm_context.txt \
  --ignore .png,.jpg,.sqlite \
  --max-tokens 100000

🧠 Why This Exists

LLMs work best when they receive structured, relevant context. Real repositories, however, are messy: they include dependency folders, caches, binaries, build output, generated files, and enough source code to overwhelm both memory and context windows.

Context Engine CLI creates a clean, LLM-friendly snapshot of a codebase by:

  • rendering the directory tree,
  • appending readable source files with clear file headers,
  • skipping binary or unreadable files gracefully,
  • respecting ignore rules,
  • estimating final token usage,
  • and streaming output safely to disk.

The result is a single text file that an LLM can parse without requiring you to manually copy files, prune noise, or guess whether the final context will fit.

🧾 Output Format

Each generated file starts with a directory tree, followed by clearly separated file sections:

CODEBASE CONTEXT
================================================================================
Directory Tree
================================================================================
my-project
|-- context_engine
|   `-- main.py
`-- pyproject.toml

================================================================================
File: context_engine/main.py
================================================================================
[FILE CONTENT HERE]

🙈 Ignore Rules

Context Engine CLI reads ignore patterns once at startup from:

  • built-in defaults,
  • .gitignore,
  • .contextignore,
  • and the optional --ignore argument.

Use .contextignore for LLM-specific exclusions without changing your Git behavior:

docs/archive/
*.snapshot
large-fixtures/

Negated ignore rules such as !important.py are currently skipped.

⚙️ CLI Reference

context-engine TARGET_DIR [-o OUTPUT] [-i EXTENSIONS] [--max-tokens N]

Arguments:

  • TARGET_DIR: Directory to scan.
  • -o, --output: Output file name. Defaults to codebase_context.txt.
  • -i, --ignore: Additional comma-separated file extensions to ignore.
  • --max-tokens: Maximum estimated tokens to write before stopping.

🛠 Development

Install locally in editable mode:

python -m pip install -e .

Run the CLI from source:

python -m context_engine.main ./my-project

Run a syntax check:

python -m compileall context_engine

Generate the local stress-test fixture:

python test_generator.py
context-engine test_env -o test_env_context.txt

📄 Package Metadata

  • Package name: context-engine-zain333
  • Python package: context_engine
  • Entry point: context-engine = context_engine.main:main
  • Python version: >=3.10
  • Runtime dependencies: none beyond the Python standard library

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

context_engine_zain333-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

context_engine_zain333-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file context_engine_zain333-0.1.1.tar.gz.

File metadata

  • Download URL: context_engine_zain333-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for context_engine_zain333-0.1.1.tar.gz
Algorithm Hash digest
SHA256 18799f28d53ee82278f0a8fca7537484d8cefb1da516ea673ad473ec2d22517f
MD5 743a8191327c30608467eb8791c3c715
BLAKE2b-256 3173c7b94b5ac73cfe953186652073f55bb5c9096a42c6c019a37236a575d8de

See more details on using hashes here.

File details

Details for the file context_engine_zain333-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for context_engine_zain333-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f8496ed89fe47c80bd8c6d0de3c48e99559d120b32a9c4576874e5bebfc07fb
MD5 6d850f2256b4a60971cc55ea56f93b5f
BLAKE2b-256 413f919074c5105427f5724651424d2a60140c371dd73f581319a2067ecff190

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