cleanup

cleanup is a command for coding agents from gf-labs/claude-toolbox. It costs 0 tokens per session (5,945 once invoked), scanned D, original, MIT.

A command for finding old Claude coding-session files, extracting their context, and deleting them. It can also target sessions matching a word or identifier.

In plain words
What is it for?
Use it to clean sessions older than a chosen number of days, find sessions by title or content, preview the cleanup, or remove a specific matching session.
Why use it?
It reduces accumulated session files while offering a dry-run mode so you can inspect the proposed cleanup before anything is deleted.

Command

Part of the tools plugin — 2 skills, 13 commands, 5 agents, 4 hooks shipped together

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/gf-labs/claude-toolbox/cleanup
Clone the repo
git clone --depth 1 https://github.com/gf-labs/claude-toolbox

Or install tools, the plugin that ships this one along with the rest of its 2 skills, 13 commands, 5 agents, 4 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/gf-labs/claude-toolbox/cleanup.svg)](https://agentmods.dev/commands/gf-labs/claude-toolbox/cleanup)
Your own site
<a href="https://agentmods.dev/commands/gf-labs/claude-toolbox/cleanup"><img src="https://agentmods.dev/badge/commands/gf-labs/claude-toolbox/cleanup.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 5,945 The whole file, excluding the scripts and references it only reads on demand.
Security scan D 2 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.1 $0.00000 $0.05945
Opus 5 $0.00000 $0.02972
Sonnet 5 $0.00000 $0.01189
Haiku 4.5 $0.00000 $0.00594

Measured 5d ago against content hash 92dc41de4834, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade D, and why

cleanup scanned grade D with 2 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 5d 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.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

- `~/.claude.json` or `~/.claude/settings.json`

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

rm -rf "$PROJ/[proj]/[session-id]/"
commands/cleanup.md · 635 lines

How it starts

The opening of the file, as written. The whole thing — 635 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Arguments

$ARGUMENTS

Parse from arguments:

  • Positional pattern (any word not starting with --) — activates Filter Mode (see below). Matches against session title, first user message, and last-prompt content. Case-insensitive substring match.
  • --days N — age threshold for OLD sessions (default: 30)
  • --dry-run — run all phases and produce reports, but skip actual deletion

Filter Mode

When a positional pattern is provided (e.g. /cleanup "delete-me" or /cleanup 4794c719), skip the normal scan phases and run this targeted flow instead.

Step F1 — Find matching sessions:

python3 -c "
import json, os, sys, shutil
from pathlib import Path

sys.path.insert(0, os.environ.get('CLAUDE_TOOLBOX_ROOT', '') + '/scripts')
from _projects import iter_session_dirs

pattern = 'PATTERN_PLACEHOLDER'.lower()
fh_dir = Path.home() / '.claude' / 'file-history'
debug_dir = Path.home() / '.claude' / 'debug'
senv_dir = Path.home() / '.claude' / 'session-env'

results = []

try:
    _dirs = iter_session_dirs()
except Exception:
    _dirs = iter_session_dirs(scope=('global', None, Path.cwd()))
for _key, proj in _dirs:
    for f in sorted(proj.glob('*.jsonl')):
        try:
            custom_title = ''
            first_user = ''
            last_prompt = ''
            for line in f.read_text(errors='replace').splitlines():
                if not line.strip(): continue
                obj = json.loads(line)
                t = obj.get('type', '')
                if t == 'custom-title':
                    custom_title = obj.get('customTitle', '')  # always take latest
                if t == 'last-prompt' and not last_prompt:
                    last_prompt = obj.get('lastPrompt', '')[:80]
                if t == 'user' and not first_user:
                    msg = obj.get('message', {})
                    if isinstance(msg, dict):
                        content = msg.get('content', '')
                        if isinstance(content, list):
                            for c in content:
                                if isinstance(c, dict) and c.get('type') == 'text':
                                    first_user = c.get('text', '')[:80]
                                    break
                        elif isinstance(content, str):
                            first_user = content[:80]
            searchable = (custom_title + ' ' + first_user + ' ' + last_prompt).lower()
            if pattern in searchable:
                sid = f.stem
                size_k = f.stat().st_size // 1024
                fh_path = fh_dir / sid
                fh_size = sum(ff.stat().st_size for ff in fh_path.rglob('*') if ff.is_file()) // 1024 if fh_path.exists() else 0
                dbg_path = debug_dir / (sid + '.txt')
                dbg_size = dbg_path.stat().st_size // 1024 if dbg_path.exists() else 0
                senv_path = senv_dir / sid
                senv_size = sum(ff.stat().st_size for ff in senv_path.rglob('*') if ff.is_file()) // 1024 if senv_path.exists() else 0
                proj_dir = proj / sid
                dir_size = sum(ff.stat().st_size for ff in proj_dir.rglob('*') if ff.is_file()) // 1024 if proj_dir.exists() else 0
                total_k = size_k + fh_size + dbg_size + senv_size + dir_size
                print(f'MATCH|{proj.name}|{sid}|{size_k}K|{fh_size}K|{dbg_size}K|{senv_size}K|{dir_size}K|{total_k}K|{custom_title or first_user[:50]!r}')
        except Exception as e:
            pass
"

Read the full file on GitHub · 635 lines

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. 5d ago First seen · 635 lines · 0 tokens per session scan D 92dc41de4834

Subscribe to this mod's changes

cleanup is a command published in the GitHub repository gf-labs/claude-toolbox (2 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 5,945 tokens. A static security scan graded it D with 2 findings (reads agent configuration directories, recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.