Workflow
When this skill triggers, follow these steps in order.
Step 1 — Receive the long context
Accept the text to compress. This can be:
- A pasted document (design doc, chat transcript, code file, meeting notes, etc.)
- A file path the user provides
- Any large blob the user wants to fit into a tighter context window
If the user provides a file path, confirm it exists before proceeding.
Step 2 — Run the compressor
From the skill root directory, run:
node scripts/compress.mjs <inputFile> <outputFile>
The engine applies four deterministic passes in order:
- Paragraph dedup — Finds paragraphs (blank-line-delimited blocks) that
appear more than once and replaces every repeat with a
_(repeated Nx, deduped)_annotation on the first occurrence. - Boilerplate stripping — Removes lines matching known low-salience patterns:
Lorem ipsum, legal confidentiality notices, copyright lines, "for internal use only" footers, and similar content. - Line dedup — Removes exact duplicate non-blank lines within the remaining text.
- Blank-line collapse — Collapses runs of two or more consecutive blank lines into a single blank line, and strips trailing whitespace from each line.
The compressed text is written to the output file. Token estimates are printed to stderr for inspection.
Step 3 — Compute before/after token estimates
The skill uses scripts/count-tokens.mjs to estimate token counts before and
after compression. The estimator uses a word + punctuation heuristic (~4 chars
per alphanumeric run, 1 token per punctuation character). It is an approximation
— see the caveat note below.
node scripts/count-tokens.mjs <file>
Step 4 — Report results to the user
Report the following:
- Tokens before (estimated)
- Tokens after (estimated)
- Percentage reduction
- The compressed context (inline or as a file reference)
- The caveat that counts are estimates
Output format
Compression complete.
Tokens before: ~<N> (estimated)
Tokens after: ~<M> (estimated)
Reduction: <X>%
Note: token counts are heuristic estimates (word+punctuation splitter).
For exact BPE counts, use tiktoken (OpenAI) or LLMLingua (Microsoft).
Compressed context:
---
<compressed text here>
---
If the reduction is below 5%, tell the user the context is already compact and compression had minimal impact.
Example
See examples/input.md for a 200+ line design document with intentional
redundancy (duplicated sections, repeated boilerplate, blank-line runs).
Run the example yourself:
cd skills/compresr-context-compressor
bash examples/run.sh
The output is written to examples/output.md with the full before/after report
and the compressed context in a fenced block.
Caveats
- Lossy-but-safe: Compression removes genuinely redundant content. It does not summarize or paraphrase — unique content is always preserved.
- Estimate caveat: Token counts are heuristic estimates, not real BPE counts.
For production use, replace
count-tokens.mjswith tiktoken or LLMLingua. - Boilerplate is deterministic: The boilerplate patterns are regex-based and
documented in the source. If a pattern incorrectly strips content, remove or
adjust it in
scripts/compress.mjs.