compress-session-context-prevent-overflow
Prevent context overflow with automatic session truncation and memory preservation.
от rondoflow★ 37 звёзд на GitHub
Установить compress-session-context-prevent-overflow в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Context Compression
Keep conversations within limits. Never lose important context.
⚡ After installing, run the interactive setup wizard to generate your config file, then add the suggested cron entry with
crontab -e. See Quick Start below for commands.
Quick Start
File location: ClawHub installs this skill to
~/.openclaw/workspace/skills/context-compression/. All scripts are placed here directly. This is the standard OpenClaw skill install path — no manual file placement needed.
# 1. Install and configure (interactive)
bash ~/.openclaw/workspace/skills/context-compression/configure.sh
# 2. Verify config exists
cat ~/.openclaw/workspace/.context-compression-config.json
# 3. Set up crontab (example: every 10 minutes)
*/10 * * * * ~/.openclaw/workspace/skills/context-compression/truncate-sessions-safe.sh
How It Works
Session Truncation (truncate-sessions-safe.sh)
- Scheduling: System crontab (e.g.,
*/10 * * * *) - Action: Reads
.jsonlsession files under~/.openclaw/agents/*/sessions/, trims each file to the configured size - Safety: Skips files with a matching
.lockfile (active session) - Integrity: Keeps JSONL line boundaries intact — never splits a line
- Strategy:
priority-firstscans for important keywords before trimming and preserves matching lines
Fact Identification
- Keyword-based:
identify-facts.sh— scans truncated content for keywords (重要, 决定, TODO, 偏好, deadline, must remember, etc.) and appends findings tomemory/YYYY-MM-DD.md - AI-assisted:
identify-facts-enhanced.sh— callsopenclaw agent --agent main --messagewith the trimmed content to semantically identify important facts. Only used whenopenclawCLI is available on PATH. - Triggered by:
truncate-sessions-safe.shcalls one of these before each truncation cycle
Preference Lifecycle (check-preferences-expiry.sh)
- Scheduling: Once daily via crontab
- Mechanism: Reads MEMORY.md preference entries tagged with
@YYYY-MM-DD, removes expired ones - Tiers: Short-term (1-7 days), Mid-term (1-4 weeks), Long-term (permanent)
Scripts
| Script | Purpose | Scheduling |
|---|---|---|
truncate-sessions-safe.sh |
Trim session JSONL files | crontab, every 10 min |
identify-facts.sh |
Keyword-based fact detection | Called by truncate script |
identify-facts-enhanced.sh |
AI-assisted fact detection | Called by truncate script |
check-preferences-expiry.sh |
Remove expired preferences | crontab, once daily |
configure.sh |
Interactive setup wizard | Manual, one-time |
session-start-hook.sh |
Load context at session start | Called by AGENTS.md |
session-end-hook.sh |
Save context at session end | Called by AGENTS.md |
check-context-health.sh |
Report current context status | Manual / on-demand |
Configuration
File: ~/.openclaw/workspace/.context-compression-config.json
{
"version": "2.3",
"maxChars": 40000,
"frequencyMinutes": 10,
"skipActive": true,
"strategy": "priority-first",
"useAiIdentification": false,
"priorityKeywords": [
"重要", "决定", "记住", "TODO", "偏好",
"important", "remember", "must", "deadline"
]
}
| Field | Type | Default | Description |
|---|---|---|---|
| maxChars | number | 40000 | Max chars to keep per session file |
| frequencyMinutes | number | 10 | How often crontab runs truncate |
| skipActive | boolean | true | Skip sessions with .lock files |
| strategy | string | priority-first | Truncation strategy |
| useAiIdentification | boolean | false | Set true to use AI-assisted fact identification (may send content to remote LLMs) |
| priorityKeywords | string[] | (see above) | Keywords to preserve during truncation |
Troubleshooting
| Problem | Solution |
|---|---|
| Context still exceeded | Reduce maxChars in config |
| Memory not persisting | Check that AGENTS.md includes session-start-hook |
| Crontab not running | Verify PATH in crontab includes node/openclaw binary location |
Safety
Data Protection
- No deletion: Truncation writes the trimmed portion back to the same file. It does not delete files.
- Backup before trim:
truncate-sessions-safe.shcreates a.pre-trimbackup of each file before modification. Backups are cleaned up after a successful write. - Line integrity: Truncation only cuts at JSONL line boundaries. Partial lines are never written.
- Active sessions protected: Files with a matching
.lock(currently in use) are always skipped, even if oversized.
Safe Defaults
All configuration values have conservative defaults:
skipActive: true— never touches a running sessionmaxChars: 40000— keeps substantial history per sessionstrategy: priority-first— preserves lines matching priority keywords before trimming anything- No direct network access from scripts. The optional AI fact identi
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- manifest.json
FAQ
Что делает скилл compress-session-context-prevent-overflow?
Prevent context overflow with automatic session truncation and memory preservation.
Как установить скилл compress-session-context-prevent-overflow?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл compress-session-context-prevent-overflow запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…