Trim noisy terminal output before it reaches your AI coding agent
Project description
sniptrace
Trim noisy terminal output before it reaches your AI coding agent. Save tokens, reduce LLM costs, and keep context windows focused on what matters.
pip install sniptrace
Quick start
Filter a string you already have
from sniptrace import filter_text
raw_output = captured_stderr # string from your agent's code execution
clean = filter_text(raw_output)
llm.complete(f"Fix this error:\n{clean}")
Run a command and get filtered output
from sniptrace import run
result = run(["pytest", "tests/"])
if not result.ok:
llm.complete(f"Fix this error:\n{result.output}")
# result.output has no progress bars, no site-packages frames, no noise
What gets filtered
SnipTrace removes known low-signal output patterns from:
- Python — stdlib/venv traceback frames, pip install chatter
- Node / JS — npm/pnpm/yarn deprecation warnings, progress lines
- Docker — BuildKit step lines, layer pull progress
- pytest / Jest / Vitest — session headers, progress dots, PASSED lines
- Cargo / Gradle / Maven — compile progress,
[INFO]lines - Generic — ANSI escape codes, progress bars, spinner frames, update banners
Lines containing error signals (error, traceback, exception, failed, cannot, etc.) are always preserved, even if they match a strip pattern.
API
filter_text(text: str) -> str
Filter an already-captured string. No CLI required — all filtering is pure Python.
from sniptrace import filter_text
clean = filter_text(raw_stderr)
run(command, *, cwd=None, env=None, timeout=None) -> SnipResult
Run a command and return filtered output. Uses the sniptrace CLI if installed (preserves telemetry), otherwise filters natively in Python.
from sniptrace import run
result = run(["pytest", "-q", "tests/"])
print(result.output) # filtered output
print(result.ok) # True if exit code was 0
print(result.reduction_pct) # e.g. 87.3
print(result.bytes_saved) # original_bytes - filtered_bytes
SnipResult
@dataclass
class SnipResult:
exit_code: int
output: str
original_bytes: int
filtered_bytes: int
reduction_pct: float
filtered: bool # False if filtering was skipped
@property
def ok(self) -> bool: ... # exit_code == 0
@property
def bytes_saved(self) -> int: ... # original_bytes - filtered_bytes
is_available() -> bool
Returns True if the sniptrace CLI is installed on PATH.
Typical agent loop
from sniptrace import run
def agent_loop(task: str, llm, max_rounds: int = 5):
code = llm.complete(f"Write Python code to: {task}")
for _ in range(max_rounds):
write_to_disk(code)
result = run(["python", "solution.py"])
if result.ok:
return code # done
code = llm.complete(
f"The code produced this error:\n{result.output}\n\nFix it."
)
return code
Zero dependencies
The package uses only the Python standard library. No external packages required.
Install the CLI (optional)
The CLI is optional — filter_text() and run() both work without it. The CLI adds telemetry (token savings counter) and shell wrappers for automatic filtering in your terminal.
curl -fsSL https://sniptrace.com/install.sh | sh
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sniptrace-1.2.0.tar.gz.
File metadata
- Download URL: sniptrace-1.2.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0c56fb63318ddd8c0bf241858a40224b9f1bad8ec3fba105c5d38835c80b4d7
|
|
| MD5 |
5203d877a110fc04f1a8a5884c362e4f
|
|
| BLAKE2b-256 |
036d7127fc57a38da63b10ea5a7374152e42875b91bf0b167b492ed57cf23d62
|
File details
Details for the file sniptrace-1.2.0-py3-none-any.whl.
File metadata
- Download URL: sniptrace-1.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f106b0c6951b7f51ed58a7cebafec5f263d45aeb681189c4d7323909667338e1
|
|
| MD5 |
af9da0595fef88b6d1f36fcbb0f20610
|
|
| BLAKE2b-256 |
dbd54f01989c5fab391eafd1b57677ab38c031dfb40bd7ccf6856d35c3607a18
|