Inspiration AI prompts waste tokens on repeated text, extra whitespace, and noise. I built a tool to clean this up before it reaches the model—saving money and keeping the newest context when budgets are tight.

What I Learned Tokens vary by model: Each model counts differently. You need the exact tokenizer for accurate counts. Rules over rewriting: Summarizing can change meaning. Conservative, validated cleanup is safer for code and docs. Local is better: Processing on your own machine means your text never leaves. How I Built It The engine removes:

Duplicate paragraphs, lines, and sentences Decorative separators and HTML comments Invisible characters and whitespace noise Code blocks are protected—Python and JSON are only compressed if they still parse correctly. A sliding window keeps the newest tokens when a budget is set.

The tokenizer cuts at character offsets (not decoded IDs) and uses binary search to handle BPE merge artifacts at the boundary.

Challenges Cutting without artifacts: Had to use tokenizer character offsets instead of decoding token IDs back to text. BPE boundary issues: Re-encoding the suffix sometimes created extra tokens; solved with binary search. Code safety: Python compression must pass compile(), JSON must parse without duplicates—if validation fails, the original is restored.

Built With

  • argparse
  • bpe
  • cli
  • css3
  • dataclasses
  • difflib
  • esmodules
  • flask
  • hashrouting
  • html5
  • huggingfacetokenizers
  • jsonvalidation
  • localfirst
  • localstorage
  • markdownparsing
  • pathlib
  • python
  • pythontokenization
  • pyyaml
  • restapi
  • tokencounting
  • utf8
  • vanillajavascript
  • websever
Share this project:

Updates

Submission history