When working with AI coding agents in environments without explicit command approvals or sandboxes, file deletion commands pose a significant risk. The rm
command permanently deletes files with no possibility of recovery, making accidental deletions potentially catastrophic.
The Problem with rm
The rm
command is destructive and irreversible. When an AI agent executes rm
on the wrong files or directories, there's no undo button. This becomes particularly dangerous when agents operate autonomously or when you're experimenting in development environments where you've temporarily relaxed safety constraints.
A Safer Alternative: The trash
Command
The trash
command provides a safety net by moving files to the system's recycle bin instead of permanently deleting them. This allows you to review deletions and restore files if needed.
Installation (macOS):
brew install trash
The command works similarly to rm
but with a crucial difference — deleted files can be recovered from the trash/recycle bin until you explicitly empty it.
Configuring AI Agents to Use trash
Modern AI coding agents with state-of-the-art models will follow explicit instructions to use safer alternatives. Add these instructions to your agent's custom configuration:
### Trash
Use `trash` to delete files and directories.
IMPORTANT: DON'T USE `rm` TO DELETE FILES AND DIRECTORIES,
AS THAT IS PERMANENT AND CANNOT BE UNDONE.
INSTEAD, USE `trash` TO MOVE FILES TO THE TRASH/RECYCLE BIN,
FROM WHERE THEY CAN BE RESTORED IF NEEDED.
Important Considerations
This approach provides an additional layer of safety for low-to-medium risk situations where you're comfortable with some autonomy but want protection against accidental deletions. Benefits include:
Reversible deletions — Files remain in the recycle bin until you empty it
Simple recovery — Restore accidentally deleted files through your system's trash interface
Minimal workflow disruption — The command syntax is similar to
rm
, requiring minimal adjustment
This is not a replacement for proper safety measures in high-stakes environments. For production systems or when working with critical data, always:
Use proper sandboxing
Require explicit approval for destructive commands
Implement comprehensive backup strategies
Resources
The trash
command offers a practical middle ground — maintaining workflow efficiency while adding a safety buffer against the irreversible consequences of misplaced rm
commands.
This is a great alternative. Funny story, I usually set virtual machine to leverage computer power, this rm deleted some critical files and I had to delete that machine, I didn't have backup, but I am glad it was a virtual machine and not my machine.