Skip to main content

Intelligently pack project context for LLMs, respecting .gitignore, skipping noise, and counting tokens.

Project description

lmpack ๐Ÿ“ฆโœจ

Effortlessly pack your project context for Large Language Models (LLMs) with intelligence and sensible defaults.

PyPI version

Tired of manually curating files for your LLM prompts? lmpack intelligently packs your project to a single markdown file, handling the noise so you don't have to. Just pip install lmpack and run!

What makes lmpack different?

  • ๐Ÿง  Git Aware: Auto-detects .gitignore even when run from subdirectories. Labels files using git paths, or simple relative paths if not in a repo.
  • ๐Ÿคซ Smart Defaults: Ignores common clutter (.git, node_modules, etc.) and skips content of images/binaries out-of-the-box.
  • ๐Ÿค– LLM Ignore Files: Automatically detects .aiignore, .aiexclude, .cursorignore, to skip content, but keeping them in the directory tree structure.
  • ๐Ÿ“Š Granular Token Counting (Optional): See exactly which parts of your project are token-heavy! Uses tiktoken (cl100k_base default) for accurate estimates. Provides both a detailed tree view and a total count.
  • โœจ Rich & Plain Tree Output: Visualize your project structure using a beautiful Rich-powered tree in your terminal or a plain text version for files.
  • ๐Ÿ›ก๏ธ Safe Output: Uses .lmpack.md to prevent self-inclusion issues.

See it in action: ๐Ÿ‘‡


Scenario 1: Running from a Subdirectory

No need to be in the root, lmpack finds your project's .gitignore.

Project:

my-repo/
โ”œโ”€โ”€ .git/
โ”œโ”€โ”€ .gitignore  <-- Contains "logs/" (Auto-detected)
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ helpers.py  <-- You are here
โ”œโ”€โ”€ logs/         <-- Will be ignored

Command:

# You are in my-repo/src/utils
lmpack

Result: lmpack detects .git and uses ../../.gitignore automatically. logs/ is correctly excluded. The file paths will be constructed relative to your repository root. โœ…


Scenario 2: Handling Noise & LLM-Specific Ignores

Defaults + LLM ignore files work together seamlessly.

Project:

another-project/
โ”œโ”€โ”€ .git/            <-- Ignored by default
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .aiexclude       <-- Contains "data/*.csv" (Auto-detected)
โ”œโ”€โ”€ node_modules/    <-- Ignored by default
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ data/
โ”‚       โ””โ”€โ”€ huge_dataset.csv <-- Ignored via .aiexclude
โ”œโ”€โ”€ images/
โ”‚   โ””โ”€โ”€ logo.png      <-- Content skipped by default
โ””โ”€โ”€ package-lock.json <-- Content skipped by default

Command:

# You are in another-project/
lmpack

Result: .git, node_modules, the CSV file, and the content of the lockfile/image are all correctly handled without extra flags. โœ…


Scenario 3: Pinpointing Token Usage

Identify token hotspots easily.

Command:

cd my-project/
pip install lmpack[tiktoken]
lmpack --count-tokens

Output (Terminal Tree):

๐Ÿ“‚ my-project (15,820 tokens)
โ”ฃโ”โ” ๐Ÿ“‚ app (12,105 tokens)  <-- High usage here!
โ”ƒ   โ”ฃโ”โ” ๐Ÿ main.py (5,300 tokens)
โ”ƒ   โ”—โ”โ” ...
โ”ฃโ”โ” ๐Ÿ“‚ tests (3,500 tokens)
โ”—โ”โ” ...

Result: The token-annotated tree immediately highlights that the app/ directory is the major token consumer. โœ…


Installation ๐Ÿš€

If you want token counting capabilities (recommended), install with the tiktoken extra:

pip install lmpack[tiktoken]

Quick Start โšก

Navigate to a folder you want to send to your LLM and simply run:

lmpack

This will create a yourproject_context.lmpack.md file in the current directory, containing your project's source tree and relevant file contents.

To include token counting:

lmpack --count-tokens

This will print a token-annotated tree to your terminal and generate the context file.

Usage & Options โš™๏ธ

Usage: lmpack [OPTIONS] [INDEX_PATH]

  Generates a single text file containing the content of files within a
  directory or git repository, respecting ignore rules, formatting each file,
  and optionally counting tokens.

Arguments:
  [INDEX_PATH]  Path to folder to index. [default: .]

Options:
  -o, --output DIRECTORY          Directory for the main context file. [default: .]
  --output-name TEXT              Template for the main context file name. Use
                                  {repo_name}, {index_path}, {rel_index_path}
                                  placeholders. [default: {repo_name}_context.lmpack.md]
  --repo-root DIRECTORY           Path to the git root that contains the index
                                  path, detected if not provided.
  -i, --include TEXT              Include only files matching the given comma
                                  seperated pattern(s). Supports fnmatch globbing.
  -e, --exclude TEXT              Exclude files matching the given comma
                                  seperated pattern(s). Supports fnmatch globbing.
  -g, --gitignore TEXT            .gitignore/.aiexclude/.aiignore type files to
                                  use. Comma separated list of file paths.
  --count-tokens                  Enable token counting (requires tiktoken).
  --encoding TEXT                 Tiktoken encoding (e.g., cl100k_base). [default: cl100k_base]
  --tree-format [rich|plain|none] Format for the directory tree output. [default: rich]
  --tree-output FILE              Optional file path to write the plain text tree.
  -v, --verbose                   Enable verbose output.
  --help                          Show this message and exit.

Key Options:

  • --include, --exclude: Use standard glob patterns (like .gitignore) to fine-tune included/excluded files beyond the defaults.
  • --count-tokens: Enable token counting.
  • --tree-format: Choose how (or if) the directory tree is displayed (rich default for terminals, plain, none).
  • --tree-output: Save the plain text tree to a separate file.

Ignoring Files

lmpack uses multiple layers for ignoring files:

  1. Default Ignores: Built-in patterns for common directories/files (see code for full list).
  2. Detected .gitignore / .dockerignore: Automatically found in the INDEX_PATH and the detected Git root.
  3. User-Provided --gitignore Files: Specify additional ignore files.
  4. User-Provided --exclude Patterns: Add specific command-line exclusion patterns.
  5. Content Ignores: Files whose content should be skipped (default list includes lockfiles, images, etc.). Can be extended by creating .aiignore or .cursorignore files (similar syntax to .gitignore).

Contributing ๐Ÿ™

Contributions are welcome and greatly appreciated! lmpack aims to be a community-driven tool, and your help can make it even better.

Whether it's reporting a bug, suggesting a feature, improving documentation, or submitting code, your input is valuable.

Ways to Contribute:

  • ๐Ÿ› Report Bugs: If you find a bug, please open an issue on GitHub detailing the problem, your environment, and steps to reproduce it.
  • ๐Ÿ’ก Suggest Features: Have an idea for a new feature or improvement? Open an issue to discuss it first.
  • ๐Ÿ“– Improve Documentation: Found a typo or think something could be clearer? Feel free to open an issue or submit a PR with improvements.
  • ๐Ÿ’ป Submit Pull Requests: For code contributions, please follow these general steps:
    1. Fork the repository.
    2. Create a new branch for your feature or bug fix (e.g., feature/add-cool-thing or fix/resolve-that-bug).
    3. Make your changes. Try to follow the existing code style.
    4. Add tests for any new functionality or bug fixes.
    5. Ensure existing tests pass.
    6. Open a Pull Request (PR) against the main branch, clearly describing your changes.

Development Setup:

This project uses Poetry for dependency management and packaging.

  1. Clone the repository:
    git clone https://github.com/ionite34/lmpack.git
    cd lmpack
    
  2. Install dependencies (including development tools and extras like tiktoken):
    poetry install --all-extras
    

We aim for a positive and respectful contribution environment. Please adhere to standard open-source etiquette โค๏ธ

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

lmpack-1.3.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

lmpack-1.3.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file lmpack-1.3.0.tar.gz.

File metadata

  • Download URL: lmpack-1.3.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lmpack-1.3.0.tar.gz
Algorithm Hash digest
SHA256 79bd78b9ade3bbefacb575b71229ca8883b1e910b26b18be6ec7652799571440
MD5 929e7614c3493bb316c332f3db1b21ad
BLAKE2b-256 086ec4e093871325f53fabd6b4c9435f47084f75b2d7ce0b03a4f1bd10e2f313

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmpack-1.3.0.tar.gz:

Publisher: publish.yml on ionite34/lmpack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lmpack-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: lmpack-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lmpack-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1627c0135ae153545e8fbf6aca4bb8ed23165d4b3aafe9f6cc01795788535393
MD5 1ccf9bb0b4c383c8ebced9af1d82b483
BLAKE2b-256 eab7c3a214d48cf10c9960840d2e1a2948df6adb7c7eb8efbb5cddf3680647eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmpack-1.3.0-py3-none-any.whl:

Publisher: publish.yml on ionite34/lmpack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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