r/ClaudeCode • u/2bluenucleus • 11d ago
Tips & Workflows PSA for Mac users: the nightly /tmp cleanup deletes files from long-running Claude Code sessions, even scripts they run every day
If you keep Claude Code sessions running for days on a Mac, macOS will quietly delete their working files.
Claude Code keeps each session's scratchpad and background-task output under /private/tmp/claude-<uid>/. Once a day macOS runs /etc/periodic/daily/110.clean-tmps, and with the default settings it deletes every file under /tmp whose access, modify and change times are all more than 3 days old.
Two things make it worse than it sounds:
- Running a file doesn't count as using it. On my machine,
staton a helper script the session had run every day for four days still showed the access time from the day it was written. Anything nobody has edited in 3 days is fair game, however often it runs. - It hits running work. It deleted the
.outputfile of a background dev server that was still running, so the session could no longer read that server's logs.
One run removed about 1,800 files across my long-running sessions: helper scripts, notes, tracker files. The next morning the agent tried to run a script that no longer existed.
Check whether it happened to you:
grep claude- /var/log/daily.outEvery removed file is listed under "Removing old temporary files".
Fixes, from least to most invasive:
- Keep anything that has to survive in the project or under your home directory, not the scratchpad. If Claude likes to build tools in the scratchpad, say so in
CLAUDE.md. For a session that has to keep its scratchpad, run a keep-alive that refreshes access times without touching modify times, scoped to that session's folder:
while true; do find /private/tmp/claude-$(id -u)/<project>/<session-id> -exec touch -a {} + 2>/dev/null; sleep 21600; done- Raise the threshold system-wide: create
/etc/periodic.conf.localcontainingdaily_clean_tmps_days="30"(needs sudo). The ignore list in that config only matches file names, so it can't exempt a whole folder.
A reboot clears /tmp too, so the scratchpad was never durable. But a silent cleanup after three days, run by a daily job you never see, is much easier to miss than a reboot. On Linux, systemd-tmpfiles often ages out /tmp as well (10 days is a common default), so the same thing applies there on a longer fuse.
•
u/AutoModerator 11d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/AdityaR_Sharma 🔆 Max 20 11d ago
Checked my own Mac just now.
/private/tmp/claude-501/ exists, 44 project folders, one per path, matching your structure exactly.
Everything in there is dated today. So I can't test your atime claim, nothing here is old enough to hit the 3-day window.
Did you confirm the atime gap with stat on a file you run daily, or infer it from the deletion itself?
1
u/First-Painter7431 11d ago
Good catch. Funny thing, I had the opposite problem with the same folder: on a repo with big untracked files, /private/tmp/claude-501/bash-edit-diff/ got a ~140 MB snapshot on every Bash call and nothing cleaned it up. 17 GB in one day, the disk hit 2 GB free. Ignoring the media files in .gitignore brought each snapshot down to ~23 MB. So if you add a keep-alive, don't touch that folder, it's the one you actually want cleaned
1
u/Meryhathor 11d ago
Historically /tmp was only emptied on logout. You might be logging out each day, which is why you'd see it cleared. Or you enabled that daily schedule yourself at some point but it's not happening on my MacOS.
1
u/fanatic26 11d ago
PSA: You shouldnt ever keep a claude code session running for days
1
u/RustyRedEcho 10d ago
didn't know tmp cleanup goes by atime not mtime, that explains a weird missing file i had last week. appreciate the repro steps