AgentSkillsCN

clean-sessions

通过交互式清理功能,从会话选择器中移除旧的 Claude Code 会话。当用户输入“/clean-sessions”、“清理会话”、“会话太多”、“会话选择器过于杂乱”,或希望删除旧的、未使用的会话时,即可使用此功能。该功能会运行一段交互式的 Python 脚本,对会话进行分类并有选择地删除。

SKILL.md
--- frontmatter
name: clean-sessions
description: Interactive cleanup of old Claude Code sessions from the resume picker. Use when the user says "/clean-sessions", "clean up sessions", "too many sessions", "session picker is cluttered", or wants to remove old/unused sessions. Runs an interactive Python script that categorizes and selectively deletes sessions.

Clean Sessions

Interactive cleanup of Claude Code sessions from the resume picker.

Process

  1. Run the cleanup script:
bash
python3 "$(dirname "$(readlink -f ~/.claude/skills/clean-sessions)")/scripts/clean-sessions.py"

If the above fails (e.g., no readlink -f on macOS), fall back to:

bash
python3 ~/.claude/skills/clean-sessions/scripts/clean-sessions.py
  1. The script will:

    • List all projects with sessions
    • Let the user select which project to clean
    • Categorize sessions into cleanup groups:
      • Old & unnamed — auto-selected (safe to remove)
      • Old & tiny (<=2 messages) — auto-selected
      • Tiny & unnamed — auto-selected
      • Old but named — shown but NOT auto-selected (user reviews)
    • Present each category interactively for toggle selection
    • Confirm before deleting
  2. For each deleted session, removes both the .jsonl transcript and session directory.

Arguments

FlagDefaultPurpose
--max-age DAYS14Days before a session is considered "old"
--min-messages N2Minimum messages for a session to be "significant"
--dry-runfalsePreview without deleting
--project PATHinteractiveSkip project selection

What Gets Preserved Elsewhere

Deleting sessions does NOT affect:

  • Auto memory (MEMORY.md) — persists independently
  • Session Kit artifacts (TLDR.md, CONTEXT_FOR_NEXT_SESSION.md, etc.) — in .stoobz/ dirs
  • Project CLAUDE.md files
  • Skills and configurations

The only thing lost is the raw conversation transcript (.jsonl file).

Rules

  • Always interactive — never auto-delete without confirmation
  • Named sessions are protected — shown in review but not auto-selected
  • Dry-run first — suggest --dry-run if the user seems uncertain