Are you TokenMaxxing hard enough? Find out in less than a minute →

Trim

Scores token-by-token significance in captured prompts and flags low-significance regions for review.

Trim scores token-by-token significance in captured prompts using LLMLingua-2, a BERT-class classifier that runs on CPU. It identifies long, low-significance regions the model likely doesn’t use and surfaces them for you to review and edit by hand.

tj optimize trim

Trim never rewrites a prompt. Aggressive compression breaks tasks in surprising ways. The report says “this region looks unimportant.” You investigate and decide.

Installation

LLMLingua-2 pulls in PyTorch and transformers (~2GB), so it’s kept out of the base install:

pipx install 'tokenjam[bloat]'

The base install does not pull torch. Trim still shows up in the analyzer choices, but running it without the extra prints an install hint and exits.

Requirements

  • [capture] prompts = true in your config. Trim needs captured prompt text to score. Without it, the analyzer prints a hint pointing at the flag.
  • The LLMLingua-2 model (~110MB) downloads on first run and caches under ~/.cache/tokenjam/models/. Subsequent runs are offline-capable. Override the cache directory with TOKENJAM_MODEL_CACHE=/path.

How to read the output

For each scored prompt (up to 50 per run, biggest first) the finding reports the prompt length, the count of significant characters above the 0.40 threshold, the flagged low-significance characters, a rough token-reduction estimate, and the individual flagged regions with their positions and a sample preview.

tj report --trim                # all agents, 30d window
tj report --trim my-agent       # scope to one agent
tj report --trim --since 7d     # custom window

The HTML report dims and strikes through the flagged regions over the original prompt, so you can read it in context before touching anything. Output goes to ~/.cache/tokenjam/reports/.

Honesty caveat

Trim confidence is structural. The classifier is trained on data outside your domain, so its low-significance predictions are predicted low-significance regions, not a quality claim about whether the model would have produced the same output with the region removed:

Predicted low-significance regions. Review before editing.

See also

  • Summarize — rewrite a whole prompt file while keeping its structure
  • Cache — measure and improve prompt-cache usage

Get TokenJam updates