Semantic context optimization and automated history pruning. Trunkate AI ensures high-density reasoning by semantically compressing text via the private Trunkate API, preserving core logic and project facts while stripping redundant boilerplate, repetitive logs, and low-signal conversation turns.
SituationActionSystematic PrecisionPreRequest hook triggers scripts/activator.py on every callMassive file/log ingestionRun: trunkate --text "$(cat log.txt)" --budget "20%"Context overflow errorSystem triggers scripts/error-detector.py for emergency wipeHigh token costs / LatencyProactive "Smart Buffer" maintains constant context densityCritical facts preservationWrap blocks in [KEEP] ... [/KEEP] tags for 100% fidelityReview performance ROICheck references/examples.md for semantic fidelity metricsMulti-agent context handoffCondense context before spawning sub-agents via sessions_spawnFocus pivotingUse manual prune with --task to reset reasoning attention
OpenClaw is the primary platform for this skill. It uses workspace-based prompt injection with automated lifecycle hooks for silent memory management.
Via ClawdHub (recommended):
bash
clawdhub install trunkate-ai
Manual:
bash
git clone https://github.com/titus-choi/trunkate-ai.git ~/.openclaw/skills/trunkate-ai
Trunkate AI follows a standardized event-driven architecture to ensure high reliability and low latency:
bash
trunkate-ai/
├── assets/ # Project initialization templates
│ └── TRUNKATE_RULES.md # User rules for "Never-Prune" blocks
├── hooks/ # Active lifecycle hooks
│ └── openclaw/
│ ├── HOOK.md # Technical documentation for hooks
│ └── pre_request.py # THE HOOK: Intercepts outgoing LLM calls
├── references/ # Technical standards and guides
│ ├── examples.md # API usage examples (Before/After)
│ ├── hooks-setup.md # Integration guide for Python hooks
│ └── openclaw-integration.md # Mapping of OpenClaw variables
├── scripts/ # Core executable logic
│ ├── activator.py # Main entry point (Proactive Systematic Hook)
│ ├── error_detector.py # Reactive hook for context failures
│ └── trunkate.py # Core API client (Python Native)
├── SKILL.md # This file
├── requirements.txt # Dependencies (requests)
└── version.txt # Version tracking
To protect specific files or data blocks from being sent to the API, customize the local rules template:
bash
cp assets/TRUNKATE_RULES.md assets/MY_PROJECT_RULES.md
Trunkate AI applies a semantic preservation hierarchy to ensure you never lose critical project requirements during compression.
Content TypePreservation PriorityStrategyAtomic Blocks****Critical100% Verbatim; wrap in [KEEP] ... [/KEEP] tagsSystem Instructions****Critical100% Verbatim [KEEP]; never send to APIActive Task/Goal****HighFull fidelity retention of current user intentProject Facts****HighCore conventions and facts (e.g. from CLAUDE.md)Recent Turns****HighVerbatim retention of the last 3-5 conversation turnsLogic Blocks****MediumSemantic compression via Trunkate APILarge Logs/Dumps****LowSummary transformation (extracting error patterns)Boilerplate****NoneAggressive pruning of license headers and noise
Trunkate AI is designed for "Invisible Operation" via automated triggers. Configure these in your OpenClaw settings to ensure memory is managed as a background utility.
Configure this in .openclaw/config.json to prune history BEFORE every LLM call. This is the primary method for maintaining "Always-On" context efficiency.
Hook Config:
json
{
"hooks": {
"PreRequest": [
{
"type": "command",
"command": "python3 hooks/openclaw/pre_request.py"
}
]
}
}
Triggers on context failures (e.g., 429 or 400 errors from the model) to perform emergency history wipes.
Error Config:
json
{
"hooks": {
"OnError": [
{
"type": "command",
"command": "python3 scripts/error_detector.py"
}
]
}
}
When manual or proactive pruning occurs, a summary of the action should be logged to ensure traceability.
Append significant optimizations to a local tracking file for review:
Logged: ISO-8601 timestamp Original Size: Token count before optimization Optimized Size: Token count after optimization ROI: Percentage reduction (e.g., 85%) Trigger: Proactive threshold | Context Error | Manual Call
One-line description of the optimized content (e.g., "Pruned 15 turns of build logs")
List of critical facts or logic blocks that were protected via [KEEP] or Rules.
If reasoning quality dropped, suggest increasing TRUNKATE_AUTO_BUDGET.
Automatically trigger trunkate or advise the user to adjust the TRUNKATE_THRESHOLD when you notice these signals.
npm install or pip install output.VariableRequirementPurposeTRUNKATE_API_KEYREQUIREDAuthentication for api.trunkate.ai.TRUNKATE_AUTO_BUDGETOptionalTarget for optimized history (e.g., 2000 or "20%").TRUNKATE_API_URLOptionalOverride default for local testing or dev environments.TRUNKATE_DEBUGOptionalEnable verbose logging of hook execution to console.
--task to guide the semantic summarizer (e.g. "Focus on the auth handler logic").TRUNKATE_RULES.md whenever you add a new foundational file or secret environment variables.trunkate with a new task description to clear your "mental workspace" when shifting from backend to frontend.When spawning sub-agents (e.g., via OpenClaw sessions_spawn), use Trunkate to optimize the hand-off context:
trunkate on the primary context with a task specific to the sub-agent's goal.Review the performance metrics and technical standards at natural breakpoints:
references/examples.md.TRUNKATE_THRESHOLD based on your model's recent reasoning performance.To comply with OpenClaw automated health/safety grades:
exec) to run local Python scripts (such as activator.py or .openclaw hooks), the skill is strictly restricted to semantic compression and logging. It contains safety boundaries to ensure it does not execute unknown payloads, access external network resources (other than api.trunkate.ai for optimization), or execute arbitrary code.Trunkate AI: Ensuring your context window is always lean, dense, and effective.