Skip to content
Back to skills

Headroom

ASecurity

Context compression for YAMTAM — nén JSON/structured tool output trước khi vào LLM. Hiệu quả với JSON (50-72% tiết kiệm); text thuần cần bản [all].

  • 28 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 8, 2026
ai-agentstypescriptpythonbashnodegitapi

Works with

  • claude code
  • api
  • mcp

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned November 8, 2026

npx -y skills add majiayu000/claude-skill-registry-data --skill headroom --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Headroom?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Headroom
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-headroom/badge)](https://www.skillsdirectory.com/skills/majiayu000-headroom)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: headroom
description: Context compression for YAMTAM — nén JSON/structured tool output trước khi vào LLM. Hiệu quả với JSON (50-72% tiết kiệm); text thuần cần bản [all].
triggers:
  - headroom
  - compress context
  - nén context
  - giảm token
  - context quá dài
  - tool output lớn
  - context window full
---

# headroom — Context Compression

**Package**: `headroom-ai` v0.22.4 (PyPI + npm)
**License**: Apache 2.0
**Source**: github.com/chopratejas/headroom

## Hiệu quả thực tế (đã test v0.22.4)

| Input type | Kết quả |
|---|---|
| JSON phẳng (100 items) | **~72%** tiết kiệm ✅ |
| JSON lồng (50 items) | **~53%** tiết kiệm ✅ |
| Text thuần, git log | 0% — cần `[all]` extras |
| Conversation history | 0% — `protect_recent` giữ nguyên |

**Khi nào dùng:** API response, RAG chunks, MANIFEST/JSON lớn.
**Không nên dùng cho:** git log thuần, prose, file .md.

## Cách dùng đúng

### 1. JSON / API response (hoạt động tốt nhất)

```python
from headroom import compress
import json

# Nén JSON response trước khi đưa vào messages
data = json.dumps(large_api_response)
messages = [{"role": "user", "content": data}]

result = compress(messages, compress_user_messages=True, target_ratio=0.3)
print(f"{result.tokens_before:,} → {result.tokens_after:,} tokens ({result.compression_ratio*100:.1f}%)")

# Dùng messages đã nén
compressed = result.messages
```

### 2. Context gần đầy — auto compress khi cần

```python
from headroom import compress

# headroom chỉ nén khi tokens gần model_limit
# Mặc định: model="claude-sonnet-4-5", limit=200K
result = compress(messages)  # nén nếu > 80% limit

# Chỉ định model cụ thể
result = compress(messages, model="claude-opus-4-20250514")
```

### 3. Force compress (không quan tâm đến limit)

```python
result = compress(
    messages,
    compress_user_messages=True,  # compress cả user messages
    target_ratio=0.3,              # giữ lại 30% tokens
    protect_recent=0,              # không bảo vệ messages gần đây
)
```

### 4. Wrap Claude Code (cần `[all]`)

```bash
pip install "headroom-ai[all]"
headroom wrap claude        # wrap Claude Code — nén tự động
headroom proxy --port 8787  # drop-in proxy, zero code change
```

### 5. MCP Server

```bash
headroom mcp install
# Tools: headroom_compress, headroom_retrieve, headroom_stats
```

## Tích hợp YAMTAM hooks

```json
{
  "type": "command",
  "command": "headroom init hook ensure",
  "timeout": 15
}
```

## Install

```bash
pip install headroom-ai            # base: JSON compression
pip install "headroom-ai[all]"    # full: proxy + MCP + ML (text compression)
npm install headroom-ai            # TypeScript/Node
```

## Anti-Fake-Pass

- `compress(messages)` với messages nhỏ → 0% (bình thường, chưa cần nén)
- `compress_user_messages=True` bắt buộc để nén user messages
- Text thuần không nén được bằng base package — đừng ghi "60-95%" khi chưa test
- `compression_ratio` = 1 - (after/before), không phải phần trăm tiết kiệm trực tiếp

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.