ContextPack

FastPress Labs · Zero Dependencies · Apache-2.0

Pack codebases into token-budgeted LLM context.

Zero-runtime-dependency CLI, Node.js library, and stdio MCP server. Pack full directories, subtrees, and Git diffs into Anthropic XML, Markdown, or llms-full.txt with strict token budgeting.

npx -p github:fastpresspages/contextpack contextpack .
Try Interactive Demo
  • Zero runtime dependencies
  • Token budget enforcement (16k–200k)
  • Native stdio MCP server
  • Anthropic XML & Markdown
  • Git diff & tree integration
  • 100% Free & Open Source

Interactive Context Simulator

Test how ContextPack formats your code and estimates token consumption in real time right in your browser.

Sample Source File: src/math.js
Packed Output 0 tokens
Click "Pack Context" above to format.

Engineered for High-Context Agentic Coding

Built from scratch with zero bloat to serve the needs of engineers building with LLMs daily.

⚡

Zero Runtime Dependencies

Built with pure Node.js standard modules. No massive node_modules folder, no native binary compile issues, and instant cold start in CI.

🎯

Strict Token Budgeting

Never crash an LLM API with context overflows. Set --max-tokens 32k and ContextPack fits as much vital code as possible, tracking omitted files cleanly.

🤖

Native stdio MCP Server

Instantly connect your local coding agent (Claude Code, OpenCode, Cursor) using standard Model Context Protocol tools for codebase packing, tree views, and diff analysis.

📁

Smart Tree & Gitignore Walker

Automatically detects and parses .gitignore, skips binary files (images, compiled binaries, archives), and filters build artifacts effortlessly.

🔄

Git Diff Integration

Pack working tree changes, staged edits, or branch diffs directly with line numbers to feed pull request reviewers and bug-triage prompts.

📑

Multi-Format Support

Export directly to Anthropic-standard XML (<documents><document>), Markdown code blocks, JSON metadata, or web-standard llms-full.txt.

Production Output Formats

Structured formats proven to maximize retrieval and reasoning accuracy in modern frontier models.

1. Anthropic Prompt XML

Recommended by Anthropic for Claude 3.5 Sonnet and Opus. Segregates files into indexed <document> wrappers with CDATA protection.

<documents>
<directory_tree>
├── src/
│   └── index.js
</directory_tree>
<document index="1">
<source>src/index.js</source>
<document_content>
1: console.log("Hello");
</document_content>
</document>
</documents>

2. Human-Readable Markdown

Perfect for pasting into ChatGPT, DeepSeek, or storing as persistent documentation files in your repository.

# Codebase Context

## Directory Tree
```
├── src/
│   └── index.js
```

## Codebase Contents

### `src/index.js`
```javascript
1: console.log("Hello");
```

Model Context Protocol (MCP) Integration

Empower your AI coding tools to inspect and pack repository context autonomously.

claude_desktop_config.json / opencode.json
{
  "mcpServers": {
    "contextpack": {
      "command": "npx",
      "args": ["-y", "-p", "github:fastpresspages/contextpack", "contextpack-mcp"]
    }
  }
}

Exposed MCP Tools

  • pack_codebase Pack directory trees with token caps, git diffs, and formatting options into ready context.
  • get_tree Generate visual directory hierarchies with file sizes and token estimates.
  • pack_diff Extract and pack staged or branch Git diffs with affected file context.
  • estimate_tokens Fast BPE token approximation for any arbitrary text snippet or disk file.

Automate in GitHub Actions

Generate packed codebase contexts inside your CI/CD workflows for automated PR review or documentation steps.

.github/workflows/ai-review.yml
- name: Pack Repository Context
  uses: fastpresspages/contextpack@main
  id: pack
  with:
    path: '.'
    format: 'xml'
    max-tokens: '64k'
    with-tree: 'true'
    git-diff: 'true'
    out: 'context.xml'

- name: AI Review Step
  run: |
    echo "Packed ${{ steps.pack.outputs.files }} files (${{ steps.pack.outputs.tokens }} tokens)"
    # Pass context.xml to your LLM API call

Frequently Asked Questions

Straightforward answers about licensing, token algorithms, and security.

Is ContextPack really free?

Yes, 100% free and open-source under the Apache-2.0 license. There are no paid tiers, no API keys, and no telemetry.

How accurate is the token estimator?

ContextPack's tokenizer uses a calibrated heuristic calibrated against Claude and cl100k_base models. In benchmark testing on real codebases (JavaScript, TypeScript, Python, Go, Rust), it correlates within ~3-5% of true tokenizers while executing orders of magnitude faster without large WASM/Rust binary dependencies.

How does token budgeting handle large codebases?

When you set --max-tokens, ContextPack reserves tokens for header metadata and the directory tree, packs files until the budget ceiling is approached, and cleanly tracks omitted files in an <omitted_files> block so your model knows which files were skipped.

Does ContextPack send any code over the internet?

Never. All file operations, tree generations, token counts, and diffs are computed locally in your Node.js process.

Who maintains ContextPack?

ContextPack is developed and maintained by FastPress Labs (github.com/fastpresspages), an open-source studio committed to building zero-bloat developer tools.

Request a Feature or Report an Issue

ContextPack is actively maintained. Have a feature request, check pattern suggestion, or question? Send us a note or open an issue on GitHub.

Email: meetcode99@gmail.com · GitHub Repository

About FastPress Labs

ContextPack is part of the FastPress Labs ecosystem: open-source developer tools with zero telemetry and verified quality audits. Check out our companion tools: