session-cleanup
Backup old AMCP sessions by renaming with execution date, then clean and compact sessions and memory.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Session Cleanup
Backup old AMCP sessions by renaming with execution date, then clean and compact sessions and memory to keep the system efficient.
What to Clean
-
Session files backup: Rename session JSON files in
~/.config/amcp/sessions/that haven't been modified in 30+ days toYYYY-MM-DD_<original_name>.json.bak - Active sessions keep: Keep the most recent 10 session files (by modification time) as active
-
Memory compaction: Compact
~/.config/amcp/memory/HISTORY.mdto keep only the last 50 entries
Procedure
Step 1: Backup Old Sessions
- List all
.jsonfiles in~/.config/amcp/sessions/directory - Get modification time of each file
- Sort by modification time (oldest first)
- Keep the 10 most recent files as active
- For files older than 30 days (or beyond the 10 most recent):
- Rename to
YYYY-MM-DD_<original_name>.json.bakwhere YYYY-MM-DD is the current execution date - Move to a
backups/subdirectory within sessions folder
- Rename to
Step 2: Clean Backup Files
- Remove
.bakbackup files older than 90 days to free space - Report: "Backed up N session files, cleaned M old backups, freed X MB"
Step 3: Compact Memory
- Read
~/.config/amcp/memory/HISTORY.md - Count the number of entries (each
-bullet is an entry) - If more than 50 entries, keep only the last 50 entries
- Add a summary entry at the top: "Compacted from X entries to 50 entries on YYYY-MM-DD"
Safety
- Never delete the currently active session (most recent)
- Only delete
.jsonand.bakfiles (not directories or other file types) - Always create backups before any cleanup operation
- Log each operation for audit trail
Example Output
Session Cleanup Report (2026-02-16):
- Active sessions kept: 10
- Sessions backed up: 15
- Old backups removed: 3
- Space freed: 45 MB
- Memory entries: compacted from 120 to 50
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-03-11
- Index updated
- 2026-03-11
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!