Enterprise-grade cleanup tool for OpenClaw subagent management. Automatically identifies and cleans up orphaned subagent sessions while preserving important work through archival.
- 🔍 Smart Detection — Identifies orphaned sessions by age and process status
- 💾 Safe Archival — Backs up transcripts before deletion
- 🛡️ Multiple Safety Layers — Dry-run mode, confirmation prompts, active process checks
- ⚙️ Configurable — YAML-based retention policies
- 📊 Detailed Reporting — JSON/text output with metrics
- 🔧 Enterprise Ready — Logging, audit trails, cron integration
# Preview what would be cleaned (dry-run)
python3 scripts/swarm_janitor.py --dry-run
# Archive old sessions, then clean
python3 scripts/swarm_janitor.py --archive --clean
# Custom retention (7 days)
python3 scripts/swarm_janitor.py --retention-days 7 --clean# Clone to your OpenClaw skills directory
cd ~/.openclaw/workspace/skills
git clone https://github.com/openclawdad/swarm-janitor.git
# Run first scan
python3 swarm-janitor/scripts/swarm_janitor.py --dry-run# Clone repository
git clone https://github.com/openclawdad/swarm-janitor.git
cd swarm-janitor
# Install dependencies (none required, pure Python)
python3 scripts/swarm_janitor.py --helpCreate ~/.swarm-janitor.yaml:
retention:
days: 3 # Delete sessions older than 3 days
min_keep: 10 # Always keep 10 most recent
archive:
enabled: true # Archive before deletion
destination: local # Or: supermemory, s3
safety:
dry_run_default: true # Default to preview mode
check_processes: true # Never delete active sessions| Safety Check | Description |
|---|---|
| Dry-Run Default | Preview mode is default — explicit --clean required |
| Process Check | Verifies no active process owns session |
| Age Verification | Only processes sessions older than threshold |
| Archive First | Backs up to SuperMemory/local before deletion |
| Confirmation | Prompts before large deletions |
# Daily at 3 AM
0 3 * * * python3 ~/.openclaw/workspace/skills/swarm-janitor/scripts/swarm_janitor.py --clean --retention-days 3# See what would be deleted
python3 scripts/swarm_janitor.py --dry-run --verbose
# Archive only (no deletion)
python3 scripts/swarm_janitor.py --archive
# Aggressive cleanup
python3 scripts/swarm_janitor.py --clean --retention-days 1 --force
# JSON output for monitoring
python3 scripts/swarm_janitor.py --report --output jsonCreate an n8n workflow node:
{
"parameters": {
"command": "python3 ~/.openclaw/workspace/skills/swarm-janitor/scripts/swarm_janitor.py --clean --output json"
}
}swarm-janitor/
├── SKILL.md # OpenClaw skill documentation
├── scripts/
│ └── swarm_janitor.py # Main Python implementation
├── references/
│ ├── config.yaml # Configuration template
│ └── advanced.md # Advanced usage guide
├── README.md # This file
└── LICENSE # MIT License
- SessionAnalyzer — Scans and classifies session files
- SuperMemoryArchiver — Archives transcripts before deletion
- SwarmJanitor — Main orchestrator with safety checks
- Discovery — Scans
~/.openclaw/agents/main/sessions/ - Analysis — Determines age, activity status, size
- Classification — Identifies orphaned vs active
- Archival — Saves to SuperMemory/local
- Cleanup — Safely removes orphaned files
- Reporting — Generates summary
MIT License — Created by OpenClawdad for the OpenClaw community.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
Made with 🦞 by OpenClawdad for the agent community.