← 返回 Skills 市场
liujc007

Context Cleaner

作者 liujc007 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
96
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install context-cleaner-1
功能描述
Automatically compress large contexts and clean up expired sessions, sub-agents, and temporary files.
使用说明 (SKILL.md)

Context Cleaner Skill

Automatically manage session context size by compressing large contexts and cleaning up expired sessions, sub-agents, and temporary files.

Quick Reference

Situation Action
Session exceeds size limit Compress early messages
Sub-agent idle > 30min Terminate automatically
Old sessions (> 7 days) Archive or delete
Large context (> 10K tokens) Summarize and compress

Setup

No special setup required. The skill automatically:

  1. Monitors session sizes - Checks if current session context is growing too large
  2. Terminates idle sub-agents - Stops sub-agents that haven't been used recently
  3. Archives old sessions - Moves completed sessions to archive
  4. Compresses context - Replaces verbose message chains with summaries

Usage

Automatic Operation

The skill runs automatically during heartbeat checks when context size exceeds thresholds.

Manual Trigger

Request cleanup anytime:

"Clean up context now"
"Remove expired sessions"
"Compress my context"

API Call

Use sessions_list and subagents tools internally. The skill orchestrates:

  1. List all sessions
  2. Check sub-agent status
  3. Terminate idle sub-agents
  4. Compress large contexts
  5. Archive old sessions

Operation Logic

Context Compression

When a session's context exceeds thresholds:

  1. Identify compressible regions - Early messages, completed task steps
  2. Generate summaries - Create concise summaries of message chains
  3. Replace verbose content - Keep only essential information
  4. Preserve key context - Maintain user preferences, decisions, ongoing tasks

Session Cleanup

Expired session criteria:

  • Idle time: No activity for 7+ days
  • Completed tasks: Sessions that finished long ago
  • Orphaned sessions: No associated work

Sub-Agent Management

Termination criteria:

  • Idle: No messages sent/received for 30+ minutes
  • Failed tasks: Sub-agents that encountered repeated errors
  • Manual request: User explicitly requests cleanup

Best Practices

  1. Preserve working sessions - Never clean active sessions
  2. Keep recent history - Maintain last 24-48 hours of messages
  3. Archive not delete - Move to archive before deleting
  4. Respect user context - Don't clean sessions with pending tasks
  5. Notify before major cleanup - Warn before deleting important sessions

Integration Points

Heartbeat Integration

Add to HEARTBEAT.md:

## 上下文管理
- [ ] 检查会话大小
- [ ] 清理过期子代理
- [ ] 压缩过大上下文

Cron Integration

Schedule regular cleanup:

# Weekly full cleanup
cron add -name "weekly-context-clean" -schedule "0 3 * * 0" -payload "Compress contexts and clean expired sessions"

Compression Strategies

Message Chaining

Convert:

User: Ask question
Model: Answer with detailed explanation
User: Follow-up
Model: More details

To:

User: Ask question
Model: ✅ Answered with 4-point explanation
User: Follow-up
Model: Continued discussion

Context Summarization

Summarize long conversation threads:

  • Key decisions: User preferences, important conclusions
  • Task progress: Completed items, pending actions
  • Context notes: Relevant background information

Session Archiving

Archive strategy:

  1. Check completion status - Is session finished?
  2. Verify no active work - No pending tasks
  3. Check age - Created more than 7 days ago?
  4. Move to archive - Session archive directory
  5. Update metadata - Record completion details

File Structure

workspace/
├── .archive/          # Archived sessions
│   ├── 2026-04/
│   │   ├── session-uuid-1/
│   │   └── session-uuid-2/
│   └── 2026-05/
├── .cache/            # Temporary compression data
└── .cleanup/          # Cleanup logs and reports
    └── cleanup-report.md

Safety Checks

Before any cleanup operation:

  1. Verify session status - Not actively being used
  2. Check pending tasks - No incomplete operations
  3. User preferences - Respect "keep forever" flags
  4. Recent activity - Last message within threshold
  5. Archive option - Offer archive before delete

Example Outputs

Cleanup Report

## Context Cleanup Report

**Time**: 2026-04-17 10:43
**Operations**:
- ✅ Compressed 3 large contexts (saved 15K tokens)
- ✅ Terminated 2 idle sub-agents
- ✅ Archived 1 old session (30 days)
- ⚠️ Skipped 1 active session (pending task)

**Impact**:
- Context size: Reduced by 25%
- Free tokens: ~50K available
- Active sessions: 5 (unchanged)

Related Skills

  • self-improvement: Log learnings about context management
  • taskflow: Manage multi-step cleanup tasks
  • memory: Keep important context in long-term memory

Note: This skill works alongside existing OpenClaw tools without requiring special permissions.

安全使用建议
This skill's behavior (listing sessions, terminating sub-agents, archiving/deleting session data) is coherent with its stated purpose but requires access and authority that the metadata does not declare. Before installing, verify with your platform operator or runtime: (1) exactly which APIs/tools the skill will be allowed to call (sessions_list, subagents, file system write/delete) and whether those calls require elevated privileges; (2) that there is a safe default (dry-run or preview) and explicit user confirmation before any deletion/termination; (3) that audit logs are enabled so you can review actions taken; and (4) that backups or archives are stored separately so accidental deletions can be recovered. If you cannot confirm those controls, prefer using a manual, user-invoked version or decline installation from this unknown source.
功能分析
Type: OpenClaw Skill Name: context-cleaner-1 Version: 1.0.0 The 'context-cleaner' skill is a utility designed to manage the agent's internal state by summarizing large conversation histories, terminating idle sub-agents, and archiving old sessions. While it includes instructions for scheduling tasks via cron and managing files in the workspace, these actions are strictly aligned with its stated purpose of context maintenance and do not exhibit signs of data exfiltration, unauthorized access, or malicious intent.
能力评估
Purpose & Capability
The skill name and description (compress contexts, clean expired sessions/sub-agents, remove temp files) align with the SKILL.md content. However, the documented actions (listing sessions, terminating sub-agents, moving/deleting sessions on disk) require access to session/sub-agent management APIs and writable workspace storage; the skill metadata declares no required permissions or credentials and states 'no special permissions required', which understates the privileges actually needed.
Instruction Scope
The runtime instructions tell an agent to: run automatically during heartbeat checks; call internal tools 'sessions_list' and 'subagents'; terminate idle sub-agents; compress and replace message histories; archive or delete sessions and update metadata; and write to archive/cache/cleanup paths. These are potentially destructive operations touching session state and on-disk archives. While the doc includes safety checks (verify status, offer archive before delete), the instructions are broad and leave significant discretion to the agent (thresholds, what counts as 'pending tasks', when to delete). The skill also instructs scheduling via cron and heartbeat integration, increasing chance of automated deletions without explicit human confirmation.
Install Mechanism
Instruction-only skill with no install spec and no code files — lowest technical install risk (nothing is downloaded or written by the skill itself).
Credentials
The skill declares no environment variables or credentials, yet it requires access to internal session listing and sub-agent control tools and to the workspace filesystem (archive, cache, cleanup directories). That mismatch (no declared privileges but actions that require privileged APIs or file write/delete) is disproportionate and should be clarified before use.
Persistence & Privilege
always:false (not force-included) and model invocation not disabled (normal). Autonomous invocation is allowed, so the skill could perform cleanup during agent operation without explicit human prompts. Combined with the scope of destructive operations (terminating sub-agents, deleting sessions), this increases the blast radius; consider limiting autonomous triggers or requiring confirmation/dry-run by default.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install context-cleaner-1
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /context-cleaner-1 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- New context-cleaner skill automatically compresses large contexts and cleans up expired sessions, sub-agents, and temporary files. - Runs in the background during heartbeat checks or can be triggered manually. - Monitors session context size, archives old sessions, and terminates sub-agents idle for over 30 minutes. - Ensures safety by never deleting active sessions, preserving recent history, and archiving before deletion. - Provides cleanup reports summarizing actions and token savings.
元数据
Slug context-cleaner-1
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Context Cleaner 是什么?

Automatically compress large contexts and clean up expired sessions, sub-agents, and temporary files. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 96 次。

如何安装 Context Cleaner?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install context-cleaner-1」即可一键安装,无需额外配置。

Context Cleaner 是免费的吗?

是的,Context Cleaner 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Context Cleaner 支持哪些平台?

Context Cleaner 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Context Cleaner?

由 liujc007(@liujc007)开发并维护,当前版本 v1.0.0。

💬 留言讨论