/major-ai-skills:head-tail-log-clippingfrom major-ai-skills
Keep the opening context and final diagnostics of large logs, with omitted content clearly identified and available if needed.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When running large test suites, Docker image builds, or package installations (npm test, cargo test, docker build), terminal commands frequently generate 500 to 5,000 lines of output.
In 99% of software failures, the critical diagnostic information is distributed in two places:
The middle 90% of the log consists of redundant progress meters ("Passing test 1..140", "Downloading layer 4a3f..."). Ingesting unclipped logs burns 10,000+ tokens per failure turn.
The Head/Tail Log Clipping Protocol (also known as the Sandwich Truncation Protocol) extracts the Head and Tail while replacing the middle with a compact tombstone count.
┌─────────────────────────────────────────────────────────────┐
│ Log Stream Ingestion Impact │
│ │
│ Unclipped Terminal Log (3,000 Lines / 18,500 Tokens): │
│ • Lines 1-20: `pytest tests/` (Environment info) │
│ • Lines 21-2950: 2,930 lines of passing green dots / tests │
│ • Lines 2951-3000: AssertionError on line 42 │
│ ↳ 18,500 tokens billed, agent loses attention in middle │
│ │
│ Sandwich Truncated Log (60 Lines / 420 Tokens - 97.7% Cut):│
│ === HEAD (Lines 1-20) === │
│ pytest tests/auth/ -v --color=no │
│ [... 2,930 passing test lines truncated for efficiency ...]│
│ === TAIL (Lines 2960-3000) === │
│ FAILED tests/auth/test_jwt.py::test_expiry - AssertionError │
│ ↳ 420 tokens billed, instant pinpoint fix on test_jwt.py │
└─────────────────────────────────────────────────────────────┘
For optimal token economy and diagnostic completeness:
┌───────────────────────────────────────────────────────────────────────────┐
│ • HEAD LINES ($H$): 20 lines (Command, Flags, Environment) │
│ • MIDDLE TOMBSTONE: `[... <N> lines truncated for token efficiency ...]` │
│ • TAIL LINES ($T$): 40 lines (Assertion, Traceback, Summary) │
│ • TOTAL RETAINED: 60 lines max ($\le 500$ tokens) │
└───────────────────────────────────────────────────────────────────────────┘
from typing import Optional
def clip_log_sandwich(
raw_output: str,
head_count: int = 20,
tail_count: int = 40
) -> str:
"""Clips large terminal output into a token-efficient Head/Tail sandwich."""
lines = raw_output.splitlines()
total_lines = len(lines)
# If log is already small, return untouched
if total_lines <= (head_count + tail_count):
return raw_output.strip()
head_lines = lines[:head_count]
tail_lines = lines[-tail_count:]
omitted_count = total_lines - (head_count + tail_count)
return (
f"{chr(10).join(head_lines)}\n\n"
f"--- [LOG TRUNCATED: {omitted_count} intermediate lines omitted for context efficiency] ---\n\n"
f"{chr(10).join(tail_lines)}"
)
For agent terminal wrappers:
# Bash: Capture head and tail in one pipeline
pytest tests/ | (head -n 20; echo "[... intermediate logs elided ...]"; tail -n 40)
Running a full Jest test suite across 40 test suites (3,200 lines of output):
| Strategy | Output Tokens Ingested | Diagnostic Accuracy | Latency |
|---|---|---|---|
| Unclipped Raw Output | 19,400 tokens | 88% (Distracted by middle logs) | 4.2 seconds |
Tail-Only (tail -n 50) | 350 tokens | 74% (Lost command arguments) | 0.2 seconds |
| Sandwich Head/Tail Protocol | 480 tokens | 100% (Full context preserved) | 0.3 seconds (97.5% Savings!) |
MANDATORY: Agent tool runners intercepting stdout from commands exceeding 100 lines MUST apply Head/Tail sandwich truncation ($H=20, T=40$) prior to returning the result into LLM context.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization.Other plugins' skills for the same job
/act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.