# Compresr Context Compressor

> Compress a long context blob to reduce LLM token usage — deduplicates repeated lines and paragraphs, strips boilerplate, collapses blank-line runs, and reports before/after token estimates so you can see exactly how much context was saved.

- Skill: `riteshkew/compresr-context-compressor` (Agent Skill, multi-file: 8 files)
- Install (CLI): `npx skillmds@latest add riteshkew/compresr-context-compressor`
- Raw SKILL.md: https://api.skillmd.com/api/skills/riteshkew/compresr-context-compressor/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: riteshkew (https://skillmd.com/u/riteshkew)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/riteshkew/compresr-context-compressor

---


# 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:

```bash
node scripts/compress.mjs <inputFile> <outputFile>
```

The engine applies four deterministic passes in order:

1. **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.
2. **Boilerplate stripping** — Removes lines matching known low-salience patterns:
   `Lorem ipsum`, legal confidentiality notices, copyright lines, "for internal
   use only" footers, and similar content.
3. **Line dedup** — Removes exact duplicate non-blank lines within the remaining text.
4. **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.

```bash
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:

```bash
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.mjs` with 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`.

