Temporary Files Accumulating and Filling Disk Space
Your application creates temporary files for processing (image transforms, PDF generation, CSV exports, file uploads) but never deletes them afterward. Over days or weeks, these orphaned files accumulate and eventually fill the disk, causing the application to crash or become unresponsive.
This is a silent issue that doesn't appear during development or testing because the files accumulate slowly. In production, you first notice it when the server runs out of disk space, uploads start failing, or the database can't write its WAL files.
The root cause is that Claude Code generated the file creation logic but didn't include cleanup logic, error handling that cleans up on failure, or a scheduled cleanup job.
Error Messages You Might See
Common Causes
- No cleanup after processing — Files are created in /tmp but fs.unlink() or os.remove() is never called after use
- Error paths skip cleanup — When processing fails with an exception, the temp file is never deleted because cleanup is in the success path only
- No try/finally block — File cleanup isn't in a finally block, so any thrown error leaves the file behind
- Missing cron job — No scheduled task to clean up files older than a certain age
- Unique filenames every request — Using UUID-based filenames means no overwriting of old files, just endless accumulation
How to Fix It
- Always clean up in a finally block — Wrap file operations in try/finally (or use Python's tempfile.NamedTemporaryFile with delete=True)
- Use streaming instead of temp files — Pipe data between transforms without writing intermediate files to disk
- Implement a cleanup cron job — Schedule a task to delete files in /tmp older than 1 hour
- Set tmpwatch or systemd-tmpfiles — Configure OS-level cleanup of temp directories on a schedule
- Monitor disk usage — Set up alerts for disk usage above 80% to catch accumulation before it causes outages
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I find what's filling my disk?
Run 'du -sh /tmp/* | sort -rh | head -20' to find the largest items in /tmp. Use 'df -h' to see overall disk usage. Check your app's upload and cache directories too.
How do I prevent temp file accumulation?
Use language-specific temp file APIs that auto-delete (Python's tempfile, Node's tmp library with cleanup option). Always delete in a finally block and add a cron job as a safety net.