lean-ctx defines 5 protocols that govern how context is managed, compressed, communicated, and shared between agents. They activate automatically based on session state, but understanding them helps you get the most out of the system.
Protocol Map
| Protocol | Full Name | When It Activates | What It Does |
|---|---|---|---|
CEP | Context Engineering Protocol | Every session (system prompt) | 5 rules for efficient context usage: act first, delta only, structured notation, one line per action, quality anchor |
CCP | Context Checkpoint Protocol | Every ~15 tool calls (auto) or manual | Creates compressed session snapshots that survive context window truncation |
TDD/CRP | Terse Data Density / Context Reduction Protocol | When CRP_MODE=tdd is set | Maximum compression: abbreviated keywords, symbol maps, diff-only output |
CLP | Context Layered Preload | Session start with ctx_preload | Intelligently pre-loads relevant files based on task description |
A2A | Agent-to-Agent | Multi-agent sessions | Message bus, shared cache, task delegation, diary persistence |
CEP - Context Engineering Protocol
CEP is injected into every session's system prompt. It establishes 5 core rules that reduce token waste from the LLM itself:
- ACT FIRST: Execute tool calls before explaining. Avoid narration before action.
- DELTA ONLY: Use file references (F1, F2...) instead of repeating paths. Show only changed code.
- STRUCTURED: Use
+(add),-(remove),~(modify) notation. - ONE LINE PER ACTION: Keep each action to a single line for scan-ability.
- QUALITY ANCHOR: Never skip edge cases, never use mock data, never placeholder.
CCP - Context Checkpoint Protocol
CCP automatically creates compressed session snapshots every ~15 tool calls. These checkpoints capture:
- Cached files with their F-references and content hashes
- Active session state (task, workflow, knowledge)
- File signatures for quick recovery
When the context window is truncated (common in long sessions), the checkpoint allows the agent to recover its full working state without re-reading all files.
TDD / CRP - Terse Data Density Mode
Activated when CRP_MODE=tdd is set in the environment or config.
Applies maximum compression to all lean-ctx output:
- Abbreviated keywords:
fn,cfg,impl,deps,req,res,ctx,err - Type shortcuts:
:s(string),:n(number),:b(boolean) - Symbol map tables (
§MAP) for long identifiers → short IDs (α1,α2...) - Diff-only output (
+/-/~notation) - Budget target: ≤150 tokens per response, zero narration
CLP - Context Layered Preload
CLP activates when you call ctx_preload at session start. It analyzes your task
description and the project structure to pre-load the most relevant files in optimal read modes.
Layers
- Layer 1 (Entry): Files directly mentioned or most relevant to the task - read in
fullmode - Layer 2 (Context): Dependencies and imports of Layer 1 files - read in
maporsignaturesmode - Layer 3 (Reference): Transitive dependencies - registered as
referencemode (no content loaded)
ctx_preload task="fix the auth refresh token bug"
→ Preloaded 7 files in 3 layers:
L1 (full): src/auth/service.rs, src/auth/token.rs
L2 (map): src/http/middleware.rs, src/db/sessions.rs, src/config.rs
L3 (ref): src/http/server.rs, src/main.rs
Total: ~2400 tokens (vs ~12000 tokens for full reads) A2A - Agent-to-Agent Protocol
A2A enables coordination between multiple AI agents working on the same project. It provides an agent registry, message bus, task delegation, shared cache, and persistent diaries — everything needed for multi-agent workflows on a single codebase.