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.
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
.gitignoreeven 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_basedefault) 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.mdto 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 (richdefault for terminals,plain,none).--tree-output: Save the plain text tree to a separate file.
Ignoring Files
lmpack uses multiple layers for ignoring files:
- Default Ignores: Built-in patterns for common directories/files (see code for full list).
- Detected
.gitignore/.dockerignore: Automatically found in theINDEX_PATHand the detected Git root. - User-Provided
--gitignoreFiles: Specify additional ignore files. - User-Provided
--excludePatterns: Add specific command-line exclusion patterns. - Content Ignores: Files whose content should be skipped (default list includes lockfiles, images, etc.). Can be extended by creating
.aiignoreor.cursorignorefiles (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:
- Fork the repository.
- Create a new branch for your feature or bug fix (e.g.,
feature/add-cool-thingorfix/resolve-that-bug). - Make your changes. Try to follow the existing code style.
- Add tests for any new functionality or bug fixes.
- Ensure existing tests pass.
- Open a Pull Request (PR) against the
mainbranch, clearly describing your changes.
Development Setup:
This project uses Poetry for dependency management and packaging.
- Clone the repository:
git clone https://github.com/ionite34/lmpack.git cd lmpack
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lmpack-1.2.0.tar.gz.
File metadata
- Download URL: lmpack-1.2.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61eea35aa6d92fc20751b83cfba6fb46d923dd8d949b742d879d742d453f86fa
|
|
| MD5 |
ace2406b70f82837c7994471783f550b
|
|
| BLAKE2b-256 |
f407a537361a618449bfa9b808d0304653aa6bb48cac2f68294343f7026ae062
|
Provenance
The following attestation bundles were made for lmpack-1.2.0.tar.gz:
Publisher:
publish.yml on ionite34/lmpack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmpack-1.2.0.tar.gz -
Subject digest:
61eea35aa6d92fc20751b83cfba6fb46d923dd8d949b742d879d742d453f86fa - Sigstore transparency entry: 199552406
- Sigstore integration time:
-
Permalink:
ionite34/lmpack@103571f1ca0b4795bae34334e0434a67aba9bf7e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ionite34
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@103571f1ca0b4795bae34334e0434a67aba9bf7e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file lmpack-1.2.0-py3-none-any.whl.
File metadata
- Download URL: lmpack-1.2.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8e17a7ffdfadc86d847ae78d2c6a742bbb6433ead2a073de53e076274d2cbd0
|
|
| MD5 |
7d7d760642a337e0cbd21de3a3c257e3
|
|
| BLAKE2b-256 |
165a23772ebbecf6626d9b4402992dba230c6184da32faf5f17f202622ff3b7a
|
Provenance
The following attestation bundles were made for lmpack-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on ionite34/lmpack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmpack-1.2.0-py3-none-any.whl -
Subject digest:
f8e17a7ffdfadc86d847ae78d2c6a742bbb6433ead2a073de53e076274d2cbd0 - Sigstore transparency entry: 199552409
- Sigstore integration time:
-
Permalink:
ionite34/lmpack@103571f1ca0b4795bae34334e0434a67aba9bf7e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ionite34
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@103571f1ca0b4795bae34334e0434a67aba9bf7e -
Trigger Event:
workflow_dispatch
-
Statement type: