Your AI made the mess. Make it clean it up — without deleting your work.
AI coding agents are excellent at creating things and terrible at taking out the trash. Old sessions, duplicated subagent histories, and abandoned worktrees quietly grow until you need disk space right now.
You could hunt through hidden folders yourself. You could also delete the wrong thing. Agent Aftercare gives you the lazy, cowardly, sensible option:
- see only known agent residue;
- refuse anything recent or tied to a detected provider process;
- compress and deduplicate what you choose;
- restore the exact bytes if you regret it.
Important
Agent Aftercare is alpha software. Version 0.1 quarantines old session logs. It detects known worktree roots but deliberately blocks worktree removal until Git metadata can be restored safely.
$ python -m scripts.demo
scan: 4 found | 3 review | 1 blocked
claude review 2340000 bytes
codex review 2340000 bytes
gemini review 875000 bytes
codex blocked 12 bytes
quarantine: 5555000 original bytes -> 9494 new stored bytes
dedupe: 1 reused object
restore: exact_bytes=TrueThis is the real output of scripts/demo.py, using
disposable fake sessions. It does not invent a 200 GB success story.
This is not a theoretical cleanup problem:
- a Codex user reported a
.codex/sessionsdirectory above 400 GB after image data was duplicated about 150,000 times (openai/codex#35470); - another reported 118 untracked run copies consuming 202 GB (openai/codex#35383).
Generic disk analyzers can show a large folder. Generic cleaners can delete it. Neither knows whether an AI session is still active, whether a path is agent state, or whether the deleted bytes can be reconstructed.
Download the standalone executable for Windows, macOS, or Linux from Releases. No model, API key, daemon, or account is required.
Or run from Python 3.10+:
python -m pip install git+https://github.com/leavemagic-cyber/agent-aftercare.git
aftercare --versionScanning is read-only:
aftercare scan
aftercare scan --min-age-days 60
aftercare scan --json
aftercare scan --allHuman output shows reviewable items first and stops at 50 rows by default;
--all expands it and --json always returns the complete set.
Every session log is labeled review, never safe, because it contains
conversation history. Recent items and items tied to an exactly named provider
process detected by the operating system are blocked.
Quarantine one ID only after reviewing it:
aftercare quarantine claude-session-log-a1b2c3d4e5f6071829 --accept-review
aftercare listUndo it:
aftercare restore q-1788020000-a1b2c3d4e5f6071829Permanently discard the quarantine only when you no longer need undo:
aftercare purge q-1788020000-a1b2c3d4e5f6071829 --yesTraditional Chinese output is available on every command:
aftercare --lang zh-TW scan| Provider | Read-only discovery root | Action in v0.1 |
|---|---|---|
| OpenAI Codex | ~/.codex/sessions/**/*.jsonl |
Review, quarantine, restore |
| Claude Code | ~/.claude/projects/**/*.jsonl |
Review, quarantine, restore |
| Gemini CLI | ~/.gemini/tmp/*/chats/**/*.jsonl |
Review, quarantine, restore |
| All three | known worktrees/ roots |
Visible, always blocked |
Agent Aftercare never treats source code, .git, credentials, settings,
AGENTS.md, CLAUDE.md, memory folders, local databases, or uploads as v0.1
cleanup candidates. It does not scan the rest of your home directory.
Before the original session is removed, Agent Aftercare:
- streams it into a deterministic gzip object;
- addresses that object by SHA-256 content hash;
- decompresses and hashes the stored object again;
- checks that the source did not change during capture;
- writes an atomic
capturedmanifest; - atomically detaches the source into a same-directory staging path, verifies that exact file again, then removes the staging link;
- advances the manifest to
quarantined.
Identical sessions share one object. aftercare list reports the new bytes
actually consumed by quarantine, not just the original file size.
By default the store lives in %LOCALAPPDATA%\AgentAftercare on Windows or
$XDG_DATA_HOME/agent-aftercare / ~/.local/share/agent-aftercare on Unix.
Set AFTERCARE_STORE to place it on another disk.
Note
Reversible compression needs temporary free space while an object is being
captured. An out-of-space or verification failure preserves the original.
A crash after capture but before final manifest advancement leaves a
restorable captured manifest.
- local-only; no network calls or telemetry;
- read-only by default;
- exact known roots and
.jsonlfiles only; - symlinks are not followed;
- process enumeration and age validation fail closed; exact process-name detection is a best-effort extra guard, while recency is the hard gate;
- restore never overwrites an existing path;
- permanent purge requires both an ID and
--yes.
See SECURITY.md for the threat model and reporting process.
- provenance-backed orphan temp-clone discovery;
- safe Git worktree removal and metadata restoration;
- checkpoint/blob adapters where formats are stable enough to fail closed;
- signed release checksums and package-manager installs.
The rule for new adapters is simple: if Aftercare cannot prove what created a path and how to undo the action, it may report the path, but it will not remove it.
python -m unittest discover -v
python -m scripts.demo
python -m aftercare --helpThe runtime has no third-party Python dependencies. Standalone release binaries are built with PyInstaller in GitHub Actions. Contributions that widen deletion scope must include failure-mode tests and a reversible design.
MIT licensed.