Text Optimizer

sonnet 5 modes owned edits only

Quick reference

FieldValue
Agentbrewtools:text-optimizer
Triggersoptimize prompt, reduce tokens, compress
ToolsRead, Write, Edit, Glob, Grep, Bash, WebFetch
Main-session entrytext-optimize
OutputPer-file measured size changes, semantic checks, rule ids, and report path

What it does

Compress text while preserving the facts and behavior that make it useful. The optimizer removes repetition, tightens wording, and applies the selected mode’s transformations. Numbers, names, dates, paths, versions, examples, negations, and scope qualifiers remain protected. Authorized factual replacements are recorded separately from loss.

Use the text-optimize skill to coordinate snapshots and acceptance. The writer owns a bounded file edit; it does not re-delegate, change Git, or accept its own optimization.

When to use

  • Tighten agent, skill, or rule instructions without weakening scope or safety conditions.
  • Remove accidental duplicate facts within a document.
  • Keep README and documentation readable while reducing verbosity.
  • Compare compression against an explicit fact inventory and actual size measurements.

Example

/brewtools:text-optimize -s README.md
/brewtools:text-optimize -l .claude/rules/project.md
/brewtools:text-optimize -d .claude/agents/domain-expert.md

The main skill snapshots the original before delegating the file. Expect an edited file and a compact report with measured words/characters, verification evidence, and unresolved losses. An unverified result is not accepted merely because it is shorter.

Modes

ModeBehavior
LightLimited cleanup; only exact-duplicate D.1 removal, without restructuring
MediumGeneral compression with a zero-loss fact self-check
StandardHuman-readable compression and independent semantic review
DeepDense instruction compression with explicit ledgers and semantic review
MaxExplicit opt-in only; deep techniques plus atomic claims and two verification methods

Without a flag, LLM instruction files default to deep, human-facing docs to standard, and unknown content to medium. Max is never auto-selected. Prompt-quality rewriting applies only to prompt-shaped content at medium or above, never to light.

Mode targets are guidance, not promised savings. Report this file’s measured result instead of presenting reference-example ratios as its outcome.

Workflow

  1. Require the original snapshot

    The main skill creates the pre-edit snapshot and supplies RUN_DIR. Missing snapshot information stops the writer before editing. Snapshot files are readable comparison evidence and remain immutable.

  2. Load rules and inventory facts

    Read the base rules and selected mode references. Measure words, bytes, and characters separately; enumerate critical facts and applicable conditions before rewriting.

  3. Deduplicate within assigned ownership

    Light uses D.1 only. Other modes distinguish repeated facts from different scopes, numbers, or conditions. Cross-file deduplication requires the main owner’s explicit canonical-location decision and a meaningful summary pointer.

  4. Edit and checkpoint the known draft immediately

    After each owned atomic write, deletion, or repair, record that exact draft before another edit or check. Preserve concurrent changes; never record another writer’s bytes as proof of ownership.

  5. Verify without automatic restoration

    The skill runs the mechanical guard with —no-restore and applies mode-specific fact checks. Standard, deep, and max require a fresh independent verifier who compares original and current files without relying on the writer’s report.

  6. Patch confirmed owned losses or refuse acceptance

    Repair only the owned draft, checkpoint immediately, and repeat required review. Unsafe or unproven recovery is refused; the current file stays intact. Report actual metrics and remaining losses.

Snapshots and safe recovery

Original evidence is immutable; current drafts need ownership proof.

The pre-edit original lives under <RUN_DIR>/orig/<repo-relative-path>. Read it for comparison; do not edit, delete, or recreate it. Progress reports are not backups. The writer checkpoints each known owned draft immediately after its edit, including an owned deletion or repair.

The mechanical guard uses verify --no-restore: failures preserve current bytes and print evidence for classification. A mechanical pass cannot prove semantic equivalence. Missing state or snapshots prevents acceptance.

Full restoration requires authorization and an already recorded checkpoint matching current bytes. Missing proof or intervening changes produces RESTORE_REFUSED and leaves the file untouched. Creating a checkpoint at failure or restore time cannot manufacture ownership. Targeted repairs also require checking current bytes against the last known draft.

Semantic acceptance

ModeRequired checks
Every modeMechanical sub-gate and skill-owned acceptance
LightNo semantic agent round
MediumWriter fact self-check plus skill review; zero loss
StandardIndependent fact review; at least 98% kept/merged
DeepIndependent fact review; at least 95%; repair and recheck failed gates
MaxAt least 95%, plus mandatory second independent method: original-derived self-QA

Standard, deep, and max also require 100% preservation of numbers, names, negations, and scope qualifiers. Mode percentages never authorize deleting project-specific obligations. Merged duplicate facts and faithful paraphrases count as preserved. Known-fact elisions are ledgered and count as loss; a word drop that distorts a fact fails that fact’s check. Unresolved confirmed loss blocks acceptance rather than shipping with a caveat.

Measurement and reports

Use wc -w for words, wc -c for bytes, and wc -m for characters. These are different measurements. Token counts require a named tokenizer and encoding. Characters divided by four is only a rough proxy; it is not measured tokens or proof of token savings.

The final return is verdict-first and compact: file paths, before/after sizes, counting method, change/ratio, semantic match, rule ids, verification verdict, and dedup summary. Fact inventories, loss/dedup ledgers, and detailed evidence stay in report files. Finished-file checkpoints and progress are recorded as work proceeds so interrupted work can resume from evidence.

📄

Brewtools overview

Text utilities, agents, and task orchestration.
✨

Text Optimize

The main skill that owns snapshots, delegation, and acceptance.
⚡

Context Slim

Coordinate context cleanup across instruction surfaces.
🔗

Agent source

Writer scope, checkpoints, measurement, and mode rules.

Updating plugins

Use /brewtools:plugin-update to check and update the brewcode plugin suite in one command. See the FAQ for details.