PLUGIN brewtools / Skills
On this page
context-slim — shrink potential context sources
Discovery is not proof of loaded context. The scan inventories potential sources (startup instructions, rules, AGENTS.md, memory, agent definitions, skill resources). Path-scoped rules load conditionally. Use measure for inventory sizes, then inspect runtime context before claiming actual session cost.
Quick reference
| Field | Value |
|---|---|
| Command | /brewtools:context-slim |
| Arguments | [prompt] [measure|preview|slim|hard|bodies|restore] [--target=N%] [--global] [--memory] [--noask] [ts] |
| Model | opus |
| Context | session |
| Tools | Read, Edit, Write, Bash, Grep, Glob, Agent, AskUserQuestion |
What it does
Three levers in one pass: cross-layer dedup, generic-knowledge removal, per-file compression. The skill never drops an exact value, key, path, version pin or != prohibition. If the verification gate finds one missing, the run rolls back in full and reports FAILED.
A bare invocation measures and reports without edits. slim, hard and bodies take a byte-exact snapshot first. MCP servers, plugin enablement and settings.json are never mutated, only advised in the report.
When to use
| Scenario | Command |
|---|---|
| CLAUDE.md keeps growing | /brewtools:context-slim (measure first) |
| Rules duplicate across files | /brewtools:context-slim preview |
| Skill or agent bodies feel bloated | /brewtools:context-slim bodies slim |
| A prior pass was not aggressive enough | /brewtools:context-slim hard --target=30% |
| Something broke after a run | /brewtools:context-slim restore last |
Examples
# Measure only: no writes, no questions
/brewtools:context-slim
# Free-form prompt, resolved to slim from keywords
/brewtools:context-slim shrink the context, remove duplicates in the rules
# Target ratio including the global layer (asks to confirm the global write)
/brewtools:context-slim slim --target=30% --global
Modes
| Mode | What it does | Mutates? |
|---|---|---|
measure | Reports potential inventory size proxies per tier and file, not loaded-context tokens. Default with empty input | no |
preview | Runs discovery through the dedup analysis and prints the projected plan and token delta | no |
slim | Full lossless compression: dedup, default-knowledge removal, per-file rewrite, verify | yes |
hard | Same as slim; when a --target is not met losslessly, the escalation gate (fires in any mutating mode) may cut further | yes, destructive |
bodies | Extends scope to SKILL.md and references/*.md. Alone it means bodies + slim | yes |
restore | Prior-snapshot recovery using last, a timestamp or --run-dir; refuses unsafe overwrites | yes, destructive |
Flow
- Resolve mode and scope
Parses the prompt and flags; asks at most one
AskUserQuestion. Destructive and global-write confirmations always fire. - Discover and measure
context-scan.shreports per-file sizes (bytes/4 proxy, not a tokenizer).measurestops here. - Snapshot, fail-closed
Copies targets byte-exact under
~/.claude/backups/. A dirty tracked target refuses the run and names the paths. - Dedup analysis
Mechanical prefilter plus an LLM judgment pass yields a drop/keep list.
previewstops here. - Compress and verify
One text-optimizer per file, then independent comparison against the originals. A miss fails acceptance and triggers recovery.
- Re-measure and report
Compares with phase 1, asks once before a lossy pass on an unmet target, then writes ratchet state and the report.
Safety and rollback #
Every mutating run is snapshotted before a byte is written. The project layer is gated on a clean git tree over tracked targets; untracked or ignored files are still snapshotted (SNAPSHOT-ONLY, never refused). The global layer gets its own snapshot under ~/.claude/backups/<ts>-global_context-slim/.
Recovery validates the prior manifest and the recorded owned drafts across all touched layers. Missing state, damaged originals or bytes changed by another writer prevent restoration; no checkpoint is created at failure time to bypass that.
| Fact | Behavior |
|---|---|
| Retention | Keeps the newest 5 runs (all layer dirs of one timestamp); never prunes a run under 24 h old |
| Collisions | Dir name is <YYYYMMDD-HHMMSS>-<layer>_context-slim; a repeat gets a -2, -3 suffix |
.gitignore | In a git root the guard appends .claude/reports/ (creating the file); restore never reverts it and it shows in git status |
| Layer pick | restore last covers every layer of the newest run; restore --global last targets the newest global run even if a project run shares its second |
/brewtools:context-slim restore last
/brewtools:context-slim restore --global last Technical details and what it never touches #
Recursive discovery follows linked directories, detects cycles and unsafe paths, and reports an incomplete scan as partial: no totals, savings or run state are published from it.
Verification runs context-guard.sh verify --ledger: a missing token is accepted only when a ledger row covers it and its survivor still carries it. A block between another tool’s begin/end markers (for example BEGIN brewcode:semble) is never compressed, moved or deleted and is reported as managed by <setup>. When a global copy covers a git-tracked project copy, both are kept.
| Surface | Handling |
|---|---|
MCP servers, plugin enablement, settings.json | Signal only: advice in the final report, never mutated |
~/.claude/plugins/cache/** | Read for signals, never written |
The chars/4 label is a bytes/4 inventory proxy, not measured token savings. MCP server count alone does not establish context cost.
Text Optimize
The per-file compression subagent context-slim fans out to.
GitHub source
Source code, scripts and the decision-rule reference set.
Brewtools overview
Commands, models and arguments for every brewtools skill.
Update: /brewtools:plugin-update, /reload-plugins, then /brewcode:setup-status upgrade - FAQ