An autonomous AI agent skill and operational protocol designed to slash agentic context bloat, eliminate "context rot", and reduce per-task LLM token usage.
Derived from published research on the Pi Coding Agent (pi.dev) and Databricks MemEx (Programmable Scratchpad Kernel).
Try the latest Z.ai GLM-5.2 & other GLM Models via Coding Plan using my invite token!
๐ 10% OFF Z.ai GLM Coding Models at Z.ai
We benchmarked the protocol on a greenfield Python CLI project (taskcli with SQLite storage & 12 pytest suites) built inside Trae Work IDE / Trae Agent Engine:
| Metric | ๐ด Native Trae Agent | ๐ข Trae Agent + Protocol v3 | Improvement / Impact |
|---|---|---|---|
| Wall-Clock Build Time | 83.9s | 47.1s | 43.9% Faster Build |
| Verification Output Volume (DTOC) | 1,847 Bytes | 190 Bytes | 9.7x Compression (DTOC) |
| Token Proxy (Code + Verify / 4) | ~2,254 tokens | ~1,513 tokens | 32.9% Token Savings |
| Code Footprint (Bytes) | 7,168 B (263 LOC) | 5,861 B (232 LOC) | 18.2% Smaller Footprint |
| Conversation Round-Trips | 5 messages | 3 messages | 40.0% Fewer Round-Trips |
| Pytest Suite Status | 12/12 Passed | 12/12 Passed | 100% Green Test Suite |
๐ Interactive Report: View the full interactive Chart.js benchmark dashboard in examples/trae-work-benchmark/index.html.
We executed a controlled 3-way benchmark comparison on the 3D Sand Clock codebase (index.html, 828 lines) comparing:
- Native Antigravity (Default / Un-optimized harness)
- Headroom AI (
headroomlabs-ai/headroom- Reactive HTTP Proxy CCR Compression) - Protocol v3 Skill (Our Proactive AST-First + DTOC + Line-Range Protocol)
| Benchmark Metric | ๐ด Native Antigravity | ๐ก Headroom AI (headroomlabs-ai) |
๐ข Protocol v3 Skill (Our Skill) | Savings / Impact |
|---|---|---|---|---|
| Execution Architecture | Unfiltered File Dumps | Reactive Post-Tool CCR Proxy | Proactive AST Search + Range Reads | Source-Level Prevention |
| Source Lines Ingested | 1,776 lines | 1,357 lines (18% drop) | 63 lines | 96.5% line reduction |
| Cumulative Billed Tokens | 45,770 tokens | 37,430 tokens (18.2% drop) | 451 tokens | 99.0% token reduction |
| Task API Cost ($) | $0.1373 | $0.1123 (1.2x cheaper) | $0.0014 | 101.5x Cheaper than Native |
| Efficiency Ratio | Baseline (1.0x) | 1.2x Cheaper | 101.5x Cheaper | 83.0x Cheaper than Headroom! |
==================================================================
๐ 3-WAY COMPARISON SUMMARY
==================================================================
Native Antigravity : 45,770 tokens | $0.1373
Headroom AI : 37,430 tokens | $0.1123 (1.2x cheaper than Native)
Protocol v3 Skill : 451 tokens | $0.0014 (101.5x cheaper than Native | 83.0x cheaper than Headroom!)
==================================================================
- Headroom AI is a reactive proxy: It compresses large tool outputs after the tool returns them. When an agent reads an 800-line file, Headroom compresses it to ~650 lines of AST/JSON summary. The agent still ingests thousands of tokens per turn.
- Protocol v3 is a proactive behavioral protocol: Instead of reading 800 lines and compressing them down to 650 lines, Protocol v3 runs
grepto pinpoint the exact 20 lines needed and reads only those 20 lines (~150 tokens), preventing 99% of unneeded tokens from ever touching the context window!
Check out the full WebGL interactive demo application in examples/sand-clock-3d/:
- ๐ฎ Live WebGL 3D Physics: Three.js 3D hourglass model with 2,500 glowing sand particles, glass refraction shaders, 180ยฐ flip mechanics, and preset timers.
- โก Live Side-by-Side Comparison: Renders the Protocol v3.0 Smart Agent vs Naรฏve 280k Context Dump Agent side-by-side on one page.
To run locally:
python3 -m http.server 8085 --directory examples/sand-clock-3d
# Open http://localhost:8085 in your browserThis skill works seamlessly across all major AI coding agents, IDEs, CLI tools, and agentic frameworks:
| Harness / IDE / CLI | Integration Method | Adapter File |
|---|---|---|
| Trae Work IDE / Trae Agent | .traerules or TRAE.md |
adapters/trae.md |
| Z.ai ZCode / GLM Harness | Global AGENTS.md or .zcoderules |
adapters/zcode.md |
| Claude Code / Claude CLI | Global skill (~/.claude/skills/) or CLAUDE.md |
adapters/claude-code.md |
| Kimi Code (Moonshot AI) | .kimirules or KIMI.md |
adapters/kimi.md |
| Koda Agent Engine | .kodarules or KODA.md |
adapters/koda.md |
| Mimo Agent Framework | .mimorules or MIMO.md |
adapters/mimo.md |
| Google Antigravity / Gemini CLI | Auto-detected from ~/.agents/skills/ |
SKILL.md |
| Cursor IDE | Project .cursorrules |
adapters/cursorrules |
| Windsurf IDE | Project .windsurfrules |
adapters/cursorrules |
| Cline / Roo Code (VS Code) | .clinerules or .roomodes |
adapters/clinerules |
| Aider / OpenHands | System prompt or .aider.conf.yml |
adapters/universal-system-prompt.md |
| Custom Agents (LangChain, AutoGen, CrewAI) | LLM System Prompt Snippet | adapters/universal-system-prompt.md |
| Agent Architecture | Context Management Strategy | Avg Context Load / Task | Cost / Bug Fix Task | Pass Rate |
|---|---|---|---|---|
| Trae Work IDE + Token Protocol | DTOC + Batched Verification | ~1,513 tokens (est.) | ~$0.02 | 12/12 Passed |
| Z.ai ZCode + Smart AST Harness | AST-First + DTOC (GLM 5.2) | ~35,000 tokens | $1.28 | 87% (Opus parity) |
| Claude Code + Token Protocol | AST-First + DTOC | ~35,000 tokens | ~$0.30 | High |
| Kimi Code + Token Protocol | JIT Line-Range Reads | ~36,000 tokens | ~$0.28 | High |
| Koda / Mimo + Token Protocol | Filtered Command Streams | ~35,000 tokens | ~$0.25 | High |
| Legacy Context Dump | 120k static window dumps (Opus 4.8) | ~120,000 tokens | $1.94 | 87% |
| Bloated Context Loop | 280k raw context loop (Sonnet 5) | ~280,000 tokens | $2.09 | 85% |
| Antigravity + Token Protocol | AST-First + DTOC + Line-Range Reads | ~37,000 tokens | ~$0.30 | High |
Pi (pi-coding-agent) |
ast-grep + localized diffs |
~35,000 tokens | ~$0.28 | High |
| Databricks MemEx | Typed Python kernel object state | ~30,000 tokens | ~$0.25 | High |
Enforces precise per-output limits to prevent log pollution:
- File listings (
ls,find): Max 20 lines (| head -n 20) - Process lists (
ps,pstree): Max 15 lines (| head -n 15) - Config dumps (
json,yaml): Max 80 lines (| head -n 80) - Log outputs: Max 30 lines (
| tail -n 30) - Diff output: Max 100 lines (
| head -n 100) - Over-limit summary protocol:
"Output was N lines. Key findings: [2-3 bullet points]."
Always start at Tier 1 before loading file contents:
- Tier 1 (Discover):
ls -la dir/ | head -n 20,find dir/ -maxdepth 2 -type f | head -n 20,grep -rl 'keyword' dir/ | head -n 10 - Tier 2 (Target):
grep -n 'function' file,sed -n '1,50p' file,wc -l file - Tier 3 (Execute):
sed -n '78,134p' fileโ targeted range edit โ verify
Explicitly forbids sending full file contents, directory trees, or previous conversation history to subagents. Uses a structured 6-field prompt template:
// โ
GOOD: Sends structured line ranges & scoped task
agent({
prompt: `Task: refactor login handler in src/auth/login.ts
File: src/auth/login.ts (847 lines)
Structure: Lines 78-134 (loginHandler)
Relevant excerpt: ${readLines('src/auth/login.ts', 78, 134)}
Constraints: Do not modify session token generator
Output format: Return refactored function block only.`
});Maintains structured memory of retrieved file sections with โ completion markers and a [PENDING] queue to avoid duplicate token consumption:
[SESSION CACHE โ files read this session]
src/main.ts (lines 1-45, 120-200) โ
package.json (full, 87 lines) โ
[PENDING โ not yet read but referenced]
src/config.ts โ mentioned in main.ts imports
Provides structured [PHASE COMPLETE: task_name] transition blocks with --- DISCARDED --- markers.
Includes a Context Budget Per Phase breakdown:
- Discovery: ~4,000 tokens
- Planning: ~8,000 tokens
- Execution: ~12,000 tokens
- Verification: ~4,000 tokens
- Summary: ~2,000 tokens
When context usage exceeds 80%, agents emit a [CONTEXT COMPRESS] block and flush intermediate tool outputs.
| Want to... | Do this FIRST | Only if that fails... |
|---|---|---|
| Find where X is defined | grep -rn 'X' src/ | head -20 |
grep -rn 'X|Y' regex search |
| Understand a file structure | wc -l f; grep -n 'func|class|export' f |
sed -n '1,50p' f header read |
| Read specific line section | sed -n 'N,Mp' file |
Read(file, offset=N, limit=M-N) |
| List directory contents | ls -la dir/ | head -20 |
find dir/ -maxdepth 2 -type f | head -20 |
| Check process status | ps aux --sort=-%mem | head -15 |
Never use bare ps aux |
| Inspect configuration file | head -n 80 config.json |
jq '.key.subkey' config.json |
| Handle large command output | | head -n 30 or | tail -n 20 |
Summarize output in 2 bullet points |
| Dispatch a subagent | Scoped 6-field template with line ranges | Never send full files or context |
| Re-examine a file | Check session cache, read delta range | Never re-read identical line range |
See adapters/ for drop-in configuration files:
- Trae Work IDE:
adapters/trae.md - Z.ai ZCode:
adapters/zcode.md - Claude Code:
adapters/claude-code.md - Kimi Code:
adapters/kimi.md - Koda Agent:
adapters/koda.md - Mimo Framework:
adapters/mimo.md - Cursor / Windsurf:
adapters/cursorrules - Cline / Roo Code:
adapters/clinerules - Universal LLMs:
adapters/universal-system-prompt.md
Distributed under the MIT License. Free for personal and commercial use.