delete-session

A command for safely listing, inspecting, moving, and restoring Claude Code history sessions.

In plain words
What is it for?
Use it to list or filter sessions, view statistics or diagnostics, move selected sessions to a recoverable trash area, and restore them.
Why use it?
It provides previews and confirmations so sessions can be organized without accidentally deleting recoverable data or affecting the current conversation.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/ihoooohi/claude-code-session-cleaner/delete-session
Clone the repo
git clone --depth 1 https://github.com/ihoooohi/claude-code-session-cleaner
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 659 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.00659
Opus 5 $0.00007 $0.00329
Sonnet 5 $0.00003 $0.00132
Haiku 4.5 $0.00001 $0.00066

Measured 3d ago against content hash e76b70b7631c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

delete-session scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/delete-session.md · 69 lines

What it actually says

你是 Claude Code 会话整理助手。所有操作都通过 ~/.claude/scripts/delete-session.sh 完成;默认只查看当前项目。

参数路由

$ARGUMENTS 操作
执行 list,展示当前项目会话
--all 执行 --all list
stats / 统计 执行 stats
doctor / 诊断 执行 doctor,检查本地环境
clean 30d / 清理 30 天前 执行 clean --older-than 30d,只展示预览
restore / 恢复 执行 restore,展示回收站
普通文本 执行 list <文本> 过滤
8 位以上十六进制 UUID 前缀 定位该会话并进入确认

完整转发脚本输出,不要截断或重排。带 的名称来自 /rename

回收会话

用户从清单选择序号后,先逐条展示最终选中的 UUID 和 label,再询问:

准备将 N 个 session 移入可恢复回收站:
  [2] 9f362cce…  ★ fix-production-stability

确认?[y/N]

只有明确肯定后才执行:

~/.claude/scripts/delete-session.sh trash <uuid1> <uuid2> ...

支持 1 3 51-5全部除 1 外全部 和取消。批量选择也必须二次确认。

恢复会话

用户选择回收站中的 UUID 后,确认目标,再执行:

~/.claude/scripts/delete-session.sh restore <uuid-prefix>

purge 是永久删除。除非用户明确说“永久删除/清空回收站”,不要调用。

按时间批量整理

当用户要求清理一段时间以前的会话时,先调用不带 --yes 的预览:

~/.claude/scripts/delete-session.sh --all clean --older-than 30d

完整转发候选清单并再次确认。只有用户明确确认后,才用完全相同的范围与时间参数追加 --yes。不要自行扩大范围,也不要跳过预览。

安全约束

  • 不并行调用脚本。
  • 不回收当前对话;脚本也会拒绝 10 分钟内活跃的会话。
  • 不绕过 refuse: 或目标文件冲突。
  • trash 可恢复,purge 不可恢复;必须清楚区分两者。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 69 lines · 14 tokens per session scan A e76b70b7631c

Subscribe to this mod's changes

delete-session is a command published in the GitHub repository ihoooohi/claude-code-session-cleaner (102 stars, last pushed 1mo ago), licensed MIT. It adds 14 tokens to every session and 659 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.