Skip to main content

Intelligently package project directories into a single markdown file for AI analysis

Project description

Context Packer - The Webpack for AI Context

PyPI version Python Support License: MIT GitHub Stars

๐ŸŽฏ One file, full context - Package your entire project into a single markdown file optimized for LLMs and documentation.

๐ŸŒŸ Why Context Packer?

In the age of AI-powered development, we face a critical challenge: Large Language Models need complete project context, but sharing multiple files is cumbersome and inefficient.

Just as webpack revolutionized JavaScript bundling and esbuild transformed build speeds, Context Packer transforms how we share code with AI models and documentation systems.

The Problem

  • ๐Ÿ“ LLMs work best with single-file contexts - No need to manage multiple uploads
  • ๐Ÿ”„ Modern documentation systems (like Next.js) support single-file downloads for offline viewing
  • ๐Ÿค– AI code reviews require complete project understanding in one shot
  • ๐Ÿ“š Knowledge sharing becomes complex with scattered files

The Solution

Context Packer intelligently bundles your entire project into a single, AI-optimized markdown file - complete with structure visualization, smart filtering, and symlink support for complex project organization.

โœจ Key Features

  • ๐Ÿ”— Advanced Symlink Support: Organize complex projects with symbolic links - perfect for selective file inclusion
  • ๐ŸŽฏ AI-Optimized Output: Formatted specifically for LLM consumption with clear structure and syntax highlighting
  • ๐Ÿ“Š Smart Filtering: Automatically excludes build artifacts, dependencies, and binary files
  • ๐ŸŒณ Visual Project Tree: Instant understanding of project structure with status indicators
  • โšก Lightning Fast: Efficient processing even for large codebases
  • ๐Ÿ”ง Highly Configurable: Fine-tune output with extensive options

๐Ÿš€ Quick Start

Installation

# Using pip
pip install context-packer

# Using uv (10-100x faster)
uv pip install context-packer

# Using pipx (isolated environment)
pipx install context-packer

Basic Usage

# Pack current directory
ctxpack .

# Pack specific project
ctxpack /path/to/project -o project_context.md

# Pack with custom settings
ctxpack . --max-size 20 --ignore "*.test.js" "docs/*"

๐ŸŽจ Advanced: The Symlink Workflow

Context Packer's symlink support enables a powerful workflow for complex projects where you need fine-grained control over what gets packed.

Scenario: Selective Project Packing

Instead of using complex ignore patterns, create a "packing directory" with symlinks to exactly what you need:

# Create a packing directory
mkdir my-project-pack
cd my-project-pack

# Symlink specific files and directories
ln -s ../src/core core
ln -s ../src/utils/helpers.js helpers.js
ln -s ../config config
ln -s ../package.json package.json
ln -s ../README.md README.md

# Pack only what you've selected
ctxpack . -o ../my-project-context.md

Real-World Example: Multi-Module Project

# You have a monorepo with multiple packages
project/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ frontend/     # React app
โ”‚   โ”œโ”€โ”€ backend/      # Node.js API  
โ”‚   โ”œโ”€โ”€ shared/       # Shared utilities
โ”‚   โ””โ”€โ”€ mobile/       # React Native app

# Create a context for AI review of web platform only
mkdir web-platform-context
cd web-platform-context

# Link only web-related packages
ln -s ../packages/frontend frontend
ln -s ../packages/backend backend  
ln -s ../packages/shared shared
ln -s ../docker-compose.yml docker-compose.yml
ln -s ../.env.example .env.example

# Generate context
ctxpack . -o web-platform.md --follow-symlinks

This approach gives you surgical precision in creating contexts for different purposes:

  • ๐ŸŽฏ Code Review Context: Only the files changed in a PR
  • ๐Ÿ—๏ธ Architecture Context: High-level structure without implementation details
  • ๐Ÿ› Debug Context: Specific module with its dependencies
  • ๐Ÿ“– Documentation Context: README files and examples only

๐Ÿ“‹ Output Format

Context Packer generates a structured markdown file with:

1. Project Structure Visualization

MyProject
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.js โœ…      # High-priority file
โ”‚   โ”œโ”€โ”€ utils/ ๐Ÿ”—๐Ÿ“      # Symlinked directory
โ”‚   โ”‚   โ””โ”€โ”€ helper.js โ˜‘๏ธ  # Included file
โ”‚   โ””โ”€โ”€ tests/ โญ๏ธ        # Ignored directory
โ”œโ”€โ”€ package.json โœ…      # Configuration file
โ””โ”€โ”€ README.md โœ…         # Documentation

2. Status Indicators

  • โœ… High-priority files (configs, README)
  • โ˜‘๏ธ Source code files
  • ๐Ÿ”— Symbolic links
  • ๐Ÿ”—๐Ÿ“ Symlinked directories
  • โš ๏ธ Circular reference detected
  • ๐Ÿ“Š Large files (truncated)
  • โญ๏ธ Ignored files

3. Complete File Contents

Each file is presented with:

  • Relative path
  • Syntax highlighting
  • Smart truncation for large files
  • Clear section separators

๐ŸŽฏ Perfect For

๐Ÿค– AI Development

# Prepare context for AI analysis
ctxpack . -o for_claude.md --max-size 30

# Get AI to review your architecture
ctxpack src/ -o architecture_review.md --max-depth 2

๐Ÿ“š Documentation

# Create offline documentation bundle
ctxpack docs/ -o documentation.md --ignore "*.png" "*.jpg"

๐Ÿ” Code Review

# Package PR changes for review
ctxpack . -o pr_context.md --ignore "node_modules" "*.test.*"

๐ŸŽ“ Learning & Teaching

# Create educational material
ctxpack examples/ -o tutorial_code.md --max-files 20

๐Ÿ› ๏ธ Command Line Options

Option Description Default
project_path Directory to pack Required
-o, --output Output file path {project}_context_{timestamp}.md
--ignore Additional ignore patterns None
--max-size Maximum total size (MB) 10
--max-files Maximum number of files 100
-L, --max-depth Maximum directory depth Unlimited
--follow-symlinks Follow symbolic links Yes
--no-follow-symlinks Don't follow symbolic links No
-v, --verbose Show detailed progress No

โšก Performance Tips

  1. Large Codebases: Use --verbose to monitor progress
  2. Selective Packing: Use symlinks for precise control
  3. Size Management: Adjust --max-size based on LLM limits
  4. Speed Optimization: Use --max-depth to limit traversal

๐Ÿ”’ Security & Best Practices

  • Automatic Exclusions: .env, .git, node_modules are ignored by default
  • Gitignore Respect: Honors your .gitignore patterns
  • Size Limits: Prevents accidental huge outputs
  • Review Before Sharing: Always check output before sending to third parties

๐Ÿง‘โ€๐Ÿ’ป Development

Setting up with UV (Recommended)

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone and setup
git clone https://github.com/MarkShawn2020/context-packer.git
cd context-packer

# Install in development mode
uv pip install -e .
uv pip install -r requirements-dev.txt

# Run tests
uv run pytest

Quick Commands

make test      # Run tests
make lint      # Check code quality
make format    # Format code
make build     # Build package
make publish   # Publish to PyPI

๐Ÿ“ฆ Publishing

With PyPI token configured:

# One-command publish (with version bump)
make release VERSION=patch  # or minor, major

# Or manual steps
python bump_version.py patch
git commit -am "Bump version"
git tag v1.2.3
git push --tags
make publish

๐ŸŒ Ecosystem

Context Packer is part of the modern AI development workflow:

  • Use with Claude, GPT-4, Gemini for code analysis
  • Integrate with CI/CD for automatic documentation
  • Combine with AI editors like Cursor, Windsurf
  • Works with documentation systems like Docusaurus, Next.js

๐Ÿค Contributing

We welcome contributions! Context Packer is designed to be the definitive solution for project context packaging.

Ideas for Contribution

  • ๐ŸŽจ GUI interface (planned)
  • ๐Ÿ”Œ Plugin system for custom processors
  • ๐ŸŒ Web service API
  • ๐Ÿ“Š Context analytics
  • ๐Ÿ”„ Incremental packing

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

Created by MarkShawn2020 to solve the real-world challenge of sharing complete project context with AI models. Inspired by the elegance of webpack and the speed of esbuild, Context Packer brings the same innovation to AI-assisted development.


๐Ÿš€ Transform how you share code with AI

Documentation โ€ข Issues โ€ข PyPI โ€ข Releases

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_packer-1.1.5.tar.gz (12.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_packer-1.1.5-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file context_packer-1.1.5.tar.gz.

File metadata

  • Download URL: context_packer-1.1.5.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for context_packer-1.1.5.tar.gz
Algorithm Hash digest
SHA256 0537d89f4df375b370fd4b593c02152632bb4b6683474ee48dbd7652d6e6ca61
MD5 4d37d285d3c337c699d864aec1434085
BLAKE2b-256 83fce9e76048a38ff00b584519893e4cfa5b1d71df2ed484ec2f909c2b8fc10e

See more details on using hashes here.

File details

Details for the file context_packer-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: context_packer-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for context_packer-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8fa08eb713e5f79affe30122b9560813ecf8d71a2dc7cb3e94ae17c7c97d8da8
MD5 3792425037b6ad3007855a92e03ca201
BLAKE2b-256 49deafc97e8958445ea994724d97545766d635b943f4c5e891be5a5b2f03df23

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