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.The loop
Section titled "The loop"whatfrees --jsonRead
entries. They are sorted bybytes.frees, biggest first.disk[].freeis the free space before you start.Choose
Section titled "Choose"Only a
safeentry can proceed without manual review:Verdict What 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, theevidenceand the size, and let them decideunsavedNever delete. The work exists nowhere else liveNever delete. Something uses it uncheckedNever delete. whatfrees couldn't tell Check again
Section titled "Check again"For a
safeentry from theworktreessource, run this right before the delete, not at the start of the session.whatfrees checkonly knows Git checkouts and the agents' leftovers; the pnpm store is alwaysask.whatfrees check --json /home/you/.codex/worktrees/9f2c/appGo on only if the check exits with 0 and the JSON
verdictis stillsafe. Skip the entry on any error or missing verdict. If it is noworphan, leave it for manual review even if the exit code is 0.Run the command
Section titled "Run the command"Run the entry's
commandas 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 athen, run it after, for the bytes to come back.Don't add
--force. Don't swap in another command.Confirm
Section titled "Confirm"Run
whatfreesagain.disk[].freeshould have grown by about thefreesyou counted. Report both numbers.
- whatfrees deletes nothing. The agent does, and the agent is responsible for the delete.
- A
safeverdict is true at the time of the scan. A person or another agent may start work afterwards. That is whywhatfrees checkcomes right before each delete. - Don't pass
--allto find more to delete. It adds entries that are in use or small, andlivestayslive. - When
partialistrue, sizes are lower bounds or missing. Run the firstnextcommand to get a longer budget, or pass--exact. - A source in
skippedhas no entries in this report. It doesn't mean the thing is empty. - Don't read the text report to parse it. Use
--jsonand the fields in the JSON report.
In code
Section titled "In code"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);
}whatfrees gives the command. Running it is up to you. See the JavaScript API.