← Back to Skills Marketplace
liujc007

Context Cleaner

by liujc007 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
96
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install context-cleaner-1
Description
Automatically compress large contexts and clean up expired sessions, sub-agents, and temporary files.
README (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.

Usage Guidance
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.
Capability Analysis
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.
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install context-cleaner-1
  3. After installation, invoke the skill by name or use /context-cleaner-1
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
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.
Metadata
Slug context-cleaner-1
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Context Cleaner?

Automatically compress large contexts and clean up expired sessions, sub-agents, and temporary files. It is an AI Agent Skill for Claude Code / OpenClaw, with 96 downloads so far.

How do I install Context Cleaner?

Run "/install context-cleaner-1" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Context Cleaner free?

Yes, Context Cleaner is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Context Cleaner support?

Context Cleaner is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Context Cleaner?

It is built and maintained by liujc007 (@liujc007); the current version is v1.0.0.

💬 Comments