Safer File Deletion with AI
When working with Claude Code or other agentic systems, you can prevent accidental permanent file deletion by configuring it to use your system's trash/recycle bin 🗑️ instead of immediate deletion. Even AI advisors can make mistakes and nobody wants their precious code files vanishing into the digital void.
By default, many command-line operations use rm
or similar commands that
permanently delete
files without
recovery options. This can be risky when an AI is handling file operations autonomously. It's like handing
your court jester 🃏 the keys to the royal treasury 💰 and hoping for the best.
Solution
Add this instruction to your Claude Code instructions (CLAUDE.md) as a safety improvement:
When deleting files use `gio trash $1 $2 ..` instead of `rm`
'gio' is an application that exposes GNOME's file management operations to the command line.
The trash command moves files to your desktop environment's trash folder, making them recoverable through
your file manager. This works on Linux systems with GNOME or compatible desktop environments - other
operating systems have their own methods for safe deletion. See the gio
manual or run man gio
in your terminal for complete details.
This simple rule transforms potentially catastrophic deletions into recoverable mistakes. Your files are safely stored in the trash bin 🗑️ instead of vanishing without a trace. It's a small change that builds resilience into your development workflow.