Optimizes text, prompts, and documentation for LLM token efficiency. Applies 41 research-backed rules across six categories: Claude behavior, token efficiency, structure, reference integrity, perception, and LLM comprehension. Use when optimizing prompts, reducing token counts, compressing verbose documentation, or improving the quality of LLM instructions.
Optimize prompts, CLAUDE.md, agent instructions, and documentation for LLM token efficiency. Applies 52 research-backed rules across 8 categories. Typical savings: 30-50% on prose, 20-30% on technical specs.
Install:
npx skills add kochetkov-ma/claude-brewcode
Use via slash command:
/text-optimizer my-prompt.md
/text-optimizer my-prompt.md -d # deep — max compression
/text-optimizer my-prompt.md -l # light — cleanup only
/text-optimizer .claude/agents/ # directory — all .md files in parallel
Or via natural language prompt:
Optimize my-prompt.md for token efficiency
Optimize all agent instructions in .claude/agents/
Claude reads 52 rules, analyzes your files, applies transformations, and outputs a before/after report with token counts. For directories — finds all .md files and processes them in parallel.
/text-optimizer CLAUDE.md
Applies all 48 lossless rules (A.1-A.4 aggressive lossy stay deep-only) with balanced restructuring. Best for most files.
<details> <summary>Optimization: filler removal + positive framing</summary>Before:
Please note that it's important to remember that the API basically
requires authentication for all endpoints. Do not use markdown
formatting in your responses. You should never create new files
when fixing bugs.
After:
The API requires authentication for all endpoints. Write responses
in flowing prose without formatting. Apply all bug fixes to
existing files only.
Rules: filler removed (T.6), negative "do not" flipped to positive "do Y" (C.3), "you should" dropped for imperative (S.2).
</details> <details> <summary>Optimization: prose to table</summary>Before:
The function accepts three parameters: name (string, required),
age (number, optional, defaults to 0), and active (boolean,
optional, defaults to true).
After:
| Param | Type | Required | Default |
|--------|---------|----------|---------|
| name | string | yes | — |
| age | number | no | 0 |
| active | boolean | no | true |
Rule: tables over prose for multi-column data (T.1).
</details>/text-optimizer system-prompt.md -d
Aggressive rephrasing, section merging, all redundancy eliminated. Review the diff after — deep mode changes structure.
<details> <summary>Optimization: aggressive language toned down</summary>Before:
CRITICAL: You MUST ALWAYS use this tool IMMEDIATELY when searching.
NEVER under ANY circumstances skip the validation step.
After:
Use this tool when the task involves file search.
Run validation before each deployment.
Rules: descriptive over emphatic (C.5), avoid ALL-CAPS in Claude 4.x (C.7). The model overtriggers on aggressive language — calm instructions get better compliance.
</details> <details> <summary>Optimization: critical info repositioned</summary>Before:
Here are the coding guidelines...
[20 pages of context]
...and remember, never expose API keys in logs.
After:
API keys must never appear in logs.
Here are the coding guidelines...
[20 pages of context]
Reminder: API keys must never appear in logs.
Rule: critical info at START and END (L.1). LLMs pay 40-50% less attention to middle content.
</details>/text-optimizer production-prompt.md -l
Text cleanup only — no restructuring, no section merging. Safe for reviewed, stable documents.
<details> <summary>Optimization: filler and redundancy only</summary>Before:
It is important to note that you should always make sure to validate
user input. Please remember that basically all external data needs
to be sanitized before processing.
After:
Validate all user input. Sanitize external data before processing.
Rules: filler removed (T.6), imperative form (S.2). Structure and sections stay intact.
</details>/text-optimizer .claude/agents/
Scans the directory, finds all .md files, and processes them in parallel. Each file gets its own optimization report. This is the fastest way to optimize an entire agents or skills folder at once.
/text-optimizer -d .claude/rules/
Deep mode on a directory — max compression for all rules files in parallel.
<details> <summary>Example: optimizing 5 agent files at once</summary>/text-optimizer .claude/agents/
Found 5 files: developer.md, reviewer.md, tester.md, architect.md, bash-expert.md
Processing in parallel...
## Optimization Report: developer.md
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Lines | 142 | 98 | -31% |
| Tokens | ~1850 | ~1190 | -36% |
## Optimization Report: reviewer.md
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Lines | 203 | 131 | -35% |
| Tokens | ~2640 | ~1580 | -40% |
... (report for each file)
</details>
/text-optimizer CLAUDE.md, .claude/agents/reviewer.md, .claude/rules/testing.md
Comma-separated list — processes each file, generates a report for each.
Optimize all agent instructions in .claude/agents/
Claude finds .claude/agents/*.md, applies medium mode to each in parallel.
/text-optimizer -d api-docs.md
The optimizer will not shorten "authentication" to "auth" or "configuration" to "config" in instructions — even in deep mode. Why? Shortening domain terms caused 30+ point accuracy drops in benchmarks. The model picks the statistically dominant meaning of the abbreviation, which may not match your intent. Short forms (impl, cfg, env) are only used in tables where context is clear. (arXiv:2512.02246)
# optimizer keeps full form in instructions:
- Ensure proper auth before accessing the config endpoint
+ Ensure proper authentication before accessing the configuration endpoint
# but abbreviates in tables where column context disambiguates:
| Param | Type | Desc |
| auth | bool | Enable authentication |
/text-optimizer system-prompt-with-code.md -d
If your prompt embeds Java/C++/C# code examples, the optimizer strips indentation — saving 11-22% tokens with under 1.6% quality loss. Python is excluded (whitespace is syntactic). (arXiv:2508.13666)
# before — 4 levels of indentation:
- public class UserService {
- public User findById(Long id) {
- return repository.findById(id)
- .orElseThrow(() -> new NotFoundException(id));
- }
- }
# after — stripped:
+ public class UserService {
+ public User findById(Long id) {
+ return repository.findById(id)
+ .orElseThrow(() -> new NotFoundException(id));
+ }
+ }
/text-optimizer long-system-prompt.md
The optimizer moves critical constraints to the beginning and end of the document. LLMs pay 40-50% less attention to content in the middle — the "Lost in the Middle" effect. (TACL 2024)
# before — buried constraint:
[page 1: introduction]
[page 2: guidelines]
- [page 3: ...and never expose API keys in logs.]
[page 4: examples]
# after — sandwiched at edges:
+ API keys must never appear in logs.
[page 1: introduction]
[page 2: guidelines]
[page 3: examples]
+ Reminder: API keys must never appear in logs.
/text-optimizer rag-prompt-template.md
If your prompt template has {{DOCUMENTS}} and a question, the optimizer reorders: documents first, query last. This improves quality by up to 30% on multi-document inputs. (Anthropic)
# before:
- Question: {{USER_QUERY}}
- Context: {{DOCUMENTS}}
- Answer based on the context above.
# after:
+ <context>
+ {{DOCUMENTS}}
+ </context>
+ Question: {{USER_QUERY}}
+ Answer based on the context above.
/text-optimizer prompt-template.md
The optimizer wraps {{VARIABLE}} sections in XML tags. Without boundaries, injected user content can look like system instructions — this is the most reliable prompt injection defense. (Anthropic)
# before — no boundaries:
- You are a helpful assistant.
- User message: {{USER_INPUT}}
- Respond helpfully.
# after — XML-wrapped:
+ You are a helpful assistant.
+ <user-message>
+ {{USER_INPUT}}
+ </user-message>
+ Respond helpfully.
-l)Text cleanup without restructuring. Safe for stable, reviewed documents.
Applies: Claude behavior rules (C.1-C.8), filler removal (T.6), exact-dup removal (D.1), reference checks (R.1-R.3), perception basics (P.1-P.4).
Skips: Table/bullet restructuring, XML tags, section merging.
Use for: Production prompts where structure is intentional, docs that have been through review.
Balanced restructuring — all 48 lossless rules applied with standard transformations.
Applies: All categories (C + T + S + D + R + P + L).
Use for: Most files — CLAUDE.md, agent instructions, skill definitions, technical docs.
-d)Maximum compression. Merges sections, rephrases aggressively, eliminates all redundancy.
Applies: All rules + aggressive lossy pass (A.1-A.4: line fusion, word drop, paraphrase, common-knowledge elision) with section merging. Self-verify round: fact inventory, >= 95% match, loss list on shortfall.
Use for: Cost-critical system prompts, context-limited scenarios. Review the diff carefully after.
| Input (100 lines) | Light | Medium | Deep | |--------------------|-------|--------|------| | Prose documentation | ~10% savings | ~40% | ~50% | | System prompts | ~15% savings | ~35% | ~45% | | Technical specs | ~5% savings | ~25% | ~30% |
| Category | Count | What it covers | |----------|-------|----------------| | Claude behavior | 8 | How Claude 4.x interprets instructions differently | | Token efficiency | 9 | Structural compression without information loss | | Structure | 8 | Organization patterns LLMs parse better | | Deduplication | 6 | Merging repeats without losing emphasis or distinct facts | | Reference integrity | 3 | Catching broken paths, URLs, circular refs | | Perception | 6 | Visual hierarchy and attention patterns | | LLM comprehension | 8 | Position bias, grounding, repetition effects + scope-qualifier preservation | | Aggressive lossy | 4 | Deep-mode only: line fusion, word drop, paraphrase, common-knowledge elision (ledgered) |
Full rules with research citations: references/rules-review.md
This skill is extracted from brewcode — a development platform for Claude Code with infinite focus tasks, 16 agents, quorum reviews, and knowledge persistence.
claude plugin marketplace add https://github.com/kochetkov-ma/claude-brewcode
claude plugin install brewcode@claude-brewcode
MIT
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer