Skip to main content

Pack any project folder into a compact, AI-readable XML snapshot — strip noise, keep signal, cut context by ~50%

Project description

promptpack

Pack any project folder into a compact, AI-readable XML snapshot.
Strip noise. Keep signal. Cut your context window usage by ~50%.

PyPI version Python Versions License: MIT GitHub


What is promptpack?

When you paste an entire codebase into an AI prompt, you waste most of your context window on blank lines, comments, docstrings, and repeated path prefixes. promptpack solves this by scanning your project and producing a single .promptpack.xml file that contains everything the AI needs — nothing more.

What it does:

  • Strips all comments, docstrings, and blank lines from source files
  • Minifies JSON files to single-line
  • Groups files by directory to avoid repeating path prefixes
  • Renders the directory tree using compact Unicode box-drawing characters
  • Skips irrelevant files: node_modules, dist, tests, docs, lock files, binaries, .env secrets, changelogs, licenses, and more
  • Respects .gitignore patterns automatically

Typical result: ~50% reduction in token count compared to pasting raw source files.


Install

pip install promptpack

Requires Python 3.8 or higher. No external dependencies.


Quick start

# Pack a project folder next to it
promptpack my-app

# Pack a project anywhere using its path
promptpack ./path/to/my-app

# Custom output path
promptpack my-app -o context.xml

# Print to stdout (pipe into clipboard, etc.)
promptpack my-app --stdout

# macOS: copy directly to clipboard
promptpack my-app --stdout | pbcopy

After running, paste the contents of my-app.promptpack.xml into your AI prompt:

Here is my full project snapshot:

[paste contents of my-app.promptpack.xml]

Now help me...

Output format

The output uses compact abbreviated XML tags to minimize token usage:

<?xml version="1.0" encoding="utf-8"?>
<proj n="my-app" files="23" tokens="~4800">
<tree>├─package.json
├─tsconfig.json
└─src/
  ├─index.ts
  ├─app.ts
  └─utils/
    ├─helper.ts
    └─types.ts</tree>
<f p="package.json" l="json">{"name":"my-app","version":"1.0.0","scripts":{"dev":"ts-node src/index.ts"}}</f>
<d p="src">
<f n="index.ts" l="ts">import {createApp} from './app'
const app = createApp()
app.listen(3000)</f>
</d>
</proj>

Tag reference

Tag Attribute Meaning
<proj> n project name
<proj> files total file count included
<proj> tokens estimated token count of packed content
<tree> directory structure with box-drawing chars
<d> p directory path (groups files to avoid path repetition)
<f> p file path (top-level files)
<f> n file name (files inside a <d> block)
<f> l language identifier

Language identifiers

py js ts jsx tsx java c cpp go rs rb php
swift kt cs dart lua sh sql html css scss
json yaml toml md gql proto tf docker nix


CLI options

usage: promptpack [-h] [-o OUTPUT] [--no-transform] [--keep-blanks]
                  [--no-tree] [--ignore [IGNORE ...]] [--stdout]
                  project
Flag Description
project Folder name or path to pack
-o, --output Custom output file path
--no-transform Skip all minification (raw source content)
--keep-blanks Keep one blank line between code blocks (less aggressive)
--no-tree Omit the directory tree from output
--ignore PATTERN Additional glob patterns to exclude
--stdout Print XML to stdout instead of writing a file

What gets included vs excluded

Included by default:

  • All source code files (.py, .ts, .js, .go, .rs, .java, …)
  • Config files (.json, .yaml, .toml, .env.example, …)
  • Build scripts (Dockerfile, Makefile, .sh, …)
  • Root-level documentation (README.md)

Excluded by default:

  • node_modules/, __pycache__/, .git/, venv/, dist/, build/
  • tests/, test/, __tests__/, spec/, e2e/
  • docs/, doc/, examples/, fixtures/, stubs/, vendor/
  • Lock files: package-lock.json, yarn.lock, pnpm-lock.yaml, *.lock
  • Minified files: *.min.js, *.min.css, *.map
  • Binary files: images, fonts, executables, archives
  • Secret files: .env, .env.local, .env.production
  • Documentation text: *.txt, *.rst, CHANGELOG*, LICENSE*, AUTHORS*
  • Any file over 512 KB
  • All patterns listed in .gitignore

You can add extra patterns at runtime:

promptpack my-app --ignore "*.test.ts" "migrations/"

Minification details

Language What gets stripped
Python Inline # comments, docstrings ("""...""", '''...'''), blank lines
JS / TS / Go / Java / C++ / Rust / … // line comments, /* */ block comments, blank lines
Ruby / Shell / YAML / TOML / … # line comments, blank lines
HTML / XML <!-- --> comments, blank lines
JSON Reformatted to single-line with no spaces
CSS / SCSS /* */ comments, excess whitespace between selectors
Markdown Trailing whitespace, consecutive blank lines

Benchmark

Tested on Flask source (31 source files, excluding tests and docs):

Size Est. tokens
Raw source 349 KB ~89,400
promptpack output 173 KB ~44,200
Reduction 50.6% 50.6%

Programmatic usage

You can use promptpack as a library inside your own scripts:

from pathlib import Path
from promptpack.scanner import scan
from promptpack.transformer import transform
from promptpack.serializer import serialize, write

project = Path("./my-app")

files = []
for rel_path, lang, content in scan(project):
    minified = transform(content, lang)
    if minified.strip():
        files.append((rel_path, lang, minified))

xml_output, stats = serialize(project_name="my-app", files=files)

print(f"Files: {stats['files']}")
print(f"Tokens: ~{stats['output_tokens']:,}")

write(Path("my-app.promptpack.xml"), xml_output)

Publishing / contributing

This project is open source under the MIT license.

Pull requests are welcome.


License

MIT © AchillesHubTeam

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

promptpack-0.1.2.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

promptpack-0.1.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file promptpack-0.1.2.tar.gz.

File metadata

  • Download URL: promptpack-0.1.2.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for promptpack-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7e4c973794269c8fc5de2f40855c449b066a662fed4a4d0f89249bd8116d9feb
MD5 b1b0f1f774d7ebadb17d8cffc5e86880
BLAKE2b-256 d61c267b4af42b013c973346a5e9f6d7ad4c69d6bba540f034e292cef1adfcf2

See more details on using hashes here.

File details

Details for the file promptpack-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: promptpack-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for promptpack-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07746ebc24eae21f470adcd2d7e95f3175304e8bcb0f659fa17734c1efe9c85d
MD5 7004e1276ca92b563f0a12e1ba55f069
BLAKE2b-256 fcbda60f34c9a13724c1552d5bba9d4ce30680f823ab66133488f27d1fc4132d

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