The Goal: Bootloader for Agents
When an autonomous agent (like a PR bot or coding assistant) encounters a new repository, it needs a mental map and relevant code snippets in seconds, without the overhead of a permanent RAG pipeline.
1. The Core Pipeline
Instead of treating code as generic text chunks for embeddings, ContextPacker follows a "breadth-first" discovery process similar to how a senior developer explores a codebase.
Phase 1: The Semantic Skeleton
We build a lightweight, hierarchical representation of the repository.
- Symbol Extraction: We use AST parsing to extract top-level functions, classes, and types.
- Hierarchical Compression: To fit large repos into a context window, we summarize low-signal folders (e.g.,
... +142 more files) while expanding high-signal branches. - Query-Aware Expansion: We tokenize the user's query and dynamically "zoom in" on folders that match the keywords.
Phase 2: Intelligent Selection
A fast reasoning model reads the compressed tree and assigns priority:
- Critical (55% budget): Core logic.
- Important (30% budget): Direct dependencies.
- Supplementary (10%): Auxiliary logic.
Phase 3: Adaptive Packing
We read the selected files and fit them into your token budget using O(1) Token Slicing. Large files are truncated gracefully, ensuring the LLM sees imports and definitions even if the full implementation is huge.
2. The Agent Lifecycle
ContextPacker is designed for iterative agent loops:
- Discovery: Agent calls
/v1/skeletonto see the repo "Map." - Planning: Agent identifies candidate directories.
- Retrieval: Agent calls
/v1/packsto get the "Data." - Action: Agent applies changes or answers the user.
3. Distribution: Zero Friction CLI
npx contextpacker https://github.com/fastapi/fastapi "routing"
We built the CLI to minimize "Time to Wow." It automatically generates an anonymous device ID and grants 100 free credits instantly. No signup, no config, no git clone.
Benchmarks
| Metric | ContextPacker | Embeddings |
|---|---|---|
| Latency (Warm) | ~1.5s | ~0.5s |
| Expert Recall | 75% | 60-70% |
| Setup Time | 0s (URL) | ~5 mins |