Skip to content

Clean stale entries in the temporary directory - #30

Draft
mattt wants to merge 3 commits into
mainfrom
mattt/tmpdir
Draft

mattt wants to merge 3 commits into
mainfrom
mattt/tmpdir

Conversation

@mattt

@mattt mattt commented Nov 16, 2026

Copy link
Copy Markdown
Owner

No Plonge rule covers the temporary directory ($TMPDIR on macOS, $TMPDIR or /tmp on Linux), where coding agents can leave tens of thousands of entries. Running apps and agents also keep files there that they still need, so a rule must select only entries that nothing is using.

This adds a built-in tmpdir prune rule, like xcode-derived-data. It runs with scan --global and clean --global, is a dry run without --apply, and needs no --include-clear. It resolves the directory's real path and skips the rule when that path is /, the home directory or one of its ancestors, or in a Git repository, or when lsof is missing or fails. It looks only at entries directly in the directory and selects one only when it and everything in it last changed, by the later of modification time and status change time, at least tmpdir_age_hours ago. The default is 24 hours, because macOS's com.apple.bsd.dirhelper job runs daily with CLEAN_FILES_OLDER_THAN_DAYS=3, so a 7-day period would select little on macOS.

The rule leaves alone, without checks, names that the system manages: com.apple.*, TemporaryItems, .AddressBookLocks, and cryptex* on macOS, and .X11-unix and the other X11 socket directories, .X*-lock, systemd-private-*, and snap-private-tmp on Linux. It refuses, and lists with the reason, a stale entry that is a symlink, belongs to another user, is open or is a working directory as lsof -F n reports, is or holds a socket, named pipe, or device, holds something that changed within the period, or is or holds a Git repository by the existing walk. With --apply, it runs lsof and the checks again right before each deletion.

lsof sees only the processes that it can inspect, which without root are the user's own. It cannot see a program that will use a path later without holding it open now. The rule reference lists these limits.

The command and MCP tests now set TMPDIR to a directory inside their fake home, so clean --global --apply in the tests cannot reach the real temporary directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant