spoilheap docs
spoilheap lists what Codex, Claude Code, OpenCode, Gemini CLI and Cline left on your disk, gives every item a verdict (SAFE, REVIEW, KEEP) with the reason, clears only what you ask for, and can block an agent before the disk fills. Running spoilheap on its own never changes anything.
01Install
curl -fsSL https://blackman99.github.io/spoilheap/install.sh | sh
The script picks the release binary for your OS and CPU, checks it against checksums.txt, and puts it in ~/.local/bin. Set SPOILHEAP_BIN=/usr/local/bin to put it somewhere else, or SPOILHEAP_VERSION=v0.1.0 to pin a version.
From source (Rust 1.85 or newer): cargo install --git https://github.com/Blackman99/spoilheap
By hand: download the archive for your platform from Releases. Linux x86_64 and aarch64 builds are static (musl). macOS builds are for arm64 and x86_64; Windows for x86_64 and arm64. Every archive is listed in checksums.txt on the release.
02First run
spoilheap # look. Deletes nothing.
spoilheap clean --safe # print the plan for every SAFE item
spoilheap clean --safe --yes
spoilheap clean 101 104 # REVIEW items, by number, after you have read them
Every item gets a number from 101 up, like a context number in a dig. The numbers are saved, so spoilheap clean 104 means the item you just saw as [104], even if you open a new terminal. If the item has changed or gone since then, spoilheap says so instead of guessing.
Repositories are searched under the current folder and under ~/code ~/src ~/projects ~/dev ~/work ~/Developer ~/repos when those exist, four levels deep. Point it elsewhere with --root DIR (repeatable) and --depth N.
03How verdicts are made
| Item | Verdict | Rule |
|---|---|---|
| Crash dumps (Codex, ChatGPT, Claude, Cursor desktop apps) | SAFE | Always. If 30 or more appeared in the last hour, the reason says the app is crash-looping and to quit it first. |
| Agent worktree, clean, every commit reachable from another branch, tag or remote, untouched for 1 h | SAFE | Removed with git worktree remove. |
| Agent worktree with commits found nowhere else | REVIEW | git rev-list --count HEAD --not --exclude=<branch> --branches --tags --remotes; the reason gives the count. |
| Agent worktree a file changed in within the last hour | REVIEW | An agent may still be working in it. |
| Folder that looks like a worktree but git no longer lists it | REVIEW | Its repo was moved or pruned, or it is a copy. Removed as a plain folder only if you name it. |
| Agent worktree with uncommitted changes | KEEP | git status --porcelain is not empty. |
| Agent worktree a running process is sitting in | KEEP | Some process has its working directory inside it (/proc/*/cwd on Linux, lsof on macOS). |
target/, node_modules/, .venv/ … inside an agent worktree | SAFE | Only when git says the folder is ignored and tracks no file in it. Listed apart from the worktree, so a KEEP worktree can still lose its build output. |
tmp_pack_*, tmp_idx_*, .tmp-* in .git/objects/pack | SAFE | Untouched for 1 h (a git that is still writing gets left alone). |
| Stale worktree registrations | SAFE | git worktree prune. |
| Session history, transcripts, file history, snapshots, task folders | REVIEW / KEEP | Older than --older (default 30 d) is REVIEW, newer is KEEP. |
| Logs, debug logs, shell snapshots | SAFE | Older than 1 day. |
| SQLite database (OpenCode, Codex logs) | REVIEW / KEEP | Free pages are read from the file header (freelist count × page size). REVIEW when at least 500 MB is free, or 20 % and 50 MB; it prints the VACUUM command and the free space VACUUM needs. Never edited by spoilheap. |
All git commands run with GIT_OPTIONAL_LOCKS=0, so spoilheap never takes index.lock from an agent that is working.
04clean
spoilheap clean --safe [--yes]
spoilheap clean 104 107 [--yes]
spoilheap clean --safe 113 --yes # every SAFE item plus REVIEW item 113
- Without
--yesit prints the plan and the total, and deletes nothing. - KEEP items are skipped even when named, and the reason is shown.
- Worktrees are re-checked right before removal, then removed with
git worktree remove(no--force). If git refuses, that item fails and the rest go on; the exit code is 1. - Files are deleted only inside the folder the item came from; empty parent folders are tidied up to that folder and no further.
- Databases print a command for you to run when the app is closed, for example
sqlite3 '~/.local/share/opencode/opencode.db' 'VACUUM;'. - After a real run it measures free space again. If the disk got back less than 70 % of the plan, it says why that usually happens (a process still holds deleted files open, or a filesystem snapshot keeps the blocks).
05watch
spoilheap watch [--every 10s] [--rate 1GB] [--floor 10GB]
Measures the agent folders and every repo's .git/objects/pack on each tick. A location that grows faster than --rate per minute is printed as RUNAWAY with its newest file and the process chain that has files open there (from /proc/*/fd on Linux, lsof on macOS), once per change. Free space under --floor is reported at most once a minute. A quiet line with the free space is printed every minute when nothing moves.
06procs: agent processes
spoilheap procs [--all] [--json]
Agents leave processes behind as well as files. Codex restarts have doubled its helper and MCP servers (openai/codex#55141), and Claude Code can leave the shell it runs commands in orphaned at PPID 1, burning a core (anthropics/claude-code#103313). procs lists them, grouped by the agent that runs them, with memory (RSS) and CPU. It only reads: it never sends a signal.
What counts as an agent process is kept narrow on purpose; a node process on its own is never listed.
- Agents, by executable or package:
claude/@anthropic-ai/claude-code,codex/@openai/codex/Codex.app,opencode/opencode-ai,gemini/@google/gemini-cli,cline. - Helpers: everything running below a live agent, down to the next agent. MCP servers are named from their package or script.
- Orphans, with no agent above them any more: Claude Code snapshot shells (
shell-snapshots/snapshot-…in the command line),codex app-server/mcp-server, Codex.app and Cline helpers, and processes whose environment carries an agent's marker variable (CLAUDECODE,CODEX_THREAD_ID,OPENCODE,GEMINI_CLI; only the name is read, never the value). A process is orphaned when its parent is PID 1, gone, or an init process that adopted it. Codex's shared app-server (--managed-daemon) detaches on purpose, so it counts as one whatever its parent.
| Verdict | When |
|---|---|
| KEEP | A running agent and everything below it. Identical helpers under one agent are folded into one line with ×N (--all unfolds them and shows every helper, not just the five biggest). |
| REVIEW | An orphan whose working folder, or a file it or a process below it has open, is inside a live git worktree; one whose working folder could not be read; a plain command an agent started (it may be a dev server you asked for); a CLI agent whose terminal is gone; a Codex app-server while a Codex is running. |
| SAFE | An orphaned snapshot shell, MCP server or helper with nothing in a live worktree. Its kill -TERM line is printed under next. |
Orphans include the processes below them in their memory and CPU (a snapshot shell at 0 % with a runaway child shows the child's CPU). Arguments that look like secrets (--token, API_KEY=…) are shown as ***. Linux reads /proc, macOS uses ps and lsof; processes of other users are not attributed. On Windows, procs says it is not supported yet and exits 0 (--json prints "supported": false). Orphaned Codex MCP servers cannot be told apart from your own: Codex starts them with a clean environment and no marker.
07guard and hooks
spoilheap guard [--floor 10GB | --floor 5%] [--path DIR]
spoilheap hook claude # prints the settings.json block
spoilheap hook codex # prints the config.toml block
guard exits 0 when free space is at or above the floor on the home folder and on the folder the agent is working in (read from the hook's JSON on stdin, field cwd, or --path). Under the floor it exits 2 and writes a message to stderr naming the three biggest SAFE items and the command to clear them. Claude Code and Codex both treat exit code 2 from a PreToolUse hook as "block this tool call and show the message to the model".
Codex hooks are behind a feature flag; the printed block sets [features] hooks = true. Codex also reads ~/.codex/hooks.json if you prefer JSON.
08MCP server
claude mcp add spoilheap -- spoilheap mcp
codex mcp add spoilheap -- spoilheap mcp
{ "mcpServers": { "spoilheap": { "command": "spoilheap", "args": ["mcp"] } } }
Stdio JSON-RPC, protocol 2025-06-18. Two tools, both marked read-only:
disk_status { path?, floor? }: free and total bytes for the filesystem holdingpath(default: home), and whether it is underfloor(default 10GB).disk_leftovers { min_bytes? }: the same report asspoilheap --json, with verdicts and reasons.
There is no delete tool. The agent can tell you what to run; you run it.
09Paths it reads
| Agent | Where |
|---|---|
| Codex | $CODEX_HOME (default ~/.codex): worktrees/, sessions/, archived_sessions/, log/, .tmp/, logs_*.sqlite. Crash dumps from the desktop apps (Codex, ChatGPT, Claude, Cursor) in each app's data folder: ~/Library/Application Support/<App>/Crashpad on macOS, %APPDATA%\<App>\Crashpad on Windows, ~/.config/<App>/Crashpad on Linux. Old bun-installed builds in ~/.bun/install/cache/@openai. |
| Claude Code | $CLAUDE_CONFIG_DIR (default ~/.claude): projects/, file-history/, shell-snapshots/, debug/; <repo>/.claude/worktrees. |
| OpenCode | $XDG_DATA_HOME/opencode (default ~/.local/share/opencode): opencode*.db (+ WAL) or $OPENCODE_DB, snapshot/<project>, storage/, log/. |
| Gemini CLI | ~/.gemini/tmp/<project hash>. |
| Cline | globalStorage/saoudrizwan.claude-dev/{tasks,checkpoints} under VS Code, Cursor, Windsurf and VSCodium user folders, and ~/.cline/data. |
| Aider | <repo>/.aider.tags.cache.v4. |
spoilheap paths prints each one with found or absent for your machine. Sizes are allocated blocks; hard links are counted once; symlinks are never followed; scans stay on one filesystem.
10Options and environment
| Flag | Meaning |
|---|---|
--root DIR | Look for repositories here (repeatable). |
--depth N | How deep under each root (default 4). |
--older D | History older than this is REVIEW (default 30d; units s m h d w). |
--all | Also list items under 1 MB. With procs: every helper, duplicates unfolded. |
--json | Machine-readable output. |
--home DIR | Treat DIR as the home folder. |
--no-color | Plain output. |
| Variable | Effect |
|---|---|
CODEX_HOME, CLAUDE_CONFIG_DIR, XDG_DATA_HOME, OPENCODE_DB | Same meaning as for the agents themselves. |
XDG_CACHE_HOME | Where the last run's item numbers are kept (spoilheap/last.json; ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows). |
NO_COLOR, FORCE_COLOR, COLUMNS | Output styling and width. |
SPOILHEAP_VACUUM_MIN | Lower the "worth a VACUUM" bar (default 50MB, with 20 %). |
SPOILHEAP_FAKE_FREE=3GB/500GB | Pretend this much is free (for testing guard and hooks). |
SPOILHEAP_FAKE_PROCS=file.json | Read the process table for procs from a file (format: tests/fixtures/procs/*.json), for tests and demos. |
SPOILHEAP_OS, SPOILHEAP_HOME, SPOILHEAP_APPARENT_SIZE | Test knobs: use another OS's path layout, another home, or count file length instead of blocks (for sparse demo files). |
11JSON output
{
"tool": "spoilheap", "version": "0.1.0", "generated_at": "2026-10-19T02:41:07Z",
"disks": [{ "path": "/", "total_bytes": 494000000000, "free_bytes": 3100000000 }],
"totals": { "bytes": 117074251949, "safe_reclaimable_bytes": 56524587087,
"review_reclaimable_bytes": 54193328174, "keep_bytes": 6186614832 },
"repos_scanned": 1,
"items": [{
"id": 127, "harness": "repo", "kind": "tmp-pack",
"label": "payments: 6 half-written git packs",
"path": "/Users/you/code/payments/.git/objects/pack",
"bytes": 11952000000, "reclaimable_bytes": 11952000000, "files": 6,
"newest_age_s": 172800, "oldest_age_s": 172800,
"verdict": "SAFE",
"reason": "tmp_pack_* from a git that died mid-write (openai/codex#54955); untouched for 1 h+",
"action": { "type": "remove", "paths": 6 }, "parent": null
}],
"notes": []
}
action.type is one of remove, git-worktree-remove, git-worktree-prune, manual (with command) or none. parent is the id of the worktree a build-output item sits in.
spoilheap procs --json prints tool, version, generated_at, supported, totals (agents, processes, orphans, rss_bytes, safe, review, keep) and a flat processes list. Each entry has pid, ppid, agent, role (agent, helper, orphan), kind, label, agent_pid, orphan, orphan_reason, cwd, rss_bytes, tree_rss_bytes, cpu_percent, age_s, children, copies, command (secrets masked), verdict, reason and suggested_command.
12Exit codes
0 | Done (for guard: enough free space). |
1 | clean: at least one item could not be removed. |
2 | guard: under the floor; the hook blocks the tool call. |
64 | Usage error: unknown flag or command, bad number. The message suggests the nearest flag. |
13FAQ
Is it safe to run?
spoilheap, paths, watch, procs, guard and mcp only read; procs prints kill commands but never sends a signal. Only clean … --yes deletes, and only items you selected, inside the folders they came from.
Why does the disk not get back everything clean promised?
A running app may hold deleted files open (the space comes back when it quits), or a filesystem snapshot (APFS local snapshots, Btrfs, ZFS) may keep the blocks. spoilheap measures before and after and says when this happened.
Why does it not delete old chats by itself?
Because you might want them: codex resume, Claude Code's /resume and Cline's task history all read them. They are REVIEW so you decide, with the age and size in front of you.
Why not just run VACUUM for me?
VACUUM rewrites the file and needs roughly its live size in free space while it runs. On a nearly full disk, with the agent possibly running, that is how databases get corrupted. You run it when the app is closed.
Does it know about my other agent?
If it keeps data under its own folder, open an issue with the path and a link to the source or docs that define it. Paths are only added from the agent's own source or docs.
Does it send anything anywhere?
No. No network, no telemetry. The only file it writes outside clean is the id map in the cache folder.