Skip to content
Back to skills

Disk Space Reclaim

BSecurity

Free disk space without breaking running work: map first, delete only what regenerates.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentspythongobashsqlnodegitdatabase

Security analysis

B85/100
  • highPerforms destructive filesystem operations

Pro scans all 2 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add Rafaelrr5/agent-cortex --skill disk-space-reclaim --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Disk Space Reclaim?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Disk Space Reclaim
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/rafaelrr5-disk-space-reclaim/badge)](https://www.skillsdirectory.com/skills/rafaelrr5-disk-space-reclaim)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: disk-space-reclaim
description: "Free disk space without breaking running work: map first, delete only what regenerates."
version: 1.0.0
author: Rafael Rocha Ribeiro (github.com/Rafaelrr5)
license: MIT
platforms: [linux, macos]
metadata:
  agent:
    tags: [disk, cleanup, cache, node_modules, uv, git, server]
    related_skills: [hermes-cron-jobs, worktree-analysis, delivery-verification]
---

# Disk space reclaim

## When to Use

- A disk alert fires, or the user says the disk is full on a server or a workstation.
- Not for memory or CPU pressure, and not for sorting personal files.

A request to "clean up the disk" on the user's own machine is approval to delete
what regenerates. Anything that holds unique work (unpushed commits, dirty trees,
project data, models) is kept and listed as an optional extra with its size.

## Procedure

1. **Measure.** `df -h /`, then `sudo du -xh --max-depth=1 / | sort -rh | head`, then
   drill into the home directory and the agent's work directories. For each big
   directory, print the newest file's mtime so you can tell idle from active.
2. **Map what must not break, before deleting anything.** Collect these paths into
   one exclude list:
   - the working directory of every running process:
     `for p in $(pgrep -u "$USER"); do readlink /proc/$p/cwd; done | sort | uniq -c`
   - running services: `systemctl --user list-units --type=service --state=running`
     (and the system ones if you have the rights);
   - every path a scheduled script reads: grep the script directories, crontabs and
     unit files for each candidate directory. Helpers often live in throwaway-looking
     folders, such as a screenshot folder whose `node_modules` a daily job needs.
   Count only executable references (scripts, unit files, job definitions, running
   processes). Prose in a note that mentions a project does not pin it.
3. **Tier A, regenerable: delete.**
   - Build output and dependency trees under the work directories: `node_modules`,
     `.next`, `.turbo`, `.gradle`, `build`, `.venv`, minus the exclude list, skipping
     any tree with a file modified in the last 24 hours. Write the list to a file,
     delete in a loop, keep the log.
   - Package caches: `npm cache clean --force` and `~/.npm/_npx`; `~/.cache/pip`
     (`pip cache purge` can hang on a large cache). For uv, see the next section.
   - Your own temp files older than two days, `sudo apt-get clean`,
     `sudo journalctl --vacuum-size=50M`, browser profile caches (`Cache`,
     `Code Cache`, `ShaderCache`).
   - Older versions of a tool when only the current one is used (headless browser
     builds, old runtime downloads). First grep scripts for hard-coded versions; make
     the script pick the newest build instead of pinning one.
4. **Tier B, unique: keep and report with size.** Clones and worktrees with unpushed
   commits or uncommitted changes, idle projects that hold data, ML models in use.
5. **Verify.** `df -h /` before and after. Check each service is still active.
   Re-run, or dry-run, every scheduled script whose paths you touched, and reinstall
   dependencies where one needed them.
6. **Report briefly:** before and after (% and GB), what was deleted, what was kept on
   purpose and why, optional extras with their size, and anything you broke and how
   you fixed it.

## The uv cache and the agent's own Python

Before clearing a uv cache, find out what the running agent executes from:

```bash
uv cache dir                              # the cache
uv python dir                             # where uv-managed Pythons live
readlink -f "$(command -v python3)"       # resolve the agent's interpreter too
```

By default uv keeps managed Python installs in the persistent data directory
(`~/.local/share/uv/python`), not in the cache, so `uv cache clean` does not remove
them ([storage](https://docs.astral.sh/uv/reference/storage/)). The default changes
when an installer sets `UV_PYTHON_INSTALL_DIR` or `UV_CACHE_DIR` to sit inside the
directory you are about to wipe. Three cases break a working setup:

- **Symlink installs.** An environment installed with `link-mode = "symlink"` points
  into the cache; uv's docs warn that `uv cache clean` then breaks every installed
  package ([settings: link-mode](https://docs.astral.sh/uv/reference/settings/#link-mode)).
  The default is clone/copy-on-write on Linux and macOS and hardlink on Windows, which
  survive a clean.
- **Environments that live in the cache.** `uvx` tool environments, `uv run` script
  environments, and project environments under the `centralized-project-envs` preview
  are stored in the cache ([tools](https://docs.astral.sh/uv/concepts/tools/#tool-environments)).
  uv recreates them on the next run, but a long-running process started from one
  (a `uvx` server, say) loses its files underneath it. If the agent itself was started
  that way, its whole environment is in the cache.
- **Deleting by hand.** uv's docs say it is never safe to modify the cache directly
  ([cache](https://docs.astral.sh/uv/concepts/cache/)). Use `uv cache prune` (unused
  entries only) or `uv cache clean`, never `rm -rf` on the cache or a broad
  `find ... -exec rm` over a directory that contains it.

`uv cache clean` and `uv cache prune` wait for the cache lock while another uv process
runs (five minutes by default, `UV_LOCK_TIMEOUT`). A long-running `uvx` process holds
it. Don't pass `--force`; restart the holder only if you know what it is, or skip uv
this round.

## Pitfalls

- **"HEAD is on origin/main and the tree is clean" does not mean a clone can go.** A
  clone keeps its own local branches and stashes. `git -C <dir> log --branches --not
  --remotes --oneline` and `git -C <dir> stash list` must both print nothing;
  otherwise keep the directory and strip only its dependencies.
- **Idle is per checkout.** Measure the newest mtime of the project a dependency tree
  belongs to, not the tree itself.
- **Long deletes outlive a foreground call.** Run the big `find`/`rm` loop as a
  background job that reports on exit, and the quick cache cleans alongside it.
- **Don't fight an application's database from a cleanup.** A large SQLite file with
  almost no free pages gains nothing from `VACUUM`. Report it as its own issue.
- **Keep models the user runs** (speech transcription, local LLMs) even when they sit
  in a cache directory. Ask before removing one.
- **A cleanup that needs a person to start it will be late.** If alerts keep coming,
  schedule a guard that cleans tier A at a threshold and reports what it already did
  plus one concrete next step, not "decide what to delete". Prove it runs
  (`hermes-cron-jobs`).

## Archive, then delete

When the space is a project the user wants moved off the machine, follow
`references/archive-then-delete.md`: code to the git remote, everything git does not
carry to object storage with a checksum manifest, and a delete gated by a script.

Files in this skill

  • SKILL.md6.8 KB
  • references/archive-then-delete.md2.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.