GitHub 0
Skip to content

For agents

The loop a coding agent follows to free disk space with whatfrees, and the rules that keep it from deleting work.

Give an agent this prompt.

Run npx whatfrees --json. Consider only safe entries for automatic cleanup. Leave orphan entries for a person to inspect and approve.
For a safe worktrees entry, run npx whatfrees check --json <path> right before deletion. Use the entry's own command only if the check exits with 0 and still reports safe; otherwise skip it.
Read https://whatfrees.loadsheet.dev/guide/agents first.
text
  1. whatfrees --json

    Read entries. They are sorted by bytes.frees, biggest first. disk[].free is the free space before you start.

  2. Only a safe entry can proceed without manual review:

    VerdictWhat to do
    safeGo on to the next step
    orphanLeave it for a person to inspect and approve. A worktree without Git metadata may still hold the only copy of a file
    askShow the person the what, the evidence and the size, and let them decide
    unsavedNever delete. The work exists nowhere else
    liveNever delete. Something uses it
    uncheckedNever delete. whatfrees couldn't tell
  3. For a safe entry from the worktrees source, run this right before the delete, not at the start of the session. whatfrees check only knows Git checkouts and the agents' leftovers; the pnpm store is always ask.

    whatfrees check --json /home/you/.codex/worktrees/9f2c/app

    Go on only if the check exits with 0 and the JSON verdict is still safe. Skip the entry on any error or missing verdict. If it is now orphan, leave it for manual review even if the exit code is 0.

  4. Run the entry's command as it is. It is a quoted POSIX command built from a short list of known verbs, so a path with spaces or $(...) in it can't become a second command. If the entry has a then, run it after, for the bytes to come back.

    Don't add --force. Don't swap in another command.

  5. Run whatfrees again. disk[].free should have grown by about the frees you counted. Report both numbers.

  • whatfrees deletes nothing. The agent does, and the agent is responsible for the delete.
  • A safe verdict is true at the time of the scan. A person or another agent may start work afterwards. That is why whatfrees check comes right before each delete.
  • Don't pass --all to find more to delete. It adds entries that are in use or small, and live stays live.
  • When partial is true, sizes are lower bounds or missing. Run the first next command to get a longer budget, or pass --exact.
  • A source in skipped has no entries in this report. It doesn't mean the thing is empty.
  • Don't read the text report to parse it. Use --json and the fields in the JSON report.

The same loop in a script.

import { check, scan } from "whatfrees";

const report = await scan();
for (const entry of report.entries) {
  if (entry.verdict !== "safe") continue;
  if (entry.source === "worktrees") {
    if (entry.path === undefined) continue;
    const answer = await check(entry.path);
    if (answer.verdict !== "safe") continue;
  }
  console.log(entry.command);
}
ts

whatfrees gives the command. Running it is up to you. See the JavaScript API.