# Context Trimmer

Trim text to an approximate token budget for LLM prompts, keeping the head, tail, middle, or both ends. Runs locally in your browser.

## Run it

- **CLI:** `gizza tool context-trimmer "Paste the long text, prompt, log, transcript, or document here…"`
- **Web:** https://gizza.ai/tools/context-trimmer/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/context-trimmer/tool.json

## Inputs

- `text` — Text _(field)_
- `max_tokens` — Max tokens _(field)_
- `chars_per_token` — Characters per token _(field)_
- `keep` — Keep _(field)_
- `marker` — Omission marker _(field)_
- `head_ratio` — Head ratio _(field)_
- `break_words` — Allow cutting inside words _(field)_

## Output

- Trimmed text (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `text` — Text
- `max_tokens` — Max tokens
- `chars_per_token` — Characters per token
- `keep` — Keep
- `marker` — Omission marker
- `head_ratio` — Head ratio
- `break_words` — Allow cutting inside words

Example: `https://gizza.ai/tools/context-trimmer/?text=Paste%20the%20long%20text%2C%20prompt%2C%20log%2C%20transcript%2C%20or%20document%20here%E2%80%A6&max_tokens=512&chars_per_token=4.0&keep=head&marker=%E2%80%A6&head_ratio=0.5&break_words=true`

---

## About this tool

**Context Trimmer** shortens text so it fits an approximate LLM token budget. It is useful when you need to paste a long log, transcript, prompt, article, or chat-history excerpt into a model with a fixed context window.

The tool uses a simple, transparent estimate: `tokens ≈ characters ÷ characters per token`. The default is `4.0` characters per token, a common English rule of thumb. Lower the value for code or non-English text when you want a more conservative trim.

### Worked example

Input:

```text
the quick brown fox jumps over the lazy dog
```

Settings: `max_tokens = 5`, `chars_per_token = 4.0`, `keep = head_tail`, marker `…`.

Output:

```text
the quick…lazy dog
```

The marker counts toward the budget, so the final result still fits the target estimate.

### Keep strategies

- **Head** keeps the beginning and drops the end.
- **Tail** keeps the end and drops the beginning.
- **Middle** keeps the centre and drops both ends.
- **Head + tail** keeps the beginning and the end, dropping the middle. Use **Head ratio** to split the budget between the two sides.

### Limits

- This is an approximate character-based budget, not a model-specific tokenizer. Exact token counts vary by model and language.
- By default, cuts move to whitespace so words are not split. Turn on **Allow cutting inside words** for exact character-limit cuts.
- If the input already fits the budget, it is returned unchanged and no marker is inserted.
- The maximum budget is capped at 1,000,000 tokens to avoid accidental huge outputs.

## FAQ

<details>
<summary>Does this use the same tokenizer as GPT, Claude, or Llama?</summary>

No. It intentionally uses a transparent approximation: characters divided by the **Characters per token** value. Use a lower value for more conservative trimming when exact model-token fit matters.

</details>

<details>
<summary>Which keep mode should I choose for logs or stack traces?</summary>

Use **Head + tail** for logs, stack traces, and command output. The beginning often has setup context, while the end usually contains the failure. Use **Tail** when only the latest messages matter.

</details>

<details>
<summary>Why does the output sometimes use fewer tokens than the target?</summary>

When word-safe trimming is enabled, the cut backs up or moves forward to a whitespace boundary so it does not split words. That can leave a little unused budget. Turn on **Allow cutting inside words** for stricter character use.

</details>

<details>
<summary>Is the text uploaded anywhere?</summary>

No. The trim runs locally in your browser with WebAssembly; your text stays on your device.

</details>

## Related tools

- [Compare Two Lists](https://gizza.ai/tools/list-set-diff/): Compare two lists as sets and see which items are only in A, only in B, or shared — with counts. Ignore case, trim, dedupe, and leading zeros. Runs in your browser.
- [Text Diff](https://gizza.ai/tools/text-diff/): Compare two text blocks and highlight added, removed, and changed lines.
- [Word Counter](https://gizza.ai/tools/word-count/): Count the words, characters, and lines in any block of text. Free, instant, runs entirely in your browser — no sign-up required.
- [Email Reply Cleaner](https://gizza.ai/tools/email-reply-cleaner/): Paste a replied or forwarded email and get just the fresh message — quoted lines, the reply chain, and signatures removed. Toggle each pass. Runs in your browser.
- [Text to Table](https://gizza.ai/tools/text-to-table/): Render delimited text (CSV, TSV, or custom-separated data) as an aligned ASCII or Markdown table.
