ha:output-compression
Reduce pytest/mypy/ruff/hassfest output noise (5-15% token savings) by installing rtk filters that compress test/lint/typecheck/hassfest output before it reaches Claude. Use when long CLI output flood
SKILL.mdskills/output-compression/SKILL.md
GitHubOutput Compression
Home Assistant toolchain commands (pytest tests/components/<domain>/,
ruff check ., mypy homeassistant/components/<domain>/,
python3 -m script.hassfest) emit verbose, repetitive output that consumes
context fast. This skill installs rtk — a CLI
proxy that filters tool output before it lands in the transcript.
The filters short-circuit happy paths to a single line (pytest: all pass)
while preserving full failure blocks, diagnostics, and tracebacks. Net win:
5-15% per-session token reduction on test/lint/hassfest-heavy workflows.
When to use
- Long sessions —
/ha:workor/ha:fullhitting context limits from pytest/ruff/mypy output - Debugging loops —
/ha:investigateretryingmypy homeassistant/components/<domain>//pytestrepeatedly - Type-check-heavy work —
mypy homeassistant/components/<domain>/output dominates the transcript
Iron Laws
- NEVER strip critical signals — test failures (
FAILED,= N failed), mypy errors (error:,Found N errors), ruff violations (rule codes likeF401), hassfest errors, and tracebacks withfile:lineMUST pass through unchanged - Verify after install — run
rtk verify(orrtk verify --filter pytest) to confirm the bundled test fixtures pass before declaring success - Never overwrite existing
.rtk/filters.toml— diff and merge instead
Workflow
Step 1: Detect rtk
which rtk && rtk --version
Read ${CLAUDE_SKILL_DIR}/references/install.md if rtk is missing — covers
homebrew install + shell hook setup.
Step 2: Seed .rtk/filters.toml
Reference filters live at ${CLAUDE_SKILL_DIR}/references/rtk-filters.toml. Six
production-tested filters covering:
pytest— short-circuits all-pass, preserves failure blocks + tracebacksruff— collapses clean runs, preserves rule-tagged violation blocksmypy— drops progress noise, keeps errors + summarypip-install— collapses "already satisfied" dependency treeshassfest— strips validation progress, short-circuits clean runsprek— collapses all-pass hook runs, preserves failed-hook output
Run this if the project has no .rtk/filters.toml yet:
mkdir -p .rtk
cp "${CLAUDE_SKILL_DIR}/references/rtk-filters.toml" .rtk/filters.toml
Read both files if one already exists. Present a diff to the user. Merge only the filters they don't already have.
Step 3: Verify filters work
rtk verify # runs all embedded [[tests.*]] fixtures
rtk verify --filter pytest # one filter only
Check that all report "passed". Flag and stop if any fail — usually means the user has a custom rtk version with regex differences.
Step 4: Confirm shell hook
Run rtk init zsh (or rtk init bash) to install the transparent rewrite hook
that turns pytest X/ruff X/mypy X into rtk pytest X/rtk ruff X/etc.
Re-running is safe (idempotent). Skip this step and the commands run unfiltered.
Customization
Add custom regex patterns to strip_lines_matching for project-specific noise
sources (e.g., third-party libraries in site-packages spamming warnings or
deprecation notices). See the inline example in
${CLAUDE_SKILL_DIR}/references/rtk-filters.toml (the commented
strip_lines_matching example in [filters.pytest]).
What this is NOT
- Not a hook — Claude Code's
PostToolUsehooks fire after the tool result is in the transcript and cannot shrink it. rtk works at the subprocess layer (the only layer where transcript-shortening is possible). - Not project-analysis — the bundled filter set is universal across HA
integration and ha-frontend projects. No
manifest.jsoninspection needed. - Not telemetry — rtk has telemetry off by default (
enabled = falseinconfig.toml). Filters run locally, no data leaves the machine.
References
${CLAUDE_SKILL_DIR}/references/rtk-filters.toml— bundled filter set${CLAUDE_SKILL_DIR}/references/install.md— rtk install + shell hook setup- rtk on GitHub