Install
openclaw skills install session-compact-skillIntelligent session compression plugin for OpenClaw that automatically manages token consumption and supports unlimited-length conversations. Compresses hist...
openclaw skills install session-compact-skillIntelligent session compression plugin for OpenClaw that automatically manages token consumption and supports unlimited-length conversations. By automatically compressing historical messages into structured summaries, it significantly reduces token usage (typically 85-95% savings).
loadFromOpenClawConfig() correctly reads from plugins.entries.<id>.configopenclaw → 2026.4.9, basic-ftp → 5.2.2openclaw.build.openclawVersion → 2026.4.9sessions, session-infoFrom ClawHub (recommended):
clawhub install openclaw-session-compact
Manual installation:
git clone https://github.com/SDC-creator/openclaw-session-compact.git \
~/.openclaw/extensions/openclaw-session-compact
cd ~/.openclaw/extensions/openclaw-session-compact
npm install --production
Add to ~/.openclaw/openclaw.json:
{
"plugins": {
"allow": ["openclaw-session-compact"],
"entries": {
"openclaw-session-compact": {
"enabled": true,
"config": {
"max_tokens": 10000,
"preserve_recent": 4,
"auto_compact": true,
"model": ""
}
}
}
}
}
重要:配置参数从 OpenClaw 配置系统读取。修改配置后需要重启 Gateway:
openclaw gateway restart
# Check current session status
openclaw compact-status
# Manually trigger compression
openclaw compact
# Force compression (ignores threshold)
openclaw compact --force
# View configuration
openclaw compact-config
# Start OpenClaw - compression works automatically
openclaw start
# When conversation history exceeds the threshold, it auto-compresses
# and continues seamlessly without user intervention
Problem: Conversations exceeding 10,000 tokens cause:
Solution: Session Compact automatically compresses history:
Before: 50 messages (1,250 tokens)
↓ [Auto-compress]
After: 5 messages (360 tokens) - 92% token savings
| Parameter | Type | Default | Description | Recommended |
|---|---|---|---|---|
max_tokens | number | 10000 | Token threshold for compression | 5000-20000 |
preserve_recent | number | 4 | Number of recent messages to keep | 4-6 |
auto_compact | boolean | true | Enable automatic compression | true |
model | string | '' | Model for summary generation | Global default |
Conservative Mode (frequent compression, max token savings):
{
"max_tokens": 5000,
"preserve_recent": 6
}
Aggressive Mode (fewer compressions, more context retained):
{
"max_tokens": 20000,
"preserve_recent": 3
}
1. Monitor token usage
↓
2. Exceeds threshold (90%)?
├─ No → Continue conversation
└─ Yes → Trigger compression
↓
3. Keep last N messages (default: 4)
↓
4. Compress old messages into structured summary
├─ Scope: Statistics
├─ Recent requests: Last 3 user requests
├─ Pending work: To-dos
├─ Key files: Important files
├─ Tools used: Tools mentioned
└─ Key timeline: Conversation timeline
↓
5. Replace old messages with System summary
↓
6. Seamlessly continue conversation
When LLM is unavailable, automatically falls back to code extraction mode:
Cause: Token count below threshold Solution:
# Check current token usage
openclaw compact-status
# Lower threshold for testing
openclaw compact --force
Cause: LLM misconfigured or unavailable Solution:
model configurationopenclaw gateway startCause: preserve_recent set too low
Solution:
{
"preserve_recent": 6 // Increase to 6 or more
}
Cause: Missing plugin configuration Solution:
# Check plugin status
openclaw plugins list | grep compact
# Ensure plugin is in plugins.allow in openclaw.json
# Run tests
npm test
# Check coverage (163 tests, 82.78%)
npm run test:coverage
For detailed API documentation and examples, see README.md.
// Compress session
const result = await compactSession(messages, config);
// Check if compression is needed
const needsCompact = shouldCompact(messages, config);
// Estimate token count
const tokens = estimateTokenCount(messages);
Contributions are welcome! Please submit Issues and Pull Requests.
MIT License
Status: ✅ Stable Release Tests: ✅ 163/163 Passing Coverage: 📈 82.78% ClawHub (Code Plugin): ✅ Published (openclaw-session-compact@1.2.1) ClawHub (Skill): ✅ Published (session-compact-skill@1.2.1) Version: v1.2.1 Maintainer: SDC-creator