Open source · Prompt & Agent Workflows

Context Window Packer

Pack context by priority while preserving required instructions and citations.

v0.1.0 · Node.js 22+ · MIT

Browse the public repository · View releases

You give it a manifest: a JSON file that names each segment of material you might put in a prompt, what kind of thing it is, how important it is, whether it is mandatory, which other segments it cites, and where its text comes from. You give it a token budget. It tells you what fits.

This walkthrough uses the tool's public README and checked-in example files. Run the command from a repository checkout with Node.js 22+.

Run the checked-in example

# Pack the worked example and write the retained segments out
node bin/context-window-packer.mjs \
  --manifest examples/brief/manifest.json \
  --config examples/packer.config.json \
  --pack-out build/example-pack.json

# The same run as machine-readable JSON
node bin/context-window-packer.mjs \
  --manifest examples/brief/manifest.json \
  --token-cost estimate --budget-tokens 240 --json

# A manifest whose mandatory instructions do not fit: exits 1
node bin/context-window-packer.mjs \
  --manifest examples/over-budget/manifest.json \
  --token-cost declared --budget-tokens 256

# Everything: lint, tests, both examples, packaging
npm run check

Read the result

A consumer piping stdout must handle the empty case. Emitting a fake report for a run that never started would be worse.

Scope

Every limit is enforced, overridable from the command line, and named in the finding when it is reached. Exceeding one is an incomplete result with no pack — never a quietly shorter window.