text-optimize — deep token optimization

Caution

Verbose prompts waste tokens and blur Claude’s focus. Every filler sentence, passive construction, and prose paragraph that could be a table adds cost and dilutes instruction signal. There is no native “compress this” in Claude Code — you get the full context or nothing.

Tip

30+ validated rules, four modes, parallel processing. The skill reads your files, applies the right rule set for the mode, verifies references, and reports exact before/after metrics. For humanizing AI-generated text, see /brewtools:text-human.

Quick reference

FieldValue
Command/brewtools:text-optimize
Arguments[-l|-s|-d] [file|folder|path1,path2]
Modelsonnet
Contextsession
ToolsRead, Write, Edit, Grep, Glob, Task, AskUserQuestion

When to use

  • Shrink CLAUDE.md — deep mode compresses with a DICT header; LLM-only output, 2-3x reduction
  • Clean up agent/skill definitions — medium mode strips filler, converts prose to tables, merges redundant sections
  • Prepare user-facing docs — standard mode targets 30-50% compression while staying human-readable
  • Light pass on production prompts-l removes filler and fixes tone; structure untouched, safe to apply without review

Modes

ModeFlagTargetCompressionHuman-readable
Light-lAny fileMinimalYes
Medium(default)Any fileModerateYes
Standard-sDocs, README30-50%Yes
Deep-dCLAUDE.md, system prompts, agent/skill defs2-3xNo — LLM-only

Auto-detection: when no flag is given, the skill reads the file path and header. CLAUDE.md, .claude/rules/*.md, KNOWLEDGE.* → deep candidate. README.md, docs/ → standard candidate. Ambiguous → asks via AskUserQuestion.

Examples

# Single file, medium mode (default)
/brewtools:text-optimize CLAUDE.md

# Light mode — safe, minimal changes, no restructuring
/brewtools:text-optimize -l .claude/agents/reviewer.md

# Standard mode — 30-50% reduction, stays readable
/brewtools:text-optimize -s README.md

# Deep mode — max compression for CLAUDE.md, review diff after
/brewtools:text-optimize -d CLAUDE.md

# Multiple files in parallel
/brewtools:text-optimize agents/planner.md, agents/executor.md, CLAUDE.md

# All markdown files in a directory
/brewtools:text-optimize -d agents/

Natural language also works: "compress this for context" → deep mode. "slim down the README" → standard mode.

Flow

  1. Parse input

    Extracts mode flag, file paths, and any prompt hints (“deep compress”, “for LLM”). No args → optimizes ALL: CLAUDE.md, .claude/agents/*.md, .claude/skills/**/SKILL.md.

  2. Auto-detect mode

    If no flag, classifies each file by path and header. Confident classification runs silently with a short notice. Ambiguous files trigger a single AskUserQuestion with mode options.

  3. Analysis phase

    Parallel Explore agents scan each file for structure, cross-references, and redundancies. Results feed the optimization context.

  4. Optimization phase

    Parallel text-optimizer agents apply the rule set for the selected mode. Deep mode builds a DICT header for repeated terms. Standard mode loads standard-compression.md reference. All modes verify file paths (R.1), URLs (R.2), and circular refs (R.3).

  5. Verification

    Standard mode runs 1 verification round comparing compressed vs original — any lost facts get patched. Deep mode runs up to 2 rounds targeting ≥95% semantic match; if still below, warns with a loss list.

  6. Report

    Each file produces a report: lines/tokens before and after, rules applied by ID, issues found and fixed, cross-reference verification status. Files are modified in-place.

Rule categories (30+ rules)
CategoryRule IDsScope
Claude behaviorC.1-C.8Literal following, avoid “think”, positive framing, match style, descriptive instructions, overengineering, avoid ALL-CAPS, prompt format
Token efficiencyT.1-T.8, T.10Tables, bullets, one-liners, inline code, abbreviations, filler, comma lists, arrows, strip whitespace
StructureS.1-S.8XML tags, imperative, single source, context/motivation, blockquotes, progressive disclosure, consistent terminology, ref depth
Reference integrityR.1-R.3Verify file paths, check URLs, linearize circular refs
PerceptionP.1-P.6Examples near rules, hierarchy, bold keywords, standard symbols, instruction order, default over options
LLM ComprehensionL.1-L.7Critical info position, documents-first, conciseness, quote-first, add WHY, reiterate constraint, prompt repetition

Mode-to-rules mapping:

ModeAppliesNotes
LightC.1-C.8, T.6, R.1-R.3, P.1-P.4, L.1-L.7Text cleanup only — no restructuring
MediumAll rules (C + T + S + R + P + L)Balanced transformations
StandardAll rules + standard-compression.md30-50% compression, 1 verification round
DeepAll rules + deep-compression.mdDICT header, symbol substitutions, 1-2 verification rounds

Text Human

Remove AI artifacts and humanize content — the complement to text-optimize.

🧠

text-optimizer agent

The subagent that handles single-file optimization in parallel batches.

🔗

GitHub source

Source code, rule references, and compression guides.

📄

Brewtools overview

All brewtools skills — text, SSH, deploy, debate, plugin management.

Updating plugins

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