Subprocess Filter
Compress noisy output before your agent reads it
npx promptreports-cli filter -- <cmd>Wraps any shell command. Captures stdout/stderr, strips ANSI, collapses repeated lines, elides long stack traces, and truncates uniform blocks. Errors pass through. Exit code preserved.
Your agent reads every byte your test suite, build, or linter prints — at input-token prices. Most of it is noise: 400 passing test lines, 80 identical stack frames, ANSI color codes. This command spawns your subprocess, captures both streams, and compresses before your agent ever sees it. Errors and warnings always pass through untouched. The tail is always preserved (configurable). The exit code is the subprocess exit code. Works with any CLI: jest, playwright, docker, webpack, cargo, anything.
On this page
Prerequisites
- Node.js >= 18
Flags & Options
| Flag | Description | Default |
|---|---|---|
| --keep-last N | Lines to preserve at tail | 20 |
| --max-repeat N | Threshold before collapsing duplicates | 2 |
| --truncate-after N | Lines before uniform-block truncation | 50 |
| --json | Emit reduction stats as JSON to stderr | — |
| --quiet | Suppress the reduction summary | — |
Examples
Filter Jest output
npx promptreports-cli filter -- npm testCollapse passing tests, preserve failures, truncate stack traces.
Filter Playwright
npx promptreports-cli filter -- playwright testHandles the long list-reporter output agents choke on.
Filter Docker build
npx promptreports-cli filter -- docker build .Docker emits hundreds of step-progress lines. Crush them.
More tail context
npx promptreports-cli filter --keep-last 50 -- npm run ciKeep 50 lines of tail for CI debugging.
Pipe stats elsewhere
npx promptreports-cli filter --json -- npm test 2>stats.jsonCapture reduction metrics without polluting the output.
Output
Compressed subprocess output followed by a reduction summary (lines in → out, percent saved). Exit code passes through so CI still breaks correctly on failure.
filter: running npm test
PASS src/utils/parse.test.ts
PASS src/utils/format.test.ts
PASS src/commands/summary.test.ts
[... 47 similar lines elided ...]
FAIL src/commands/push.test.ts
● should dedupe turns
expect(received).toEqual(expected)
at Object.<anonymous> (src/commands/push.test.ts:42:21)
[... 18 stack frames elided ...]
at processTicksAndRejections (node:internal/process)
Test Suites: 1 failed, 49 passed, 50 total
Tests: 1 failed, 423 passed, 424 total
filter: 1,847 lines in → 142 out (92.3% reduction) exit 1What it reads and writes
Reads
- Subprocess stdout/stderr (streamed, never written to disk)
Writes
Nothing (read-only)
Free vs Pro usage
Free tier
- Wrap any CLI command your agent invokes to cut token burn
- Get back the tail of a long build without the middle
- Keep stack traces actionable by preserving first/last frames
Pro tier
Upgrade- Push reduction stats to a team dashboard to quantify savings
- Enforce filter-wrapping via agent hooks/presets
- A/B compare pre- and post-filter token spend in dashboards
Pro tips
- If your agent hits the 200K context wall on a single command, wrap it in filter
- Pass --keep-last 100 for CI debugging when you need more tail context
- Failing tests always pass through — never worry about missing the real error