session-cleanup — скилл для Claude Code: чистка сессий агента
Находит пустые и зависшие сессии в Agent Monitor, показывает список к удалению и стирает их только после подтверждения.
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a claude-codeЧто делает session-cleanup
Скилл работает с базой мониторинга Claude: сначала читает GET /api/stats и GET /api/sessions?limit=1000, отмечает сессии без событий, с нулевым turn_count и нулевой стоимостью, а также те, что числятся активными, но давно не подавали признаков жизни. Порог устаревания задаётся аргументом, по умолчанию 24 часа.
Дальше идёт таблица кандидатов: короткий id, статус, причина, имя каталога, время старта, стоимость в USD с четырьмя знаками после точки. Удаление выполняет POST /api/settings/cleanup — серверная процедура, которая вычищает пустые и осиротевшие сессии вместе с висящими событиями. Отменить её из дашборда нельзя, поэтому скилл сначала показывает превью и ждёт явного confirm.
Это единственный скилл в плагине, который меняет данные, и только через один документированный эндпоинт. Расширять область до POST /api/settings/clear-data он не станет. Если дашборд не отвечает, запустите его командой npm start из корня репозитория.
Какие задачи решает
- найти сессии, которые стартовали и ничего не сделали
- отделить зависшие активные сессии от действительно работающих
- посмотреть список к удалению до того, как данные пропадут
- почистить базу мониторинга после серии брошенных запусков
- сравнить состояние базы до и после уборки
Примеры запросов агенту
- Покажи, какие сессии в Agent Monitor можно удалить, ничего не трогай
- Проверь сессии старше 7d и выведи таблицу кандидатов
- Подтверждаю: запусти cleanup и покажи разницу в статистике
Как установить session-cleanup
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a claude-code2Вручную: положить файлы
~/.claude/skills/session-cleanup/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/session-cleanup/
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a codex2Вручную: положить файлы
.agents/skills/session-cleanup/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a cursor2Вручную: положить файлы
.cursor/skills/session-cleanup/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install hoangsonww/Claude-Code-Agent-Monitor session-cleanup2Вручную: положить файлы
.github/skills/session-cleanup/SKILL.md1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a gemini-cli2Командой платформы
gemini skills install https://github.com/hoangsonww/Claude-Code-Agent-Monitor --path plugins/ccam-sessions/skills/session-cleanupВручную: положить файлы
.devin/skills/session-cleanup/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о session-cleanup
Как установить session-cleanup в Claude Code?
Выполните npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill session-cleanup -a claude-code, файл появится по пути ~/.claude/skills/session-cleanup/SKILL.md.
Что делает session-cleanup?
Собирает статистику мониторинга, помечает пустые, зависшие и оборванные сессии, показывает их таблицей и удаляет только после подтверждения.
Можно ли откатить удаление?
Нет. POST /api/settings/cleanup стирает строки навсегда, из дашборда их не вернуть, поэтому скилл по умолчанию работает в режиме превью.
Исходный текст
SKILL.md · MIT
--- name: session-cleanup description: > Identify stale and empty Claude Code sessions in the Agent Monitor and explain the cleanup endpoint (POST /api/settings/cleanup), always showing the exact list of what WOULD be removed before anything is deleted. Cleanup permanently deletes data, so this skill previews first and requires explicit user confirmation. Use when tidying the monitoring database. --- # Session Cleanup Find prune-worthy sessions and explain cleanup — preview first, delete only on explicit confirmation. ## Input The user provides: **$ARGUMENTS** - Empty / `preview` → only show what would be removed (the safe default). - `confirm` → the user has reviewed the preview and explicitly authorizes deletion. - An optional staleness threshold (e.g. `older than 7d`) for what counts as stale. ## Data Sources | Endpoint | Returns | |----------|---------| | `GET /api/sessions?limit=N` | session list: id, status, model, cwd, started_at, ended_at, cost, metadata (turn_count, total_turn_duration_ms) | | `GET /api/stats` | totals: total_sessions, active_sessions, total_events, events_today, sessions_by_status, agents_by_status | | `POST /api/settings/cleanup` | runs the cleanup routine and returns what was removed — DESTRUCTIVE, only after confirmation | ## Report Sections ### 1. Baseline `GET /api/stats` — record total_sessions, sessions_by_status, total_events. This is the before-state to compare against. ### 2. Identify candidates `GET /api/sessions?limit=1000`. Flag sessions that are: - **Empty** — zero events and `turn_count` 0 / null and `cost` 0 (started but never did anything). - **Stale active** — `status` active/working but last activity older than the threshold (default 24h), i.e. never cleanly stopped. - **Truncated** — no `ended_at` and no recent events. ### 3. Preview table (ALWAYS shown) List every candidate with the reason it qualifies. State the total count and confirm that **nothing has been deleted yet**. ### 4. Explain the endpoint Describe `POST /api/settings/cleanup`: it prunes empty / orphaned sessions and their dangling events server-side and returns a summary of removed rows. Make clear this is **permanent** and **not reversible** from the dashboard. ### 5. Execute only on confirmation If — and only if — `$ARGUMENTS` is `confirm` (or the user has explicitly approved this run), call `POST /api/settings/cleanup`, then re-read `/api/stats` and report the before → after delta. Otherwise stop after the preview and tell the user to re-run with `confirm`. ## Output A preview Markdown table: `id (short) | status | reason | cwd basename | started_at | cost`, then a one-line count and the explicit "nothing deleted — re-run with `confirm` to proceed" notice. On a confirmed run, add a before → after summary using ▲/▼ on the counts. Currency as USD to 4 decimal places. ## Safety - This is the ONLY skill in the plugin that mutates data, and only via the one documented endpoint. - NEVER call `POST /api/settings/cleanup` without an explicit `confirm` from the user in this turn — previewing is the default. - Never widen scope to `POST /api/settings/clear-data` or any other destructive endpoint; cleanup of stale/empty sessions only. - If the dashboard is unreachable, tell the user to start it with `npm start` from the repo root.
© hoangsonww · MIT · hoangsonww/Claude-Code-Agent-Monitor